40#ifndef AGXOSG_FIRST_PERSON_MANIPULATOR
41#define AGXOSG_FIRST_PERSON_MANIPULATOR
45#if defined(OSG_VERSION_GREATER_OR_EQUAL)
46# if OSG_VERSION_GREATER_OR_EQUAL(2,9,11)
50#include <osgGA/StandardManipulator>
51#include <osgGA/TrackballManipulator>
52#include <osgViewer/Viewer>
75class AGXOSG_EXPORT FirstPersonManipulator :
public osgGA::StandardManipulator
77 typedef StandardManipulator inherited;
81 FirstPersonManipulator( osgViewer::GraphicsWindow* window,
int flags = DEFAULT_SETTINGS );
82 FirstPersonManipulator(
const FirstPersonManipulator& fpm,
83 const osg::CopyOp& copyOp = osg::CopyOp::SHALLOW_COPY );
85 META_Object( osgGA, FirstPersonManipulator );
87 virtual void setByMatrix(
const osg::Matrixd& matrix );
88 virtual void setByInverseMatrix(
const osg::Matrixd& matrix );
89 virtual osg::Matrixd getMatrix()
const;
90 virtual osg::Matrixd getInverseMatrix()
const;
92 virtual void setTransformation(
const osg::Vec3d& eye,
const osg::Quat& rotation );
93 virtual void setTransformation(
const osg::Vec3d& eye,
const osg::Vec3d& center,
const osg::Vec3d& up );
94 virtual void getTransformation( osg::Vec3d& eye, osg::Quat& rotation )
const;
95 virtual void getTransformation( osg::Vec3d& eye, osg::Vec3d& center, osg::Vec3d& up )
const;
97 virtual void setVelocity(
const double& velocity );
98 inline double getVelocity()
const;
99 void setRotationSpeed(
const double& rotationSpeed );
100 inline double getRotationSpeed()
const;
101 virtual void setAcceleration(
const double& acceleration,
bool relativeToModelSize =
false );
102 double getAcceleration(
bool *relativeToModelSize =
nullptr )
const;
103 virtual void setMaxVelocity(
const double& maxVelocity,
bool relativeToModelSize =
false );
104 double getMaxVelocity(
bool *relativeToModelSize =
nullptr )
const;
106 virtual void setMovement(
const double& wheelMovement,
bool relativeToModelSize =
false );
107 double getMovement(
bool *relativeToModelSize =
nullptr )
const;
109 virtual void home(
const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
110 virtual void home(
double );
112 virtual void init(
const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
115 FirstPersonManipulator();
117 virtual bool handleFrame(
const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
118 virtual bool handleKeyDown(
const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
119 virtual bool handleKeyUp(
const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
121 virtual bool handleMouseWheel(
const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
123 virtual bool handleMousePush(
const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
124 virtual bool handleMouseRelease(
const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
127 virtual bool performMouseDeltaMovement(
const float dx,
const float dy );
128 virtual void applyAnimationStep(
const double currentProgress,
const double prevProgress );
129 virtual bool startAnimationByMousePointerIntersection(
const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
131 void moveForward(
const double distance );
132 void moveForward(
const osg::Quat& rotation,
const double distance );
133 void moveRight(
const double distance );
134 void moveUp(
const double distance );
136 void handleContinuousEvents(
agx::Real dt);
139 osg::Quat m_rotation;
141 double m_rotationSpeed;
142 double m_acceleration;
143 static int m_accelerationFlagIndex;
145 static int m_maxVelocityFlagIndex;
147 static int m_movementFlagIndex;
151 bool m_mousedDraggedFirstFrame;
154 osg::observer_ptr<osgViewer::GraphicsWindow> m_window;
157 class FirstPersonAnimationData :
public AnimationData {
159 osg::Quat m_startRot;
160 osg::Quat m_targetRot;
161 void start(
const osg::Quat& startRotation,
const osg::Quat& targetRotation,
const double startTime );
163 virtual void allocAnimationData() { _animationData =
new FirstPersonAnimationData(); }
172double FirstPersonManipulator::getVelocity()
const {
return m_velocity; }
176double FirstPersonManipulator::getRotationSpeed()
const {
return m_rotationSpeed; }
Inheritance with partial specialization due to bug with ref_ptr containers.
The Timer class permits timing execution speed with the same refinement as the built in hardware cloc...
The agxOSG namespace provides functionality for visualizing AGX simulations with OpenSceneGraph.
void AGXPHYSICS_EXPORT init()
Initialize AGX Dynamics API including thread resources and must be executed before using the AGX API.