1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2010 Robert Osfield
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version. The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * OpenSceneGraph Public License for more details.
13 * FirstPersonManipulator code Copyright (C) 2010 PCJohn (Jan Peciva)
14 * while some pieces of code were taken from OSG.
15 * Thanks to company Cadwork (www.cadwork.ch) and
16 * Brno University of Technology (www.fit.vutbr.cz) for open-sourcing this work.
19#ifndef OSGGA_FIRST_PERSON_MANIPULATOR
20#define OSGGA_FIRST_PERSON_MANIPULATOR 1
22#include <osgGA/StandardManipulator>
28/** FirstPersonManipulator is base class for camera control based on position
29 and orientation of camera, like walk, drive, and flight manipulators. */
30class OSGGA_EXPORT FirstPersonManipulator : public StandardManipulator
32 typedef StandardManipulator inherited;
36 FirstPersonManipulator( int flags = DEFAULT_SETTINGS );
37 FirstPersonManipulator( const FirstPersonManipulator& fpm,
38 const osg::CopyOp& copyOp = osg::CopyOp::SHALLOW_COPY );
40 META_Object( osgGA, FirstPersonManipulator );
42 virtual void setByMatrix( const osg::Matrixd& matrix );
43 virtual void setByInverseMatrix( const osg::Matrixd& matrix );
44 virtual osg::Matrixd getMatrix() const;
45 virtual osg::Matrixd getInverseMatrix() const;
47 virtual void setTransformation( const osg::Vec3d& eye, const osg::Quat& rotation );
48 virtual void setTransformation( const osg::Vec3d& eye, const osg::Vec3d& center, const osg::Vec3d& up );
49 virtual void getTransformation( osg::Vec3d& eye, osg::Quat& rotation ) const;
50 virtual void getTransformation( osg::Vec3d& eye, osg::Vec3d& center, osg::Vec3d& up ) const;
52 virtual void setVelocity( const double& velocity );
53 inline double getVelocity() const;
54 virtual void setAcceleration( const double& acceleration, bool relativeToModelSize = false );
55 double getAcceleration( bool *relativeToModelSize = NULL ) const;
56 virtual void setMaxVelocity( const double& maxVelocity, bool relativeToModelSize = false );
57 double getMaxVelocity( bool *relativeToModelSize = NULL ) const;
59 virtual void setWheelMovement( const double& wheelMovement, bool relativeToModelSize = false );
60 double getWheelMovement( bool *relativeToModelSize = NULL ) const;
62 virtual void home( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
63 virtual void home( double );
65 virtual void init( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
69 virtual bool handleMouseWheel( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
71 virtual bool performMovementLeftMouseButton( const double eventTimeDelta, const double dx, const double dy );
72 virtual bool performMouseDeltaMovement( const float dx, const float dy );
73 virtual void applyAnimationStep( const double currentProgress, const double prevProgress );
74 virtual bool startAnimationByMousePointerIntersection( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
76 void moveForward( const double distance );
77 void moveForward( const osg::Quat& rotation, const double distance );
78 void moveRight( const double distance );
79 void moveUp( const double distance );
86 static int _accelerationFlagIndex;
88 static int _maxVelocityFlagIndex;
89 double _wheelMovement;
90 static int _wheelMovementFlagIndex;
92 class FirstPersonAnimationData : public AnimationData {
96 void start( const osg::Quat& startRotation, const osg::Quat& targetRotation, const double startTime );
98 virtual void allocAnimationData() { _animationData = new FirstPersonAnimationData(); }
107double FirstPersonManipulator::getVelocity() const { return _velocity; }
112#endif /* OSGGA_FIRST_PERSON_MANIPULATOR */