WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   Coordinates change (https://forum.worldviz.com/showthread.php?t=3420)

jincheker 02-04-2011 02:10 PM

Coordinates change
 
Hi, I try to make some program that could add on-the-fly objects by following the path of mouse movement.

I use code like this
Code:

PointBall = viz.add('ball.wrl')
PointBall.color(viz.RED)
PointBall.setPosition(e.x , e.y,2)

where variable "e" is obtained by left-button mouse event.

I also make PivotNavigate by mouse on, but disabled left-button function part.

The problem is: when I move the mouse on the screen, those generated objects do not follow the trajectory of the mouse cursor, there are some offset.

How can I neglect this, and if I zoom in or zoom out the screen, does this method still apply?

Thanks

Jeff 02-07-2011 01:15 PM

Try using the .screenToWorld command. Is this what you're looking for?
Code:

import viz
import vizact
viz.go()

viz.link( viz.Mouse,viz.addTexQuad(viz.SCREEN,texture=viz.add('crosshair.png')) )

def addBall():
       
        ball = viz.addChild('ball.wrl',cache=viz.CACHE_CLONE)
        line = viz.MainWindow.screenToWorld(viz.mouse.getPosition())
        pos = vizmat.MoveAlongVector(line.begin,line.dir,10)
        ball.setPosition(pos)
       
vizact.onmousedown(viz.MOUSEBUTTON_LEFT,addBall)

viz.mouse(viz.OFF)


jincheker 02-08-2011 11:01 AM

Thanks Jeff, That works


All times are GMT -7. The time now is 01:14 PM.

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