Accueil
Rechercher:
sur developpez.com sur les forums
Forums | Tutoriels | F.A.Q's | Participez | Hébergement | Contacts
Accueil Conception Java DotNET Visual Basic  C  C++ Delphi Eclipse MS-Office SQL & SGBD Oracle  4D  Business Intelligence
Club Emploi Blogs   TV   Dév. Web PHP XML Python Autres 2D-3D-Jeux Sécurité Windows Linux PC Mac
FORUM PYTHON F.A.Q PYTHON TUTORIELS PYTHON SOURCES PYTHON OUTILS PYTHON LIVRES PYTHON
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

Responsable bénévole de la rubrique Python : Guillaume Duriaud - Contacter par EMail :
Vos questions techniques : forum d'entraide Python - Publiez vos articles, tutoriels et cours
et rejoignez-nous dans l'équipe de rédaction du club d'entraide des développeurs francophones
Nous contacter - Copyright © 2000-2008 www.developpez.com - Legal informations.