WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   mouse link (https://forum.worldviz.com/showthread.php?t=2162)

durf 07-16-2009 11:46 AM

mouse link
 
Hello,

Is there a way to link the mouse to an obj rather then using ppt to an object?

Thanks

durf 07-16-2009 12:17 PM

I tried viz.link(viz.Mouse, box) and all I can get it to do is move side to side and not very much. I even tried this to improve the amount it moves, boxLink.postScale([4,1,6],target = viz.LINK_FULL_OP).

my view is a straight down view(IE view would be on a ceiling looking straight down on the floor.)

Is there a way to move the box in a x,z movement?

farshizzo 07-20-2009 10:03 AM

The problem is that the mouse position is in 2D coordinates, and your model is in 3D coordinates, so there isn't an easy way to convert between the two reference frames. You can use the viz.MainWindow.screenToWorld command to get the line that passes through the given 2D coordinates. You can view the documentation for the command here.

Here is sample code that uses this command to place an object 5 meters away from the viewpoint at the current mouse position:
Code:

import viz
viz.go()

# Create a model
model = viz.add('ball.wrl')

def UpdateModel():
       
        # Get line that passes through current mouse position
        line = viz.MainWindow.screenToWorld(viz.mouse.getPosition())
       
        # Place model 5 meters away from current view
        model.setPosition(line.endFromDistance(5))
       
vizact.ontimer(0,UpdateModel)



All times are GMT -7. The time now is 12:30 PM.

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