IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Untitled Document

Click example

This program displays a sphere (which automatically creates a window referred to as scene), then repeatedly waits for a mouse left click, prints the mouse position, and displays a small red sphere. A mouse left click is defined as pressing and releasing the left mouse button at nearly the same location.

scene.range = 4

sphere() # display a white sphere for context

while 1:

    if scene.mouse.clicked:

        m = scene.mouse.getclick()

        loc = m.pos

        print loc

        sphere(pos=loc, radius=0.1, color=(1,0,0))

Try running this program. You will find that if you click inside the white sphere, nothing seems to happen. This is because the mouse click is in the x,y plane, so the little red sphere is buried inside the large white sphere. If you rotate the scene and then click, you'll see that the little red spheres go into the new plane parallel to the screen and passing through display.center. If you want all the red spheres to go into the xy plane, do this:

        loc = m.project(normal=(0,0,1))

        if loc: # loc is None if no intersection with plane

            print loc

            sphere(pos=loc, radius=0.1, color=(1,0,0))

Choose Back, or Go to top of mouse documentation