libQGLViewer mouse behavior
The mouse motion is transmitted to one of the three entities:
- The
QGLViewer::mouseGrabber(), if it is defined.
- The camera if the
CAMERA state key is pressed, or
- the
QGLViewer::manipulatedFrame() if the FRAME state key is pressed.
The default state key is Qt::NoButton for the CAMERA and
Qt::ControlButton for the FRAME.
The behavior of the MouseGrabber depends on your implementation. See the MouseGrabber documentation page for
details.
The Camera behavior
The camera has two modes. The REVOLVE mode (default) lets you examine a 3D object while
the FLY mode is designed for walkthrough applications.
In REVOLVE mode, the button bindings are the following:
- Left button rotates the camera around the
revolveAroundPoint(). Spinning is possible with a fast motion.
- Middle button zooms in or out on the object.
- 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 an horizontal or vertical translation.
With a double simple click © (press/release a mouse button, then an other, at any speed but without moving the mouse) :
- A left then right click defines the
revolveAroundPoint() as the point under the mouse.
Mnemonic : 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.
Mnemonic : 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 acts as a zoom.
You can switch between the two camera modes using the CAMERA_MODE
QGLViewer::shortcutKey() (space by default).
Try the simpleViewer example for an illustration.
The ManipulatedFrame behavior
The manipulatedFrame essentially behaves like the camera in REVOLVE mode:
- Left button rotates the frame. Spinning is possible with a fast motion.
- Middle button zooms the frame in or out.
- Right button translates the frame.
A double click automates the normal behavior, and two buttons pressed together result in a screen space motion.
Try the manipulatedFrame example for an illustration.
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.
Set to 0 to forbid a given mouse behavior.
// The manipulatedFrame can be moved without any key pressed:
setMouseStateKey(QGLViewer::FRAME, Qt::NoButton);
// The camera is moved with the Control key.
setMouseStateKey(QGLViewer::CAMERA, Qt::ControlButton);
- For a more complete redefinition, overload the
QGLViewer::mousePressEvent(QMouseEvent *e),
mouseMoveEvent(), mouseDoubleClickEvent() and mouseReleaseEvent() functions. See the
mouseMoveEvent() documentation for details and code samples.
Last modified on vendredi, juin 27 2003.