WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 08-05-2009, 07:46 AM
Chrissy2009 Chrissy2009 is offline
Member
 
Join Date: May 2009
Posts: 33
Draw line with a triangle at the end

Hi,

I want to draw a line and at the end of this line I want to draw an arrow.

I've made:
Code:
		viz.startlayer(viz.LINES)
		viz.linewidth(5)
		viz.vertexcolor(0,0.6,0)
		viz.vertex(punkt1)
		viz.vertex(punkt2)
		viz.startlayer(viz.TRIANGLES)
		viz.vertex(1,0,0)
		viz.vertex(-1,0,0)
		viz.vertex(0,1,0)			
		name = viz.endlayer(scene=szene)
But now I've got the problem, that the triangle should be drawn in the local coordinate sytem of the line. So that the arrows shows allways at the right direction.

I looked at the tutorial "Hierarchical Models", but this does not help.

I want to draw a line and at the end of this line there should be an arrow.

And it should be possible to rotate the line along with the arrow.

Can anybody help me - please?

Thanks a lot!
Reply With Quote
  #2  
Old 08-05-2009, 01:05 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
You can set the triangle's parent to be the line and then when you move or rotate the line the triangle will follow.
Code:
triangle = viz.endlayer(parent=line)
Reply With Quote
  #3  
Old 08-06-2009, 04:08 AM
Chrissy2009 Chrissy2009 is offline
Member
 
Join Date: May 2009
Posts: 33
Hey,
I've done this, but it does not work:

Code:
viz.startlayer(viz.LINES)
		viz.linewidth(5)
		viz.vertexcolor(0,0.6,0)
		viz.vertex(punkt1)
		viz.vertex(punkt2)
		
		viz.startlayer(viz.TRIANGLES)
		viz.vertex(1,0,0)
		viz.vertex(-1,0,0)
		viz.vertex(0,1,0)			
		name = viz.endlayer(scene=szene)
		triangle = viz.endlayer(parent=name)

		name.center(punkt1)
01.bmp shows my actual program. But the arrow isn't at the right position.

In 02.bmp I've described my problem. I want to draw a line and afterthat I want to draw the triangle in the local coordinate system of the line.

So, that I'm able to set the triangle allways on
Code:
viz.vertex(1,0,0)
		viz.vertex(-1,0,0)
		viz.vertex(0,1,0)
regardless of which is the direction of the line.

Hope somebody can help me.
Attached Images
File Type: bmp 01.bmp (133.9 KB, 1344 views)
File Type: bmp 02.bmp (146.6 KB, 1317 views)
Reply With Quote
  #4  
Old 08-11-2009, 01:41 AM
Chrissy2009 Chrissy2009 is offline
Member
 
Join Date: May 2009
Posts: 33
Oh, is there nobody who can help me???
Reply With Quote
  #5  
Old 08-11-2009, 07:03 AM
GiudiceLab GiudiceLab is offline
Member
 
Join Date: May 2009
Location: Orono, ME
Posts: 49
I don't know if it would work, but could you make the triangle vertices a function of the line vertex? Something like this:

Code:
viz.startlayer(viz.TRIANGLES)
v1 = line.getVertex(1)
viz.vertex(v1[0]+1,v1[1],v1[2])
viz.vertex(v1[0]-1,v1[1],v1[2])
viz.vertex(v1[0],v1[1]+1,v1[2])
triangle = viz.endlayer(parent=line)
__________________
Virtual Environments and Multimodal Interaction (VEMI) Lab

This time, it should work...
Reply With Quote
  #6  
Old 08-11-2009, 08:49 AM
Chrissy2009 Chrissy2009 is offline
Member
 
Join Date: May 2009
Posts: 33
No, that does not work! Sorry!
Reply With Quote
  #7  
Old 08-12-2009, 11:27 PM
Chrissy2009 Chrissy2009 is offline
Member
 
Join Date: May 2009
Posts: 33
Oh, the arrows are so important for my project.

Is there no possibility to draw these?
Reply With Quote
  #8  
Old 08-13-2009, 10:39 AM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Here is a sample script that draws arbitrary arrows on the screen. Hope this helps:
Code:
import viz
import vizmat
viz.go()

def addArrow(begin,end):
	
	ARROW_SIZE = 0.015
	
	#Find distance between points
	d = vizmat.Distance(begin,end)
	
	#Draw arrow line
	viz.startlayer(viz.LINES)
	viz.linewidth(5)
	viz.vertex(0,0,0)
	viz.vertex(0,d,0)
	
	#Draw arrow tip
	viz.startlayer(viz.TRIANGLES)
	viz.vertex(-ARROW_SIZE,d,0)
	viz.vertex(0,d+(2*ARROW_SIZE),0)
	viz.vertex(ARROW_SIZE,d,0)
	
	#Finish drawing arrow
	arrow = viz.endlayer(parent=viz.SCREEN)
	
	#Place/rotate arrow to match begin end points
	arrow.setPosition(begin)
	arrow.setEuler(0,0,-vizmat.AngleToPoint(begin,end))
	
	return arrow

arrow1 = addArrow([0.2,0.2,0],[0.4,0.4,0])
arrow1.color(viz.GREEN)

arrow2 = addArrow([0.6,0.2,0],[0.8,0.9,0])
arrow2.color(viz.RED)
Reply With Quote
  #9  
Old 08-20-2009, 09:36 AM
Chrissy2009 Chrissy2009 is offline
Member
 
Join Date: May 2009
Posts: 33
Oh yes, thanks a lot!

If I draw one line, it works fine.
If I draw one line and afterthat I draw a second one it works fine, too.

But:
If I draw the two lines and turn this lines around the y-axis and afterthat I want to draw a third line from the end of the first line to the end of the second line, than it doesn't work.

I've found out, that the problem is the vizmat.AngleToPoint calculation. It works fine, if the two points are at the z-position 0. But If I turn the lines around so that the z-value is for example -0.5 then the calculation is wrong.

How can I solve this problem?

I want to draw to lines and turn this around the y-axis. And then I want to calculate the third line from the end of line1 to the end of line2.

Thanks a lot....
Reply With Quote
  #10  
Old 08-24-2009, 11:12 AM
Chrissy2009 Chrissy2009 is offline
Member
 
Join Date: May 2009
Posts: 33
Is there no way to solve my problem???
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Draw a triangle instead of a point Chrissy2009 Vizard 1 07-21-2009 09:46 AM
Create line and vertex Chrissy2009 Vizard 2 07-20-2009 10:53 AM
Draw Vector in viewpoint lookat direction Chrissy2009 Vizard 2 05-30-2009 12:50 AM
Draw Line between Points Chrissy2009 Vizard 2 05-13-2009 04:42 AM
Draw Line between Points selected by mouse Johannes Vizard 7 01-07-2005 02:50 PM


All times are GMT -7. The time now is 04:19 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC