| 
		
	
		
		
			
			 
				
				Draw Line between Points selected by mouse
			 
			 
			
		
		
		
			
			Hi, 
the following program should draw a line between two in the "world" selected by mouse. 
 
As viz.screentoworld(viz.mousepos()) returns a vector - is there an easier way to figure out the point the mouse was pressed at (e.g. return value [3,4,5]? 
 
I guess I really don't understand viz.screentoworld(viz.mousepos()) that much - where does this vector start - at the viewpoint? 
 
Thank you, 
Johannes 
 
 
 
import viz 
 
viz.go() 
 
SPIsSet,EPIsSet=0,0 
startPoint=[0,0,0] 
endPoint=[0,0,0] 
 
 
def mousedown(button): 
	#  
	if button == viz.MOUSEBUTTON_LEFT: 
		global startPoint,SPIsSet 
		global endPoint,EPIsSet 
		if SPIsSet==0: 
			startPoint=viz.screentoworld(viz.mousepos()) 
			print 'startPoint:',startPoint 
			SPIsSet=1 
		elif (SPIsSet!=0 & EPIsSet==0): 
			endPoint=viz.screentoworld(viz.mousepos()) 
			print 'ePoint:',endPoint 
			EPIsSet=1 
			drawLine(startPoint, endPoint) 
			EPIsSet=0 
			SPIsSet=0 
		else: 
			print 'forgot option 3' 
			 
def drawLine(begin, end): 
	viz.clearcolor(0.0,0.0,0.0) 
	viz.vertexcolor(2, 4, 4) 
	viz.startlayer(viz.LINE_LOOP) 
	viz.vertex(begin) 
	viz.vertex(end) 
	line = viz.endlayer() 
	#posBox=viz.add('../resources/models/box.wrl') 
	#posBox.scale(0.01,0.01,0.01) 
	#posBox.translate(begin) 
	 
#Create callbacks for timer events and mouse click events 
viz.callback(viz.MOUSEDOWN_EVENT,mousedown)
		 
		
		
		
		
		
		
		
		
			
			
			
			
				 
			
			
			
			
			
			
			
				
			
			
			
		 
	
	 |