StandardManipulator
Go to the documentation of this file.
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2010 Robert Osfield
*
* 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.
*
* StandardManipulator code Copyright (C) 2010 PCJohn (Jan Peciva)
* while some pieces of code were taken from OSG.
* Thanks to company Cadwork (www.cadwork.ch) and
* Brno University of Technology (www.fit.vutbr.cz) for open-sourcing this work.
*/
#ifndef OSGGA_CAMERA_MANIPULATOR
#define OSGGA_CAMERA_MANIPULATOR 1
#include <osgGA/CameraManipulator>
namespace osgGA {
class OSGGA_EXPORT StandardManipulator : public CameraManipulator
{
typedef CameraManipulator inherited;
public:
// flags
enum UserInteractionFlags
{
UPDATE_MODEL_SIZE = 0x01,
COMPUTE_HOME_USING_BBOX = 0x02,
PROCESS_MOUSE_WHEEL = 0x04,
SET_CENTER_ON_WHEEL_FORWARD_MOVEMENT = 0x08,
DEFAULT_SETTINGS = UPDATE_MODEL_SIZE /*| COMPUTE_HOME_USING_BBOX*/ | PROCESS_MOUSE_WHEEL
};
StandardManipulator( int flags = DEFAULT_SETTINGS );
StandardManipulator( const StandardManipulator& m,
const osg::CopyOp& copyOp = osg::CopyOp::SHALLOW_COPY );
// We are not using META_Object as this is abstract class.
// Use META_Object(osgGA,YourManipulator); in your descendant non-abstract classes.
virtual const char* className() const { return "StandardManipulator"; }
virtual void setTransformation( const osg::Vec3d& eye, const osg::Quat& rotation ) = 0;
virtual void setTransformation( const osg::Vec3d& eye, const osg::Vec3d& center, const osg::Vec3d& up ) = 0;
virtual void getTransformation( osg::Vec3d& eye, osg::Quat& rotation ) const = 0;
virtual void getTransformation( osg::Vec3d& eye, osg::Vec3d& center, osg::Vec3d& up ) const = 0;
virtual void setNode( osg::Node* );
virtual const osg::Node* getNode() const;
virtual osg::Node* getNode();
virtual void setVerticalAxisFixed( bool value );
inline bool getVerticalAxisFixed() const;
inline bool getAllowThrow() const;
virtual void setAllowThrow( bool allowThrow );
virtual void setAnimationTime( const double t );
double getAnimationTime() const;
bool isAnimating() const;
virtual void finishAnimation();
virtual void home( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
virtual void home( double );
virtual void init( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
virtual bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
virtual void getUsage( osg::ApplicationUsage& usage ) const;
protected:
virtual bool handleFrame( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
virtual bool handleResize( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
virtual bool handleMouseMove( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
virtual bool handleMouseDrag( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
virtual bool handleMousePush( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
virtual bool handleMouseRelease( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
virtual bool handleKeyDown( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
virtual bool handleKeyUp( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
virtual bool handleMouseWheel( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
virtual bool handleMouseDeltaMovement( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
virtual bool performMovement();
virtual bool performMovementLeftMouseButton( const double eventTimeDelta, const double dx, const double dy );
virtual bool performMovementMiddleMouseButton( const double eventTimeDelta, const double dx, const double dy );
virtual bool performMovementRightMouseButton( const double eventTimeDelta, const double dx, const double dy );
virtual bool performMouseDeltaMovement( const float dx, const float dy );
virtual bool performAnimationMovement( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
virtual void applyAnimationStep( const double currentProgress, const double prevProgress );
void addMouseEvent( const osgGA::GUIEventAdapter& ea );
void flushMouseEventStack();
virtual bool isMouseMoving() const;
float getThrowScale( const double eventTimeDelta ) const;
virtual void centerMousePointer( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
static void rotateYawPitch( osg::Quat& rotation, const double yaw, const double pitch,
const osg::Vec3d& localUp = osg::Vec3d( 0.,0.,0.) );
static void fixVerticalAxis( osg::Quat& rotation, const osg::Vec3d& localUp, bool disallowFlipOver );
void fixVerticalAxis( osg::Vec3d& eye, osg::Quat& rotation, bool disallowFlipOver );
static void fixVerticalAxis( const osg::Vec3d& forward, const osg::Vec3d& up, osg::Vec3d& newUp,
const osg::Vec3d& localUp, bool disallowFlipOver );
virtual bool setCenterByMousePointerIntersection( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
virtual bool startAnimationByMousePointerIntersection( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
// mouse state
bool _thrown;
bool _allowThrow;
float _mouseCenterX, _mouseCenterY;
// internal event stack comprising last two mouse events.
osg::ref_ptr< const osgGA::GUIEventAdapter > _ga_t1;
osg::ref_ptr< const osgGA::GUIEventAdapter > _ga_t0;
double _delta_frame_time;
double _last_frame_time;
// scene data
osg::ref_ptr< osg::Node > _node;
double _modelSize;
bool _verticalAxisFixed;
// animation stuff
class OSGGA_EXPORT AnimationData : public osg::Referenced {
public:
double _animationTime;
bool _isAnimating;
double _startTime;
double _phase;
AnimationData();
void start( const double startTime );
};
osg::ref_ptr< AnimationData > _animationData;
virtual void allocAnimationData() { _animationData = new AnimationData(); }
// flags
int _flags;
// flags indicating that a value is relative to model size
int _relativeFlags;
inline bool getRelativeFlag( int index ) const;
inline void setRelativeFlag( int index, bool value );
static int numRelativeFlagsAllocated;
static int allocateRelativeFlag();
};
//
// inline methods
//
inline bool StandardManipulator::getRelativeFlag( int index ) const
{
return ( _relativeFlags & (0x01 << index) ) != 0;
}
inline void StandardManipulator::setRelativeFlag( int index, bool value )
{
if( value ) _relativeFlags |= (0x01 << index);
else _relativeFlags &= ~(0x01 << index);
}
inline bool StandardManipulator::getVerticalAxisFixed() const
{
return _verticalAxisFixed;
}
inline bool StandardManipulator::getAllowThrow() const
{
return _allowThrow;
}
}
#endif /* OSGGA_CAMERA_MANIPULATOR */
CameraManipulator
osgGA::CameraManipulator::CameraManipulator
CameraManipulator()
osgGA::GUIActionAdapter
Definition GUIActionAdapter:62
osgGA::GUIEventAdapter
Definition GUIEventAdapter:82
osgGA::StandardManipulator::AnimationData
Definition StandardManipulator:149
osgGA::StandardManipulator::AnimationData::_animationTime
double _animationTime
Definition StandardManipulator:151
osgGA::StandardManipulator::AnimationData::AnimationData
AnimationData()
osgGA::StandardManipulator::AnimationData::_isAnimating
bool _isAnimating
Definition StandardManipulator:152
osgGA::StandardManipulator::AnimationData::start
void start(const double startTime)
osgGA::StandardManipulator::AnimationData::_startTime
double _startTime
Definition StandardManipulator:153
osgGA::StandardManipulator::AnimationData::_phase
double _phase
Definition StandardManipulator:154
osgGA::StandardManipulator::_last_frame_time
double _last_frame_time
Definition StandardManipulator:141
osgGA::StandardManipulator::StandardManipulator
StandardManipulator(const StandardManipulator &m, const osg::CopyOp &copyOp=osg::CopyOp::SHALLOW_COPY)
osgGA::StandardManipulator::className
virtual const char * className() const
Definition StandardManipulator:52
osgGA::StandardManipulator::handleMouseRelease
virtual bool handleMouseRelease(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &us)
osgGA::StandardManipulator::_delta_frame_time
double _delta_frame_time
Definition StandardManipulator:136
osgGA::StandardManipulator::getTransformation
virtual void getTransformation(osg::Vec3d &eye, osg::Vec3d &center, osg::Vec3d &up) const =0
osgGA::StandardManipulator::getTransformation
virtual void getTransformation(osg::Vec3d &eye, osg::Quat &rotation) const =0
osgGA::StandardManipulator::setTransformation
virtual void setTransformation(const osg::Vec3d &eye, const osg::Vec3d &center, const osg::Vec3d &up)=0
osgGA::StandardManipulator::StandardManipulator
StandardManipulator(int flags=DEFAULT_SETTINGS)
osgGA::StandardManipulator::_ga_t0
osg::ref_ptr< const osgGA::GUIEventAdapter > _ga_t0
Definition StandardManipulator:130
osgGA::StandardManipulator::init
virtual void init(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &us)
osgGA::StandardManipulator::numRelativeFlagsAllocated
static int numRelativeFlagsAllocated
Definition StandardManipulator:169
osgGA::StandardManipulator::flushMouseEventStack
void flushMouseEventStack()
osgGA::StandardManipulator::handleKeyUp
virtual bool handleKeyUp(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &us)
osgGA::StandardManipulator::rotateYawPitch
static void rotateYawPitch(osg::Quat &rotation, const double yaw, const double pitch, const osg::Vec3d &localUp=osg::Vec3d(0., 0., 0.))
osgGA::StandardManipulator::performMovementLeftMouseButton
virtual bool performMovementLeftMouseButton(const double eventTimeDelta, const double dx, const double dy)
osgGA::StandardManipulator::applyAnimationStep
virtual void applyAnimationStep(const double currentProgress, const double prevProgress)
osgGA::StandardManipulator::handleMouseMove
virtual bool handleMouseMove(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &us)
osgGA::StandardManipulator::getVerticalAxisFixed
bool getVerticalAxisFixed() const
Returns whether manipulator preserves camera's "UP" vector.
Definition StandardManipulator:190
osgGA::StandardManipulator::handleFrame
virtual bool handleFrame(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &us)
osgGA::StandardManipulator::getNode
virtual const osg::Node * getNode() const
osgGA::StandardManipulator::handle
virtual bool handle(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &us)
osgGA::StandardManipulator::isAnimating
bool isAnimating() const
osgGA::StandardManipulator::performMovement
virtual bool performMovement()
osgGA::StandardManipulator::home
virtual void home(double)
osgGA::StandardManipulator::_thrown
bool _thrown
Definition StandardManipulator:124
osgGA::StandardManipulator::allocateRelativeFlag
static int allocateRelativeFlag()
osgGA::StandardManipulator::getUsage
virtual void getUsage(osg::ApplicationUsage &usage) const
osgGA::StandardManipulator::performAnimationMovement
virtual bool performAnimationMovement(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &us)
osgGA::StandardManipulator::isMouseMoving
virtual bool isMouseMoving() const
osgGA::StandardManipulator::performMouseDeltaMovement
virtual bool performMouseDeltaMovement(const float dx, const float dy)
osgGA::StandardManipulator::handleMousePush
virtual bool handleMousePush(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &us)
osgGA::StandardManipulator::startAnimationByMousePointerIntersection
virtual bool startAnimationByMousePointerIntersection(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &us)
osgGA::StandardManipulator::setAnimationTime
virtual void setAnimationTime(const double t)
osgGA::StandardManipulator::_modelSize
double _modelSize
Definition StandardManipulator:145
osgGA::StandardManipulator::getRelativeFlag
bool getRelativeFlag(int index) const
Definition StandardManipulator:178
osgGA::StandardManipulator::setTransformation
virtual void setTransformation(const osg::Vec3d &eye, const osg::Quat &rotation)=0
osgGA::StandardManipulator::handleMouseDeltaMovement
virtual bool handleMouseDeltaMovement(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &us)
osgGA::StandardManipulator::performMovementRightMouseButton
virtual bool performMovementRightMouseButton(const double eventTimeDelta, const double dx, const double dy)
osgGA::StandardManipulator::UserInteractionFlags
UserInteractionFlags
Definition StandardManipulator:38
osgGA::StandardManipulator::COMPUTE_HOME_USING_BBOX
@ COMPUTE_HOME_USING_BBOX
Definition StandardManipulator:40
osgGA::StandardManipulator::PROCESS_MOUSE_WHEEL
@ PROCESS_MOUSE_WHEEL
Definition StandardManipulator:41
osgGA::StandardManipulator::UPDATE_MODEL_SIZE
@ UPDATE_MODEL_SIZE
Definition StandardManipulator:39
osgGA::StandardManipulator::DEFAULT_SETTINGS
@ DEFAULT_SETTINGS
Definition StandardManipulator:43
osgGA::StandardManipulator::SET_CENTER_ON_WHEEL_FORWARD_MOVEMENT
@ SET_CENTER_ON_WHEEL_FORWARD_MOVEMENT
Definition StandardManipulator:42
osgGA::StandardManipulator::setCenterByMousePointerIntersection
virtual bool setCenterByMousePointerIntersection(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &us)
osgGA::StandardManipulator::_mouseCenterX
float _mouseCenterX
Definition StandardManipulator:126
osgGA::StandardManipulator::_relativeFlags
int _relativeFlags
Definition StandardManipulator:166
osgGA::StandardManipulator::getNode
virtual osg::Node * getNode()
osgGA::StandardManipulator::handleMouseWheel
virtual bool handleMouseWheel(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &us)
osgGA::StandardManipulator::home
virtual void home(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &us)
osgGA::StandardManipulator::finishAnimation
virtual void finishAnimation()
osgGA::StandardManipulator::setVerticalAxisFixed
virtual void setVerticalAxisFixed(bool value)
osgGA::StandardManipulator::getThrowScale
float getThrowScale(const double eventTimeDelta) const
osgGA::StandardManipulator::setRelativeFlag
void setRelativeFlag(int index, bool value)
Definition StandardManipulator:183
osgGA::StandardManipulator::performMovementMiddleMouseButton
virtual bool performMovementMiddleMouseButton(const double eventTimeDelta, const double dx, const double dy)
osgGA::StandardManipulator::setNode
virtual void setNode(osg::Node *)
osgGA::StandardManipulator::getAnimationTime
double getAnimationTime() const
osgGA::StandardManipulator::handleMouseDrag
virtual bool handleMouseDrag(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &us)
osgGA::StandardManipulator::_animationData
osg::ref_ptr< AnimationData > _animationData
Definition StandardManipulator:159
osgGA::StandardManipulator::_flags
int _flags
Definition StandardManipulator:163
osgGA::StandardManipulator::centerMousePointer
virtual void centerMousePointer(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &us)
osgGA::StandardManipulator::fixVerticalAxis
static void fixVerticalAxis(osg::Quat &rotation, const osg::Vec3d &localUp, bool disallowFlipOver)
osgGA::StandardManipulator::_verticalAxisFixed
bool _verticalAxisFixed
Definition StandardManipulator:146
osgGA::StandardManipulator::fixVerticalAxis
void fixVerticalAxis(osg::Vec3d &eye, osg::Quat &rotation, bool disallowFlipOver)
osgGA::StandardManipulator::_ga_t1
osg::ref_ptr< const osgGA::GUIEventAdapter > _ga_t1
Definition StandardManipulator:129
osgGA::StandardManipulator::handleKeyDown
virtual bool handleKeyDown(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &us)
osgGA::StandardManipulator::setAllowThrow
virtual void setAllowThrow(bool allowThrow)
osgGA::StandardManipulator::_mouseCenterY
float _mouseCenterY
Definition StandardManipulator:126
osgGA::StandardManipulator::handleResize
virtual bool handleResize(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &us)
osgGA::StandardManipulator::fixVerticalAxis
static void fixVerticalAxis(const osg::Vec3d &forward, const osg::Vec3d &up, osg::Vec3d &newUp, const osg::Vec3d &localUp, bool disallowFlipOver)
osgGA::StandardManipulator::allocAnimationData
virtual void allocAnimationData()
Definition StandardManipulator:160
osgGA::StandardManipulator::getAllowThrow
bool getAllowThrow() const
Returns true if the camera can be thrown, false otherwise. It defaults to true.
Definition StandardManipulator:196
osgGA::StandardManipulator::addMouseEvent
void addMouseEvent(const osgGA::GUIEventAdapter &ea)
osgGA::StandardManipulator::_node
osg::ref_ptr< osg::Node > _node
Definition StandardManipulator:144
osgGA::StandardManipulator::_allowThrow
bool _allowThrow
Definition StandardManipulator:125
osg::ApplicationUsage
Definition ApplicationUsage:26
osg::CopyOp
Definition CopyOp:41
osg::CopyOp::SHALLOW_COPY
@ SHALLOW_COPY
Definition CopyOp:47
osg::Node
Definition Node:72
osg::Quat
Definition Quat:30
osg::Referenced
Definition Referenced:44
osg::Vec3d
Definition Vec3d:30
osg::ref_ptr< const osgGA::GUIEventAdapter >
osgGA
Definition Callback:21
OSGGA_EXPORT
#define OSGGA_EXPORT
Definition osgGA/Export:40