---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-1-ff02cdeb3911> in <module>()
297 if drag:
298 newobs = scene.mouse.project( normal = vector(1, 0, 0),
--> 299 d = 0
300 )
301 if newobs and (newobs != obs):
C:\Users\Paco\Anaconda3\lib\site-packages\vpython\vpython.py in project(self, **args)
2341 ndr = dot(normal, self._ray)
2342 t = -ndc/ndr
-> 2343 return self._canvas.camera.pos.add(self._ray.multiply(t))
2344
2345 class Camera(object):
Projecting mouse position onto a given plane
Here is a way to get the mouse position relative to a particular plane in space:
temp = scene.mouse.project(
normal=vec(0,1,0),
point=vec(0,3,0) )
# None if no intersection with plane:
if temp != None) ball.pos = temp
This projects the mouse cursor onto a plane that is perpendicular to the specified normal. If the second parameter is not specified, the plane passes through the origin. It returns a 3D position, or None if the projection of the mouse misses the plane (scene.mouse.ray is parallel to the plane).
In the example shown above, the user of your program will be able to use the mouse to place balls in a plane parallel to the xy plane, a height of 3 above the xy plane, no matter how the user has rotated the point of view.
You can instead specify a perpendicular distance from the origin to the plane that is perpendicular to the specified normal. The example above is equivalent to
temp=scene.mouse.project(normal=vec(0,1,0), d=3 )