PDA

View Full Version : Draw Line between Points


Chrissy2009
05-12-2009, 01:33 AM
Hi,

I want to create a line between two points. The first point at the mouseDown Position and the second point at the mouseUp Position. Between these two points I want to draw a line.

This works very fine.

But now I want to show the line, before the mouseUp Event. So that I push down the mousebutton, move it at another position and can already see the line, although the mousebutton is pushed.

The line would change as long as I push the mousebutton.

Is this possible?

Thanks in advance...

farshizzo
05-12-2009, 09:12 AM
Yes, this is definitely possible. Here is a sample script that uses the viztask module to draw lines with the mouse:import viz
import viztask
viz.go()

def DrawLineTask():

while True:

#Wait for left mouse butten to be pressed
yield viztask.waitMouseDown(viz.MOUSEBUTTON_LEFT)

#Get mouse position
pos = viz.mouse.getPosition()

#Create line
viz.startlayer(viz.LINES)
viz.vertexcolor(viz.RED)
viz.vertex(pos[0],pos[1],0)
viz.vertex(pos[0],pos[1],0)
line = viz.endlayer(parent=viz.SCREEN)

#Create link between mouse position and vertex
VertexLink = viz.link(viz.Mouse,line.Vertex(1))

#Wait for mouse button to be released
yield viztask.waitMouseUp(viz.MOUSEBUTTON_LEFT)

#Destroy link
VertexLink.remove()

viztask.schedule( DrawLineTask() )

Chrissy2009
05-13-2009, 04:42 AM
Hi,

thanks a lot!

And how can I stop the schedule, so I'm able to draw only two lines and no more??

Is there a possibility to save the separate positions of all these four vertex?