QGLViewer mouse behavior
The mouse can be used to manipulate two types of objects : the camera or a manipulated frame. The
behavior is selected from the specific state key that is pressed when a mouse button is clicked:
Behavior |
State key |
Description |
Camera |
None |
Moves the camera in the scene. |
Frame |
Alt |
Moves a manipulated frame in the scene (if any). |
The Camera motion behavior :
There are two modes for the camera behavior (see camera::mode()) : REVOLVE (default, used to revolve
around a 3D object) or FLY (walkthrough applications).
In REVOLVE mode :
- Left button rotates the camera around the revolveAroundPoint(). Spining is possible with a fast motion.
- Middle button changes the camera zoom.
- Right button translates the camera in the camera XY plane.
- Mouse wheel is a zoom.
With a double click, the original action is automated :
- Left button aligns the camera viewing direction to the closest axis (if any).
- Middle button fits the zoom so that the entire scene is visible (see setSceneRadius() and showEntireScene()).
- Right button moves the camera so that the sceneCenter is projected in the middle of the window.
When two buttons are pressed together, the motion is defined with respect to the screen coordinate system:
- Left and middle buttons together rotate around an axis orthogonal to the screen.
- Right and middle buttons together constrain to a purely horizontal/vertical translation.
With a (c) double simple click (two successive mouse clicks and releases on different buttons, with no mouse motion in between) :
- A left then right click defines the revolveAroundPoint() as the point under the mouse.
Mnemo : I want to rotate (left) around that pixel (right).
- A right then left click performs the opposite action : the revolveAroundPoint() is reset to the sceneCenter().
- A middle then right click zooms on the point under the mouse.
Mnemo : I want to zoom (middle) on that pixel (right).
- A right then middle click performs the opposite action : camera zooms out.
In FLY mode :
- Left button changes the view direction and goes forward.
- Middle button changes the viewing direction. No motion.
- Right button changes the view direction and goes backward.
- Mouse wheel is a zoom.
The manipulated frame behavior :
When a manipulatedFrame is defined and attached to the viewer, you can move this frame with the
mouse. The mouse bindings are the same as for the camera in REVOLVE mode. See the manipulatedFrame example.
Mouse behavior customization
As for the keyboard, there are two ways of changing the default mouse behavior:
- If you simply want to change the state key that is associated with a behavior, call
QGLViewer::setMouseStateKey(Behavior, StateKey)
in your init()
function.
See the luxo example. Set to 0 to forbid a given mouse behavior.
- For a more complete redefinition, overload the
void QGLViewer::mousePressEvent(QMouseEvent *e),
mouseMoveEvent(), mouseDoubleClickEvent()
and mouseReleaseEvent()
functions. See the
mouseMoveEvent()
documentation for details and code samples.
Last modified on jeudi, janvier 16 2003.