A FPS style CameraManipulator with ground clamping and intersection.
More...
#include <FPSCameraManipulator.h>
|
| ~FPSCameraManipulator () |
|
virtual bool | handleMouseMove (const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &us) |
| Handles the movement of the mouse. More...
|
|
virtual bool | handleFrame (const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &us) |
| Handles, what happens every frame. More...
|
|
virtual bool | handleKeyDown (const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &us) |
| Handle key down presses. For supported keys see the class desc. More...
|
|
virtual bool | handleKeyUp (const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &us) |
| Handle key up presses. For supported keys see the class desc. More...
|
|
virtual bool | performMovement () |
| MouseLook is implemented in this method. More...
|
|
virtual bool | performMovementLeftMouseButton (const double eventTimeDelta, const double dx, const double dy) |
|
virtual bool | handleMouseWheel (const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &us) |
|
|
bool | performEyeMovement () |
| moves the cameraEye, checking various conditions More...
|
|
bool | intersect (const osg::Vec3d start, const osg::Vec3d end, double &distance) |
| Finds the distance between start and end intersection, if there is any. More...
|
|
bool | groundIntersection (osg::Vec3d &newEye) |
| checks, whether the newEye is still clamped to ground More...
|
|
A FPS style CameraManipulator with ground clamping and intersection.
- Controls:
W = Move forward.
A S D = (A)=Move Left, (S)=Move backward, (D)=Move Right.
F = Toggle FlightMode on/off
Q / E = Up/Down (in FlightMode)
G = Attach/Detach Body
X = Crouch
SPACE = Jump (if not flying)
SHIFT = Sprint
CTRL = Walk
Inspiration for Intersection and Clamping Testing:
Official OSG Source (mostly DriveManipulator)
GameManipulator and Pod by Viggo Løvli, http://markmail.org/message/e6magjobl7fywbe6 , visited 26/05/2014
For Nodes, which should be passable regardless of FlightMode (e.g. FakeWalls) one must set the
NodeMask to ~brtrcollisionMask
Body Code not used anymore (we did not like it). Not deleted, because it works.
- Author
- Gleb Ostrowski
- Version
- 1.0
- Date
- 06/2014
- Precondition
- Need to be attached to a viewer, so, create a viewer first
- Bug:
- Jumping forward if there is no ground is not working
- Copyright
- GNU Public License.
Definition at line 33 of file FPSCameraManipulator.h.
brtr::FPSCameraManipulator::FPSCameraManipulator |
( |
double |
movementSpeed, |
|
|
double |
zHeight, |
|
|
osg::Node * |
root, |
|
|
bool |
flightMode = false |
|
) |
| |
Constructor.
- Parameters
-
movementSpeed | the player "movement" speed |
zHeight | the camera height |
root | root node for attaching the body to, not used anymore |
flightMode | flightmoe true or false in the beginning |
Definition at line 12 of file FPSCameraManipulator.cpp.
brtr::FPSCameraManipulator::~FPSCameraManipulator |
( |
| ) |
|
|
protected |
double brtr::FPSCameraManipulator::getJumpHeight |
( |
| ) |
const |
double brtr::FPSCameraManipulator::getMovementSpeed |
( |
| ) |
const |
double brtr::FPSCameraManipulator::getZHeight |
( |
| ) |
const |
bool brtr::FPSCameraManipulator::groundIntersection |
( |
osg::Vec3d & |
newEye | ) |
|
|
private |
checks, whether the newEye is still clamped to ground
Performs a LineIntersectionTest from newEye to -Z_AXIS * FPSCameraManipulator::_maxFallHeight if a ground is found (any geometry within _maxFallHeight), the z-Value of newEye will be corrected to be _zHeight above ground. some smoothing is applied for not-so-abrupt jumps
- Parameters
-
newEye | the wannabe new cameraEye Position |
- Returns
- true, if Position is valid, false otherwise
Definition at line 246 of file FPSCameraManipulator.cpp.
bool brtr::FPSCameraManipulator::handleFrame |
( |
const osgGA::GUIEventAdapter & |
ea, |
|
|
osgGA::GUIActionAdapter & |
us |
|
) |
| |
|
protectedvirtual |
Handles, what happens every frame.
Every frame there is a movement check, if the player holds one of the move buttons down the camera moves.
- Parameters
-
ea | the GUIEventAdapter |
us | the GUIActionAdapter |
- Returns
- always false otherwise the method would block other frame handle methods
Definition at line 63 of file FPSCameraManipulator.cpp.
bool brtr::FPSCameraManipulator::handleKeyDown |
( |
const osgGA::GUIEventAdapter & |
ea, |
|
|
osgGA::GUIActionAdapter & |
us |
|
) |
| |
|
protectedvirtual |
Handle key down presses. For supported keys see the class desc.
- Parameters
-
- Returns
- true, if the keypress is handled, false otherwise
Definition at line 71 of file FPSCameraManipulator.cpp.
bool brtr::FPSCameraManipulator::handleKeyUp |
( |
const osgGA::GUIEventAdapter & |
ea, |
|
|
osgGA::GUIActionAdapter & |
us |
|
) |
| |
|
protectedvirtual |
Handle key up presses. For supported keys see the class desc.
- Parameters
-
ea | ea the GUIEventAdapter |
us | us the GUIActionAdapter |
- Returns
- true, if the key-de-press is handled, false otherwise
Definition at line 123 of file FPSCameraManipulator.cpp.
bool brtr::FPSCameraManipulator::handleMouseMove |
( |
const osgGA::GUIEventAdapter & |
ea, |
|
|
osgGA::GUIActionAdapter & |
us |
|
) |
| |
|
protectedvirtual |
Handles the movement of the mouse.
Warp the mouse back to the center, adds the mouse movement to the event stack and calls performMovement(). If it was succesfull, request redraw.
- Parameters
-
ea | the GUIEventAdapter |
us | the GUIActionAdapter |
- Returns
- always false otherwise the method would block other mouse movement handle methods
Definition at line 56 of file FPSCameraManipulator.cpp.
bool brtr::FPSCameraManipulator::handleMouseWheel |
( |
const osgGA::GUIEventAdapter & |
ea, |
|
|
osgGA::GUIActionAdapter & |
us |
|
) |
| |
|
protectedvirtual |
bool brtr::FPSCameraManipulator::intersect |
( |
const osg::Vec3d |
start, |
|
|
const osg::Vec3d |
end, |
|
|
double & |
distance |
|
) |
| |
|
private |
Finds the distance between start and end intersection, if there is any.
performs a LineIntersectionTest in Model coordinates, from intersect::start to intersect::end the distance to the nearest intersection point, if any exist, is stored in intersect::distance
- Parameters
-
start | the start point of the line |
end | the end point of the line |
distance | var, which will hold the distance to the nearest intersection point, if any |
- Returns
- true, if there is at least one intersection, false otherwise
Definition at line 263 of file FPSCameraManipulator.cpp.
bool brtr::FPSCameraManipulator::performEyeMovement |
( |
| ) |
|
|
private |
moves the cameraEye, checking various conditions
directions + speed depends on the pressed keys. if flightmode is off, clamping to ground is performed, _zHeight is height of eye also, if flightmode is off, LineIntersection from the eye is performed so no walking trough walls again, with flightmode off, jumping request is also handled if flightmode is on, then just moves the cameraEye
- Returns
- true, if there was any movement, false otherwise
Definition at line 170 of file FPSCameraManipulator.cpp.
bool brtr::FPSCameraManipulator::performMovement |
( |
| ) |
|
|
protectedvirtual |
MouseLook is implemented in this method.
Because the mouse is always at the center, it is enough to get the previous mouse position (_ga_t0, the current position is always the center = _ga_t1) and rotate the camera to that position.
- Returns
- true, if there was any movement, false otherwise
Definition at line 154 of file FPSCameraManipulator.cpp.
bool brtr::FPSCameraManipulator::performMovementLeftMouseButton |
( |
const double |
eventTimeDelta, |
|
|
const double |
dx, |
|
|
const double |
dy |
|
) |
| |
|
protectedvirtual |
bool brtr::FPSCameraManipulator::_attachBody |
|
private |
bool brtr::FPSCameraManipulator::_backwardMovement |
|
private |
osg::ref_ptr<osg::PositionAttitudeTransform> brtr::FPSCameraManipulator::_body |
|
private |
double brtr::FPSCameraManipulator::_bodyLength |
|
private |
bool brtr::FPSCameraManipulator::_crouch |
|
private |
bool brtr::FPSCameraManipulator::_ctrl |
|
private |
bool brtr::FPSCameraManipulator::_downMovement |
|
private |
bool brtr::FPSCameraManipulator::_flightMode |
|
private |
bool brtr::FPSCameraManipulator::_forwardMovement |
|
private |
double brtr::FPSCameraManipulator::_frameFactor |
|
private |
double brtr::FPSCameraManipulator::_intensity |
|
private |
double brtr::FPSCameraManipulator::_jumpHeight |
|
private |
bool brtr::FPSCameraManipulator::_jumpingDown |
|
private |
bool brtr::FPSCameraManipulator::_jumpingUp |
|
private |
bool brtr::FPSCameraManipulator::_leftMovement |
|
private |
double brtr::FPSCameraManipulator::_maxFallHeight |
|
private |
double brtr::FPSCameraManipulator::_movementSpeed |
|
private |
bool brtr::FPSCameraManipulator::_rightMovement |
|
private |
double brtr::FPSCameraManipulator::_savedzHeight |
|
private |
double brtr::FPSCameraManipulator::_savedzHeightCrouch |
|
private |
bool brtr::FPSCameraManipulator::_shift |
|
private |
bool brtr::FPSCameraManipulator::_upMovement |
|
private |
double brtr::FPSCameraManipulator::_zHeight |
|
private |
The documentation for this class was generated from the following files: