Unofficial OpenGL Software Development Kit
0.5.0
|
#include <MousePoles.h>
Mouse-based control over the orientation and position of the camera.
This view controller is based on a target point, which is centered in the camera, and an orientation around that target point that represents the camera. The Pole allows the user to rotate around this point, move closer to/farther from it, and to move the point itself.
This Pole is given a ViewData object that contains the initial viewing orientation, as well as a ViewScale that represents how fast the various movements change the view, as well as its limitations.
This Pole is given an action button, which it will listen for click events from. If the mouse button is clicked and no modifiers are pressed, the the view will rotate around the object in both the view-local X and Y axes. If the CTRL key is held, then it will rotate about the X or Y axes, based on how far the mouse is from the starting point in the X or Y directions. If the ALT key is held, then the camera will spin in the view-local Z direction.
Scrolling the mouse wheel up or down moves the camera closer or farther from the object, respectively. The distance is taken from ViewScale::largeRadiusDelta. If the SHIFT key is held while scrolling, then the movement will be the ViewScale::smallRadiusDelta value instead.
The target point can be moved, relative to the current view, with the WASD keys. W/S move forward and backwards, while A/D move left and right, respectively. Q and E move down and up, respectively. If the bRightKeyboardCtrls parameter of the constructor is set, then it uses the IJKLUO keys instead of WASDQE. The offset applied to the position is ViewScale::largePosOffset; if SHIFT is held, then ViewScale::smallPosOffset is used instead.
Public Member Functions | |
ViewPole (const ViewData &initialView, const ViewScale &viewScale, MouseButtons actionButton=MB_LEFT_BTN, bool bRightKeyboardCtrls=false) | |
Creates a view pole with the given initial target position, view definition, and action button. More... | |
glm::mat4 | CalcMatrix () const |
Generates the world-to-camera matrix for the view. | |
void | SetRotationScale (float rotateScale) |
Sets the scaling factor for orientation changes. More... | |
float | GetRotationScale () const |
Gets the current scaling factor for orientation changes. | |
const ViewData & | GetView () const |
Retrieves the current viewing information. | |
void | Reset () |
Resets the view to the initial view. Will fail if currently dragging. | |
bool | IsDragging () const |
Returns true if the mouse is being dragged. | |
Input Providers | |
These functions provide input, since Poles cannot get input for themselves. See the Pole manual for details. | |
void | MouseClick (MouseButtons button, bool isPressed, int modifiers, const glm::ivec2 &position) |
void | MouseMove (const glm::ivec2 &position) |
void | MouseWheel (int direction, int modifiers, const glm::ivec2 &position) |
void | CharPress (char key) |
glutil::ViewPole::ViewPole | ( | const ViewData & | initialView, |
const ViewScale & | viewScale, | ||
MouseButtons | actionButton = MB_LEFT_BTN , |
||
bool | bRightKeyboardCtrls = false |
||
) |
Creates a view pole with the given initial target position, view definition, and action button.
initialView | The starting state of the view. |
viewScale | The viewport definition to use. |
actionButton | The mouse button to listen for. All other mouse buttons are ignored. |
bRightKeyboardCtrls | If true, then it uses IJKLUO instead of WASDQE keys. |
void glutil::ViewPole::SetRotationScale | ( | float | rotateScale | ) |
Sets the scaling factor for orientation changes.
The scaling factor is the number of degrees to rotate the view per window space pixel. The scale is the same for all mouse movements.