Home | Pictures of 3D objects

# Click Example This program displays a box (which automatically creates a window referred to as scene), then repeatedly waits for a mouse click, displays the mouse position in a label, and displays a sphere. A mouse click is defined as pressing and releasing the left mouse button, so the sphere appears when you release the mouse button. scene.range = 2 box() # display a box for context show = label( pos=vec(0,1,0) ) while True: scene.waitfor("click",wait) loc = scene.mouse.pos show.text = loc sphere( pos=loc, size=0.1*vec(1,1,1) ) Copy this program and run the program. Click outside the box and a sphere appears where you click. If you click inside the box, nothing seems to happen. This is because the mouse click is in the xy plane, and the sphere is buried inside the box. If you rotate the scene and then click, you'll see that the spheres go into the new plane parallel to the screen and passing through scene.center. If you want all of the spheres to go into the xy plane, perpendicular to the z axis, change the latter part of the program like this: loc = scene.mouse.project(vec(0,0,1)) # loc is null if no intersection with plane if loc: show.text = loc sphere( pos=loc, size=0.2*vec(1,1,1) ) JavaScript version of original click program: scene.range = 2 box() // display a box for context var show = label({pos:vec(0,1,0)}) while (true) { scene.waitfor("click",wait) var loc = scene.mouse.pos show.text = loc sphere({pos:loc, size:0.1*vec(1,1,1)}) } Here is general mouse documentation.

Top of page