Open topic with navigation
Mouse input
\examples\input\mouse.py
This script demonstrates how to detect certain mouse events. Moving
the mouse will move the object on screen. Press either the left or right
button to play a sound.
"""
This script demonstrates how to detect certain mouse events.
Moving the mouse will move the object on screen.
Press either the left or right button to play a sound.
"""
import viz
viz.setMultiSample(4)
viz.fov(60)
viz.go()
import vizinfo
vizinfo.InfoPanel()
#Add a ground plane
viz.addChild('ground.osgb')
#Add the model to move around by mouse
h = viz.addChild('tut_hedra.wrl')
#Disable mouse navigation
viz.mouse(viz.OFF)
def mymouse(e):
#Move the object based on the mouse position
h.setPosition([(e.x-0.5)*6,e.y*4,5])
#Setup callbacks for when the mouse moves and when a button is pressed
viz.callback(viz.MOUSE_MOVE_EVENT, mymouse)
# Play sound when mouse button pressed
vizact.onmousedown(viz.MOUSEBUTTON_LEFT, viz.playSound,'BOING!.wav')
vizact.onmousedown(viz.MOUSEBUTTON_RIGHT, viz.playSound,'quack.wav')
# Preload sound files
viz.playSound('BOING!.wav',viz.SOUND_PRELOAD)
viz.playSound('quack.wav',viz.SOUND_PRELOAD)