| VRS - The Virtual Rendering System |
| version 3.3 |
#include <vrs/sg/gamenavigation.h>

Public Member Functions | |
| GameNavigation (LookAt *target=NULL, InputEvent::Button button=InputEvent::MouseButton1, InputEvent::Modifier must_modifier=InputEvent::NoModifier, InputEvent::Modifier must_not_modifier=InputEvent::NoModifier, const Vector &onGroundPlane=Vector::origin, double minHeight=0.01, double refHeight=1.0, double walkSpeed=0.1, double runSpeed=0.3, double verticalTime=2.0, double horizontalAccelerationTime=0.3, double verticalAccelerationTime=0.3) | |
| double | getSensitivity () const |
| Returns the current sensitivity value. | |
| void | setSensitivity (double sensitivity=0.05) |
| Vector | getGroundPlaneVector () const |
| Returns the ground plane vector. | |
| void | setGroundPlaneVector (const Vector &onGroundPlane) |
| Sets the ground plane vector. | |
| double | getMinHeight () const |
| Returns the minimum height. | |
| void | setMinHeight (double height) |
| Sets the minimum height. | |
| double | getReferenceHeight () const |
| Returns the reference height. | |
| void | setReferenceHeight (double height) |
| Sets the reference height. | |
| double | getWalkSpeed () const |
| Returns the walk speed. | |
| void | setWalkSpeed (double s) |
| Sets the walk speed. | |
| double | getRunSpeed () const |
| Returns the run speed. | |
| void | setRunSpeed (double s) |
| Sets the run speed. (see constructor comment). | |
| double | getVerticalTime () const |
| Returns the time needed to halve/double the camera height. | |
| void | setVerticalTime (double time) |
| Sets the time needed to halve/double the camera height. | |
| double | getHorizontalAccelerationTime () const |
| Returns the acceleration time for horizontal movement. | |
| void | setHorizontalAccelerationTime (double acceleration) |
| Sets the acceleration time for horizontal movement. | |
| double | getVerticalAccelerationTime () const |
| Return the acceleration time for vertical movement. | |
| void | setVerticalAccelerationTime (double acceleration) |
| Sets the accleration time for vertical movement. | |
| bool | isRunning () const |
| void | setKeyTimeout (unsigned int t) |
| void | setKeys (unsigned int front, unsigned int back, unsigned int left, unsigned int right, unsigned int up, unsigned int down, unsigned int toggleSpeed, unsigned int turnAround) |
| Defines control keys. With the toogleSpeed key you can change between walk speed and run speed. | |
| void | enableKeys () |
| void | disableKeys () |
| void | enableMouseButtonAcceleration (InputEvent::Button button=InputEvent::MouseButton3) |
| void | disableMouseButtonAcceleration () |
| double | getHorizontalScaling () const |
| double | getVerticalScaling () const |
| void | setScaling (double horizontal=1.0, double vertical=1.0) |
| virtual BehaviorNode::InvalidationHint | dragStart (int x, int y, ButtonEvent *) |
| virtual BehaviorNode::InvalidationHint | dragMotion (int x, int y, MotionEvent *) |
| virtual BehaviorNode::InvalidationHint | dragEnd (int x, int y, ButtonEvent *) |
| virtual BehaviorNode::InvalidationHint | handle (Event *) |
| virtual | ~GameNavigation () |
| VRS_TYPEINFO (GameNavigation, Manipulator) | |
If you have a scene, for which the y-direction is "up" and the ground plane contains the origin, an appropriate game navigation is constructed as follows:
| VRS::GameNavigation::GameNavigation | ( | LookAt * | target = NULL, |
|
| InputEvent::Button | button = InputEvent::MouseButton1, |
|||
| InputEvent::Modifier | must_modifier = InputEvent::NoModifier, |
|||
| InputEvent::Modifier | must_not_modifier = InputEvent::NoModifier, |
|||
| const Vector & | onGroundPlane = Vector::origin, |
|||
| double | minHeight = 0.01, |
|||
| double | refHeight = 1.0, |
|||
| double | walkSpeed = 0.1, |
|||
| double | runSpeed = 0.3, |
|||
| double | verticalTime = 2.0, |
|||
| double | horizontalAccelerationTime = 0.3, |
|||
| double | verticalAccelerationTime = 0.3 | |||
| ) |
'target': specifies the LookAt object the Navigation is assigned to. 'target' must not be NULL.
Note: The value of target->getUp() defines the upVector for the navigation. So the up vector of 'target' must be perpendicular to the ground plane.
'button': specifies the mouse button that have to be pressed to use the GameNavigation. 'must_modifier': if must_modifier is not InputEvent::NoModifier, the navigation processes mouse events only if the must_modifier key is hold down. 'must_not_modifier': if must_not_modifier is not InputEvent::NoModifier, the navigation processes mouse events only if the must_not_modifier key is not hold down. 'onGroundPlane': The navigation needs a defined "ground plane". This plane is defined by a point on it (onGroundPlane) and a normal vector (specified by target->getUp() ) 'minHeigth': To avoid that the camera passes accidentally through the ground plane, the navigation ensures that the distance d of the camera from the ground plane is always greater than 'minHeight'. 'refHeight': To achieve the impression of movement in an appropriate speed it is neccesary to vary the movement speed and acceleration with the camera height, i.e. with the distance of the camera from the ground plane. The speed parameters that can be configured by the following parameters determines the camera speed in a preferred "reference height", which is defined by this parameter. 'walkSpeed': Determines the speed of vertical movement. If the camera height is 'refHeight', the walk speed is 'walkspeed' units per second. 'runSpeed': The GameNavigation allows to switch between walkSpeed and runSpeed by a specific key, e.g. by "space". A useful value for runSpeed is 2.*walkSpeed. 'verticalTime': Since the movement speed depends on the camera height, the speed of vertical movement is permanently changing. More exactly, if you start with a camera height (i.e. the distance between camera and ground plane) of 'h', the time needed to double or to halve the camera height is always constant. This time constant is specified in seconds by the 'verticalTime' parameter. 'horizontalAccelerationTime': To achieve smooth movement, the GameNavigation enables a smooth acceleration into a desired walk direction. 'horizontalAccelerationTime' specifies the time in seconds to accelerate from speed 0 to walkSpeed. 'verticalAccelerationTime': Time needed to acclerate vertical camera movement from speed 0 up to the vertical speed that is specified defined by the 'verticalTime' parameter and the current height.
By default, the following key assignment is active: cursor key: horizontal movement (forward, backward, left, right) space bar: toggle speed (walk speed / run speed) pageDown/pageUp: vertical movement (up, down) 't': turn arround (rotate by 180 degrees)
Note:
| virtual VRS::GameNavigation::~GameNavigation | ( | ) | [virtual] |
| double VRS::GameNavigation::getSensitivity | ( | ) | const [inline] |
Returns the current sensitivity value.
| void VRS::GameNavigation::setSensitivity | ( | double | sensitivity = 0.05 |
) |
The sensitivity value controls the effect of the mouse to the viewing direction. It must be positive.
| Vector VRS::GameNavigation::getGroundPlaneVector | ( | ) | const [inline] |
Returns the ground plane vector.
| void VRS::GameNavigation::setGroundPlaneVector | ( | const Vector & | onGroundPlane | ) |
Sets the ground plane vector.
| double VRS::GameNavigation::getMinHeight | ( | ) | const [inline] |
Returns the minimum height.
| void VRS::GameNavigation::setMinHeight | ( | double | height | ) |
Sets the minimum height.
| double VRS::GameNavigation::getReferenceHeight | ( | ) | const [inline] |
Returns the reference height.
| void VRS::GameNavigation::setReferenceHeight | ( | double | height | ) |
Sets the reference height.
| double VRS::GameNavigation::getWalkSpeed | ( | ) | const [inline] |
Returns the walk speed.
| void VRS::GameNavigation::setWalkSpeed | ( | double | s | ) |
Sets the walk speed.
| double VRS::GameNavigation::getRunSpeed | ( | ) | const [inline] |
Returns the run speed.
| void VRS::GameNavigation::setRunSpeed | ( | double | s | ) |
Sets the run speed. (see constructor comment).
| double VRS::GameNavigation::getVerticalTime | ( | ) | const [inline] |
Returns the time needed to halve/double the camera height.
| void VRS::GameNavigation::setVerticalTime | ( | double | time | ) |
Sets the time needed to halve/double the camera height.
| double VRS::GameNavigation::getHorizontalAccelerationTime | ( | ) | const [inline] |
Returns the acceleration time for horizontal movement.
| void VRS::GameNavigation::setHorizontalAccelerationTime | ( | double | acceleration | ) |
Sets the acceleration time for horizontal movement.
| double VRS::GameNavigation::getVerticalAccelerationTime | ( | ) | const [inline] |
Return the acceleration time for vertical movement.
| void VRS::GameNavigation::setVerticalAccelerationTime | ( | double | acceleration | ) |
Sets the accleration time for vertical movement.
| bool VRS::GameNavigation::isRunning | ( | ) | const [inline] |
Each GameNavigation stores two speed values, one value for walking and one usually larger value for running. By default it can be switched between walking and running by the space key. By isRunning() one can check, whether the run-mode is active.
| void VRS::GameNavigation::setKeyTimeout | ( | unsigned int | t | ) |
Some simpler GUI toolkits do not send a key-release message, but send multiple messages for key repeat. In this case a timeout value must be set. With each key-pressed event a countdown is re-initialized with a timeout value. If the countdown reaches zero, an internal key-release event is invoked. The timeout value is specified in fiftieth parts of a second. E.g. if you set t=5 and press the forward key very shortly, the forward movement stops past a tenth part of a second. t is expected to be a positive integer between 0 and 1000. The key timeout is disabled by passing t=0 (default value).
| void VRS::GameNavigation::setKeys | ( | unsigned int | front, | |
| unsigned int | back, | |||
| unsigned int | left, | |||
| unsigned int | right, | |||
| unsigned int | up, | |||
| unsigned int | down, | |||
| unsigned int | toggleSpeed, | |||
| unsigned int | turnAround | |||
| ) |
Defines control keys. With the toogleSpeed key you can change between walk speed and run speed.
| void VRS::GameNavigation::enableKeys | ( | ) |
| void VRS::GameNavigation::disableKeys | ( | ) |
If you want to use the GameNavigation only to look around, but to move via other navigation metaphors, you can disable the control keys.
| void VRS::GameNavigation::enableMouseButtonAcceleration | ( | InputEvent::Button | button = InputEvent::MouseButton3 |
) |
By default, all movement is controlled by keys. Alternatively you can invoke forward acceleration by pressing a mouse key. By default, this option is disabled.
| void VRS::GameNavigation::disableMouseButtonAcceleration | ( | ) |
Disables acceleration by mouse button.
| double VRS::GameNavigation::getHorizontalScaling | ( | ) | const [inline] |
| double VRS::GameNavigation::getVerticalScaling | ( | ) | const [inline] |
| void VRS::GameNavigation::setScaling | ( | double | horizontal = 1.0, |
|
| double | vertical = 1.0 | |||
| ) |
The behavior of a GameNavigation is specified by several parameters that were quite inconvenient to specify explicitly. By default all parameters are chosen in a way that the Navigation behaves "reasonable" in a scene that is scaled to the [0,1]-cube. If you want to scale your scene you can easily scale the navigation appropriately, so that the behavior of the navigation keeps the same. Note: The setScaling() method does not change the parameters directly, e.g. the value return by getRunSpeed() keeps unaffected by the scaling.
| virtual BehaviorNode::InvalidationHint VRS::GameNavigation::dragStart | ( | int | x, | |
| int | y, | |||
| ButtonEvent * | ||||
| ) | [virtual] |
Reimplemented from VRS::Navigation.
| virtual BehaviorNode::InvalidationHint VRS::GameNavigation::dragMotion | ( | int | x, | |
| int | y, | |||
| MotionEvent * | ||||
| ) | [virtual] |
Reimplemented from VRS::Navigation.
| virtual BehaviorNode::InvalidationHint VRS::GameNavigation::dragEnd | ( | int | x, | |
| int | y, | |||
| ButtonEvent * | e | |||
| ) | [virtual] |
These methods implements the concrete manipulator functionality. They are overloaded by subclasses. `dragStart' is called if an event of type `ButtonEvent` is received which matches the button condition. `dragMotion' is called if the interaction has been started already and an `MotionEvent' has been received which matches the modifier conditions. `dragEnd' is called if the interaction has been started already and an event of type `ButtonEvent' has been received which matches the button condition. The return value specifies the redrawing code required by `handle'. (It specifies if the world, a canvas or nothing has to be redrawn).
Reimplemented from VRS::Navigation.
| virtual BehaviorNode::InvalidationHint VRS::GameNavigation::handle | ( | Event * | ) | [virtual] |
Event handling methods.
Reimplemented from VRS::Navigation.
| VRS::GameNavigation::VRS_TYPEINFO | ( | GameNavigation | , | |
| Manipulator | ||||
| ) |