By default, Vizard worlds use the mouse to navigate (although you can turn mouse navigation off and adjust its scale). You can also access mouse input for your own purposes. To use mouse input within your world, register a mouse callback that will monitor for mouse activity. Mouse callbacks can monitor for mouse movement, mouse clicks, and mouse wheel movement. Two ways to register these callbacks are described below. Also described are commands to query current mouse activity, to change the visibility of the mouse, and to trap the mouse in the graphics window.
Of course mouse navigation is the default in Vizard. To turn off mouse navigation, use viz.mouse.setOverride(). To turn it back on, use viz.mouse.setOverride(viz.OFF). To get the current status of mouse navigation, use viz.mouse.getOverride() which will return True or False. For more on defining your own method of mouse navigation, check out the section on the camera handlers.
To set the scale of mouse navigation, use viz.mouse.setScale(<scale and position factors>)
One way to register a mouse callback is viz.callback( <callback flag>, <command> ) where the <callback flag> is either viz.MOUSEDOWN_EVENT, viz.MOUSEUP_EVENT, viz.MOUSE_MOVE_EVENT, or viz.MOUSEWHEEL_EVENT. Depending on which flag you choose, the callback will monitor for a button being pressed, a button being released, the mouse being moved, or the mouse wheel being spun.
For mousedown and mouseup events, the callback will call the <command> and provide it with the button's identity. To make things clearer, Vizard has flags for mouse button id numbers (viz.MOUSEBUTTON_LEFT, viz.MOUSEBUTTON_RIGHT, viz.MOUSEBUTTON_MIDDLE).
A mouse move callback will return both the mouse's absolute position in the graphics window and its relative changes in position (where the bottom left corner of the window is (0,0)).
A mouse wheel callback returns a positive value if the mousewheel was scrolled up and a negative number if it was scrolled down.
You can also register one of these callbacks within a class.
The Vizact actions library has several commands to add mouse callbacks. Use vizact.onmousedown, vizact.onmouseup, and vizact.whilemousedown to monitor for mouse clicks. For these commands, provide the flag for the button (e.g. viz.MOUSEBUTTON_LEFT) and the command it should call along with the values to drop into that command. (Make sure you use a comma, and not use parentheses after the referenced command.)
Similarly, use vizact.onwheelup or vizact.onwheeldown to monitor for mouse scrolling and provide it with whatever command you want to call when the event occurs.
You can manually query the button state or position of the mouse at any time.
To get the current state of the mouse buttons, use viz.mouse.getState(). This command will return an integer flag that specifies which mouse buttons are currently being pressed.
To get the current position of the mouse, use viz.mouse.getPosition(). This command will return the (x,y) position of the mouse in the requested coordinate frame. The default coordinate frame is normalized (0,1) window coordinates. You can also get the position in pixel coordinates.
Use viz.mouse.setVisible( viz.OFF ) to turn off the visibility of the mouse. To trap the mouse in the graphics window, use viz.mouse.setTrap( viz.ON ).
Camera handlers - Describes how to define viewpoint navigation with whatever input you choose.
Actions- Introduction to the vizact library of actions.
Mouse navigation - Describes how the default mouse navigation works in Vizard.