2010-05-27 21:59:34 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2010 Robert Osfield
|
2010-05-25 20:05:13 +08:00
|
|
|
*
|
|
|
|
* This library is open source and may be redistributed and/or modified under
|
|
|
|
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*
|
|
|
|
* FirstPersonManipulator code Copyright (C) 2010 PCJohn (Jan Peciva)
|
2010-05-27 21:59:34 +08:00
|
|
|
* while some pieces of code were taken from OSG.
|
2010-05-25 20:05:13 +08:00
|
|
|
* Thanks to company Cadwork (www.cadwork.ch) and
|
|
|
|
* Brno University of Technology (www.fit.vutbr.cz) for open-sourcing this work.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef OSGGA_FIRST_PERSON_MANIPULATOR
|
|
|
|
#define OSGGA_FIRST_PERSON_MANIPULATOR 1
|
|
|
|
|
|
|
|
#include <osgGA/StandardManipulator>
|
|
|
|
|
|
|
|
|
|
|
|
namespace osgGA {
|
|
|
|
|
|
|
|
|
|
|
|
/** FirstPersonManipulator is base class for camera control based on position
|
|
|
|
and orientation of camera, like walk, drive, and flight manipulators. */
|
|
|
|
class OSGGA_EXPORT FirstPersonManipulator : public StandardManipulator
|
|
|
|
{
|
2010-05-26 01:02:11 +08:00
|
|
|
typedef StandardManipulator inherited;
|
2010-05-25 20:05:13 +08:00
|
|
|
|
2010-05-26 01:02:11 +08:00
|
|
|
public:
|
2010-05-25 20:05:13 +08:00
|
|
|
|
2010-05-26 01:02:11 +08:00
|
|
|
FirstPersonManipulator( int flags = DEFAULT_SETTINGS );
|
|
|
|
FirstPersonManipulator( const FirstPersonManipulator& fpm,
|
|
|
|
const osg::CopyOp& copyOp = osg::CopyOp::SHALLOW_COPY );
|
2010-05-25 20:05:13 +08:00
|
|
|
|
2010-05-26 01:02:11 +08:00
|
|
|
META_Object( osgGA, FirstPersonManipulator );
|
2010-05-25 20:05:13 +08:00
|
|
|
|
2010-05-26 01:02:11 +08:00
|
|
|
virtual void setByMatrix( const osg::Matrixd& matrix );
|
|
|
|
virtual void setByInverseMatrix( const osg::Matrixd& matrix );
|
|
|
|
virtual osg::Matrixd getMatrix() const;
|
|
|
|
virtual osg::Matrixd getInverseMatrix() const;
|
2010-05-25 20:05:13 +08:00
|
|
|
|
2010-05-26 01:02:11 +08:00
|
|
|
virtual void setTransformation( const osg::Vec3d& eye, const osg::Quat& rotation );
|
2010-08-16 19:03:24 +08:00
|
|
|
virtual void setTransformation( const osg::Vec3d& eye, const osg::Vec3d& center, const osg::Vec3d& up );
|
2010-05-26 01:02:11 +08:00
|
|
|
virtual void getTransformation( osg::Vec3d& eye, osg::Quat& rotation ) const;
|
2010-08-16 19:03:24 +08:00
|
|
|
virtual void getTransformation( osg::Vec3d& eye, osg::Vec3d& center, osg::Vec3d& up ) const;
|
2010-05-25 20:05:13 +08:00
|
|
|
|
2010-05-26 01:02:11 +08:00
|
|
|
virtual void setVelocity( const double& velocity );
|
|
|
|
inline double getVelocity() const;
|
|
|
|
virtual void setAcceleration( const double& acceleration, bool relativeToModelSize = false );
|
|
|
|
double getAcceleration( bool *relativeToModelSize = NULL ) const;
|
|
|
|
virtual void setMaxVelocity( const double& maxVelocity, bool relativeToModelSize = false );
|
|
|
|
double getMaxVelocity( bool *relativeToModelSize = NULL ) const;
|
2010-05-25 20:05:13 +08:00
|
|
|
|
2010-05-26 01:02:11 +08:00
|
|
|
virtual void setWheelMovement( const double& wheelMovement, bool relativeToModelSize = false );
|
|
|
|
double getWheelMovement( bool *relativeToModelSize = NULL ) const;
|
2010-05-25 20:05:13 +08:00
|
|
|
|
2010-05-26 01:02:11 +08:00
|
|
|
virtual void home( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
|
|
|
|
virtual void home( double );
|
2010-05-25 20:05:13 +08:00
|
|
|
|
2010-05-26 01:02:11 +08:00
|
|
|
virtual void init( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
|
2010-05-25 20:05:13 +08:00
|
|
|
|
2010-05-26 01:02:11 +08:00
|
|
|
protected:
|
2010-05-25 20:05:13 +08:00
|
|
|
|
2010-05-26 01:02:11 +08:00
|
|
|
virtual bool handleMouseWheel( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
|
2010-05-25 20:05:13 +08:00
|
|
|
|
2010-05-27 21:59:34 +08:00
|
|
|
virtual bool performMovementLeftMouseButton( const double eventTimeDelta, const double dx, const double dy );
|
2010-05-26 01:02:11 +08:00
|
|
|
virtual bool performMouseDeltaMovement( const float dx, const float dy );
|
|
|
|
virtual void applyAnimationStep( const double currentProgress, const double prevProgress );
|
|
|
|
virtual bool startAnimationByMousePointerIntersection( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
|
2010-05-25 20:05:13 +08:00
|
|
|
|
2010-05-26 01:02:11 +08:00
|
|
|
void moveForward( const double distance );
|
|
|
|
void moveForward( const osg::Quat& rotation, const double distance );
|
|
|
|
void moveRight( const double distance );
|
|
|
|
void moveUp( const double distance );
|
2010-05-25 20:05:13 +08:00
|
|
|
|
2010-05-26 01:02:11 +08:00
|
|
|
osg::Vec3d _eye;
|
|
|
|
osg::Quat _rotation;
|
|
|
|
double _velocity;
|
2010-05-25 20:05:13 +08:00
|
|
|
|
2010-05-26 01:02:11 +08:00
|
|
|
double _acceleration;
|
|
|
|
static int _accelerationFlagIndex;
|
|
|
|
double _maxVelocity;
|
|
|
|
static int _maxVelocityFlagIndex;
|
|
|
|
double _wheelMovement;
|
|
|
|
static int _wheelMovementFlagIndex;
|
2010-05-25 20:05:13 +08:00
|
|
|
|
2010-05-26 01:02:11 +08:00
|
|
|
class FirstPersonAnimationData : public AnimationData {
|
|
|
|
public:
|
|
|
|
osg::Quat _startRot;
|
|
|
|
osg::Quat _targetRot;
|
|
|
|
void start( const osg::Quat& startRotation, const osg::Quat& targetRotation, const double startTime );
|
|
|
|
};
|
|
|
|
virtual void allocAnimationData() { _animationData = new FirstPersonAnimationData(); }
|
2010-05-25 20:05:13 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// inline methods
|
|
|
|
//
|
|
|
|
|
|
|
|
/// Returns velocity.
|
|
|
|
double FirstPersonManipulator::getVelocity() const { return _velocity; }
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* OSGGA_FIRST_PERSON_MANIPULATOR */
|