Thread: mouse link
View Single Post
Old 07-20-2009, 10:03 AM
farshizzo farshizzo is offline
WorldViz Team Member
Join Date: Mar 2003
Posts: 2,849
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:
import viz

# 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
Reply With Quote