From Jan Perciva with changes from Robert Osfield, "I am submitting improved osgGA camera manipulators.
Changes: - new mouse wheel zoom/movement/center functionality - ability to fix vertical axis (important for CAD) - possibility to specify values as absolute values or relative to model size - kind of backward compatibility by flags passed to constructor - and much more - restructuring classes to use kind of hierarchy and standard way of event processing (handle methods). This way, there is much more code reusability and it is more easy to develop new kinds of manipulators. Briefly, the new architecture keeps MatrixManipulator as base abstract class. StandardManipulator is the feature-rich standard manipulator with two main descendant classes: OrbitManipulator and FirstPersonManipulator. OrbitManipulator is base class for all trackball style manipulators, based on center, rotation and distance from center. FirstPersonManipulator is base for walk or fly style manipulators, using position and rotation for camera manipulation. " Changes by Robert: Replaced osg::Vec3 by osg::Vec3d, introduced DEFAULT_SETTINGS enum and usage. Added frame time member variables in prep for improving throw animation when vysync is off.
This commit is contained in:
112
include/osgGA/FirstPersonManipulator
Normal file
112
include/osgGA/FirstPersonManipulator
Normal file
@@ -0,0 +1,112 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 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.
|
||||
*
|
||||
* FirstPersonManipulator code Copyright (C) 2010 PCJohn (Jan Peciva)
|
||||
* while some pieces of code were reused 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_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
|
||||
{
|
||||
typedef StandardManipulator inherited;
|
||||
|
||||
public:
|
||||
|
||||
FirstPersonManipulator( int flags = DEFAULT_SETTINGS );
|
||||
FirstPersonManipulator( const FirstPersonManipulator& fpm,
|
||||
const osg::CopyOp& copyOp = osg::CopyOp::SHALLOW_COPY );
|
||||
|
||||
META_Object( osgGA, FirstPersonManipulator );
|
||||
|
||||
virtual void setByMatrix( const osg::Matrixd& matrix );
|
||||
virtual void setByInverseMatrix( const osg::Matrixd& matrix );
|
||||
virtual osg::Matrixd getMatrix() const;
|
||||
virtual osg::Matrixd getInverseMatrix() const;
|
||||
|
||||
virtual void setTransformation( const osg::Vec3d& eye, const osg::Quat& rotation );
|
||||
virtual void setTransformation( const osg::Vec3d& center, const osg::Vec3d& eye, const osg::Vec3d& up );
|
||||
virtual void getTransformation( osg::Vec3d& eye, osg::Quat& rotation ) const;
|
||||
virtual void getTransformation( osg::Vec3d& center, osg::Vec3d& eye, osg::Vec3d& up ) const;
|
||||
|
||||
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;
|
||||
|
||||
virtual void setWheelMovement( const double& wheelMovement, bool relativeToModelSize = false );
|
||||
double getWheelMovement( bool *relativeToModelSize = NULL ) const;
|
||||
|
||||
virtual void home( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
|
||||
virtual void home( double );
|
||||
|
||||
virtual void init( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
|
||||
|
||||
protected:
|
||||
|
||||
virtual bool handleMouseWheel( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
|
||||
|
||||
virtual bool performMovementLeftMouseButton( const double dt, const double dx, const double dy );
|
||||
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 );
|
||||
|
||||
void moveForward( const double distance );
|
||||
void moveForward( const osg::Quat& rotation, const double distance );
|
||||
void moveRight( const double distance );
|
||||
void moveUp( const double distance );
|
||||
|
||||
osg::Vec3d _eye;
|
||||
osg::Quat _rotation;
|
||||
double _velocity;
|
||||
|
||||
double _acceleration;
|
||||
static int _accelerationFlagIndex;
|
||||
double _maxVelocity;
|
||||
static int _maxVelocityFlagIndex;
|
||||
double _wheelMovement;
|
||||
static int _wheelMovementFlagIndex;
|
||||
|
||||
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(); }
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// inline methods
|
||||
//
|
||||
|
||||
/// Returns velocity.
|
||||
double FirstPersonManipulator::getVelocity() const { return _velocity; }
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif /* OSGGA_FIRST_PERSON_MANIPULATOR */
|
||||
@@ -1,119 +1,82 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 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
|
||||
* 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
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef OSGGA_FLIGHTMANIPULATOR
|
||||
#define OSGGA_FLIGHTMANIPULATOR 1
|
||||
#ifndef OSGGA_FLIGHT_MANIPULATOR
|
||||
#define OSGGA_FLIGHT_MANIPULATOR 1
|
||||
|
||||
#include <osgGA/MatrixManipulator>
|
||||
#include <osg/Quat>
|
||||
#include <osgGA/FirstPersonManipulator>
|
||||
|
||||
namespace osgGA{
|
||||
|
||||
/**
|
||||
FlightManipulator is a MatrixManipulator which provides flight simulator-like
|
||||
updating of the camera position & orientation. By default, the left mouse
|
||||
button accelerates, the right mouse button decelerates, and the middle mouse
|
||||
button (or left and right simultaneously) stops dead.
|
||||
*/
|
||||
namespace osgGA {
|
||||
|
||||
class OSGGA_EXPORT FlightManipulator : public MatrixManipulator
|
||||
|
||||
/** FlightManipulator is a MatrixManipulator which provides flight simulator-like
|
||||
* updating of the camera position & orientation. By default, the left mouse
|
||||
* button accelerates, the right mouse button decelerates, and the middle mouse
|
||||
* button (or left and right simultaneously) stops dead.
|
||||
*/
|
||||
class OSGGA_EXPORT FlightManipulator : public FirstPersonManipulator
|
||||
{
|
||||
public:
|
||||
typedef FirstPersonManipulator inherited;
|
||||
|
||||
FlightManipulator();
|
||||
public:
|
||||
|
||||
virtual const char* className() const { return "Flight"; }
|
||||
enum YawControlMode {
|
||||
YAW_AUTOMATICALLY_WHEN_BANKED,
|
||||
NO_AUTOMATIC_YAW
|
||||
};
|
||||
|
||||
/** set the position of the matrix manipulator using a 4x4 Matrix.*/
|
||||
virtual void setByMatrix(const osg::Matrixd& matrix);
|
||||
FlightManipulator( int flags = UPDATE_MODEL_SIZE | COMPUTE_HOME_USING_BBOX );
|
||||
FlightManipulator( const FlightManipulator& fpm,
|
||||
const osg::CopyOp& copyOp = osg::CopyOp::SHALLOW_COPY );
|
||||
|
||||
/** set the position of the matrix manipulator using a 4x4 Matrix.*/
|
||||
virtual void setByInverseMatrix(const osg::Matrixd& matrix) { setByMatrix(osg::Matrixd::inverse(matrix)); }
|
||||
META_Object( osgGA, FlightManipulator );
|
||||
|
||||
/** get the position of the manipulator as 4x4 Matrix.*/
|
||||
virtual osg::Matrixd getMatrix() const;
|
||||
virtual void setYawControlMode( YawControlMode ycm );
|
||||
inline YawControlMode getYawControlMode() const;
|
||||
|
||||
/** get the position of the manipulator as a inverse matrix of the manipulator, typically used as a model view matrix.*/
|
||||
virtual osg::Matrixd getInverseMatrix() const;
|
||||
virtual void home( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
|
||||
virtual void init( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
|
||||
virtual void getUsage( osg::ApplicationUsage& usage ) const;
|
||||
|
||||
protected:
|
||||
|
||||
virtual void setNode(osg::Node*);
|
||||
virtual bool handleFrame( 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 flightHandleEvent( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
|
||||
|
||||
virtual const osg::Node* getNode() const;
|
||||
virtual bool performMovement();
|
||||
virtual bool performMovementLeftMouseButton( const double dt, const double dx, const double dy );
|
||||
virtual bool performMovementMiddleMouseButton( const double dt, const double dx, const double dy );
|
||||
virtual bool performMovementRightMouseButton( const double dt, const double dx, const double dy );
|
||||
|
||||
virtual osg::Node* getNode();
|
||||
|
||||
virtual void home(const GUIEventAdapter& ea,GUIActionAdapter& us);
|
||||
|
||||
virtual void init(const GUIEventAdapter& ea,GUIActionAdapter& us);
|
||||
|
||||
virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& us);
|
||||
|
||||
/** Get the keyboard and mouse usage of this manipulator.*/
|
||||
virtual void getUsage(osg::ApplicationUsage& usage) const;
|
||||
|
||||
enum YawControlMode {
|
||||
YAW_AUTOMATICALLY_WHEN_BANKED,
|
||||
NO_AUTOMATIC_YAW
|
||||
};
|
||||
|
||||
/** Configure the Yaw control for the flight model. */
|
||||
void setYawControlMode(YawControlMode ycm) { _yawMode = ycm; }
|
||||
|
||||
void setModelScale(double in_ms) { _modelScale = in_ms; }
|
||||
double getModelScale() const { return _modelScale; }
|
||||
|
||||
void setAcceleration(double in_acc) { _acceleration = in_acc; }
|
||||
double getAcceleration() const { return _acceleration; }
|
||||
|
||||
void setVelocity(double in_vel) { _velocity = in_vel; }
|
||||
double getVelocity() const { return _velocity; }
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~FlightManipulator();
|
||||
|
||||
/** Reset the internal GUIEvent stack.*/
|
||||
void flushMouseEventStack();
|
||||
/** Add the current mouse GUIEvent to internal stack.*/
|
||||
void addMouseEvent(const GUIEventAdapter& ea);
|
||||
|
||||
void computePosition(const osg::Vec3& eye,const osg::Vec3& lv,const osg::Vec3& up);
|
||||
|
||||
/** For the give mouse movement calculate the movement of the camera.
|
||||
Return true is camera has moved and a redraw is required.*/
|
||||
bool calcMovement();
|
||||
|
||||
|
||||
// Internal event stack comprising last two mouse events.
|
||||
osg::ref_ptr<const GUIEventAdapter> _ga_t1;
|
||||
osg::ref_ptr<const GUIEventAdapter> _ga_t0;
|
||||
|
||||
osg::observer_ptr<osg::Node> _node;
|
||||
|
||||
double _modelScale;
|
||||
double _acceleration;
|
||||
double _velocity;
|
||||
|
||||
YawControlMode _yawMode;
|
||||
|
||||
osg::Vec3d _eye;
|
||||
osg::Quat _rotation;
|
||||
double _distance;
|
||||
YawControlMode _yawMode;
|
||||
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// inline methods
|
||||
//
|
||||
|
||||
/// Returns the Yaw control for the flight model.
|
||||
inline FlightManipulator::YawControlMode FlightManipulator::getYawControlMode() const { return _yawMode; }
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* OSGGA_FLIGHT_MANIPULATOR */
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 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
|
||||
* 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
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
@@ -57,7 +57,7 @@ public:
|
||||
|
||||
/** Get the const complete list of manipulators attached to this keyswitch manipulator.*/
|
||||
const KeyManipMap& getKeyManipMap() const { return _manips; }
|
||||
|
||||
|
||||
|
||||
/** Get the current active manipulators.*/
|
||||
MatrixManipulator* getCurrentMatrixManipulator() { return _current.get(); }
|
||||
@@ -81,10 +81,6 @@ public:
|
||||
|
||||
// Overrides from MatrixManipulator...
|
||||
|
||||
/** set the minimum distance (as ratio) the eye point can be zoomed in towards the
|
||||
center before the center is pushed forward.*/
|
||||
virtual void setMinimumDistance(float minimumDistance);
|
||||
|
||||
/** set the coordinate frame which callback tells the manipulator which way is up, east and north.*/
|
||||
virtual void setCoordinateFrameCallback(CoordinateFrameCallback* cb);
|
||||
|
||||
@@ -106,12 +102,6 @@ public:
|
||||
/** Get the FusionDistanceValue. Used by SceneView for setting up stereo convergence.*/
|
||||
virtual float getFusionDistanceValue() const { return _current->getFusionDistanceValue(); }
|
||||
|
||||
/** Set the distance property. */
|
||||
void setDistance(double distance);
|
||||
|
||||
/** Get the distance property. */
|
||||
double getDistance() const;
|
||||
|
||||
|
||||
virtual void setNode(osg::Node* n);
|
||||
|
||||
@@ -125,7 +115,7 @@ public:
|
||||
|
||||
virtual void computeHomePosition();
|
||||
|
||||
virtual void home(const GUIEventAdapter& ee,GUIActionAdapter& aa) { if (_current.valid()) _current->home(ee,aa); }
|
||||
virtual void home(const GUIEventAdapter& ee,GUIActionAdapter& aa);
|
||||
|
||||
virtual void init(const GUIEventAdapter& ee,GUIActionAdapter& aa) { if (_current.valid()) _current->init(ee,aa); }
|
||||
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 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
|
||||
* 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
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
@@ -36,13 +36,16 @@ amount of default functionality, for classes which wish to control OSG cameras
|
||||
in response to GUI events.
|
||||
|
||||
*/
|
||||
class OSGGA_EXPORT MatrixManipulator : public GUIEventHandler
|
||||
{
|
||||
class OSGGA_EXPORT MatrixManipulator : public GUIEventHandler {
|
||||
|
||||
typedef GUIEventHandler inherited;
|
||||
|
||||
public:
|
||||
|
||||
|
||||
// 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 "MatrixManipulator"; }
|
||||
|
||||
|
||||
/** callback class to use to allow matrix manipulators to query the application for the local coordinate frame.*/
|
||||
class CoordinateFrameCallback : public osg::Referenced
|
||||
{
|
||||
@@ -51,16 +54,6 @@ public:
|
||||
protected:
|
||||
virtual ~CoordinateFrameCallback() {}
|
||||
};
|
||||
|
||||
|
||||
|
||||
/** set the minimum distance (as ratio) the eye point can be zoomed in towards the
|
||||
center before the center is pushed forward.*/
|
||||
virtual void setMinimumDistance(float minimumDistance) { _minimumDistance=minimumDistance; }
|
||||
|
||||
/** get the minimum distance (as ratio) the eye point can be zoomed in */
|
||||
float getMinimumDistance() const { return _minimumDistance; }
|
||||
|
||||
|
||||
/** set the coordinate frame which callback tells the manipulator which way is up, east and north.*/
|
||||
virtual void setCoordinateFrameCallback(CoordinateFrameCallback* cb) { _coordinateFrameCallback = cb; }
|
||||
@@ -70,14 +63,14 @@ public:
|
||||
|
||||
/** get the coordinate frame callback which tells the manipulator which way is up, east and north.*/
|
||||
const CoordinateFrameCallback* getCoordinateFrameCallback() const { return _coordinateFrameCallback.get(); }
|
||||
|
||||
|
||||
/** get the coordinate frame.*/
|
||||
osg::CoordinateFrame getCoordinateFrame(const osg::Vec3d& position) const
|
||||
{
|
||||
if (_coordinateFrameCallback.valid()) return _coordinateFrameCallback->getCoordinateFrame(position);
|
||||
return osg::CoordinateFrame();
|
||||
}
|
||||
|
||||
|
||||
osg::Vec3d getSideVector(const osg::CoordinateFrame& cf) const { return osg::Vec3d(cf(0,0),cf(0,1),cf(0,2)); }
|
||||
osg::Vec3d getFrontVector(const osg::CoordinateFrame& cf) const { return osg::Vec3d(cf(1,0),cf(1,1),cf(1,2)); }
|
||||
osg::Vec3d getUpVector(const osg::CoordinateFrame& cf) const { return osg::Vec3d(cf(2,0),cf(2,1),cf(2,2)); }
|
||||
@@ -100,12 +93,6 @@ public:
|
||||
/** Get the FusionDistanceValue. Used by SceneView for setting up stereo convergence.*/
|
||||
virtual float getFusionDistanceValue() const { return 1.0f; }
|
||||
|
||||
/** Set the distance parameter (used by TrackballManipulator etc.) */
|
||||
void setDistance(double /*distance*/) {}
|
||||
|
||||
/** Get the distance parameter. */
|
||||
virtual double getDistance() const { return 1.0; }
|
||||
|
||||
/** Set the mask to use when set up intersection traversal such as used in manipulators that follow terrain or have collision detection.
|
||||
* The intersection traversal mask is useful for controlling what parts of the scene graph should be used for intersection purposes.*/
|
||||
void setIntersectTraversalMask(unsigned int mask) { _intersectTraversalMask = mask; }
|
||||
@@ -134,7 +121,7 @@ public:
|
||||
_homeCenter = center;
|
||||
_homeUp = up;
|
||||
}
|
||||
|
||||
|
||||
/** Get the manually set home position. */
|
||||
virtual void getHomePosition(osg::Vec3d& eye, osg::Vec3d& center, osg::Vec3d& up) const
|
||||
{
|
||||
@@ -143,36 +130,23 @@ public:
|
||||
up = _homeUp;
|
||||
}
|
||||
|
||||
/** Set whether the automatic compute of the home position is enabled.*/
|
||||
/** Set whether the automatic compute of the home position is enabled.*/
|
||||
virtual void setAutoComputeHomePosition(bool flag) { _autoComputeHomePosition = flag; }
|
||||
|
||||
/** Get whether the automatic compute of the home position is enabled.*/
|
||||
|
||||
/** Get whether the automatic compute of the home position is enabled.*/
|
||||
bool getAutoComputeHomePosition() const { return _autoComputeHomePosition; }
|
||||
|
||||
/** Compute the home position.*/
|
||||
virtual void computeHomePosition()
|
||||
{
|
||||
if(getNode())
|
||||
{
|
||||
const osg::BoundingSphere& boundingSphere=getNode()->getBound();
|
||||
|
||||
setHomePosition(boundingSphere._center+osg::Vec3( 0.0,-3.5f * boundingSphere._radius,0.0f),
|
||||
boundingSphere._center,
|
||||
//osg::Vec3(0.0f,0.0f,1.0f),
|
||||
_homeUp,
|
||||
_autoComputeHomePosition);
|
||||
}
|
||||
}
|
||||
|
||||
/** Compute the home position.*/
|
||||
virtual void computeHomePosition(const osg::Camera *camera = NULL, bool useBoundingBox = false);
|
||||
|
||||
/**
|
||||
Move the camera to the default position.
|
||||
Move the camera to the default position.
|
||||
May be ignored by manipulators if home functionality is not appropriate.
|
||||
*/
|
||||
virtual void home(const GUIEventAdapter& ,GUIActionAdapter&) {}
|
||||
|
||||
/**
|
||||
Move the camera to the default position.
|
||||
Move the camera to the default position.
|
||||
This version does not require GUIEventAdapter and GUIActionAdapter so may be
|
||||
called from somewhere other than a handle() method in GUIEventHandler. Application
|
||||
must be aware of implications.
|
||||
@@ -191,14 +165,16 @@ public:
|
||||
protected:
|
||||
|
||||
MatrixManipulator();
|
||||
MatrixManipulator(const MatrixManipulator& mm, const osg::CopyOp& copyOp = osg::CopyOp::SHALLOW_COPY);
|
||||
|
||||
virtual ~MatrixManipulator();
|
||||
|
||||
double _minimumDistance;
|
||||
|
||||
std::string getManipulatorName() const;
|
||||
|
||||
unsigned int _intersectTraversalMask;
|
||||
|
||||
bool _autoComputeHomePosition;
|
||||
|
||||
|
||||
osg::Vec3d _homeEye;
|
||||
osg::Vec3d _homeCenter;
|
||||
osg::Vec3d _homeUp;
|
||||
|
||||
@@ -1,44 +1,51 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 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
|
||||
* 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
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef OSGGA_NODETRACKERMANIPULATOR
|
||||
#define OSGGA_NODETRACKERMANIPULATOR 1
|
||||
#ifndef OSGGA_NODE_TRACKER_MANIPULATOR
|
||||
#define OSGGA_NODE_TRACKER_MANIPULATOR 1
|
||||
|
||||
#include <osgGA/MatrixManipulator>
|
||||
#include <osg/ObserverNodePath>
|
||||
#include <osg/Quat>
|
||||
#include <osgGA/OrbitManipulator>
|
||||
|
||||
namespace osgGA{
|
||||
|
||||
class OSGGA_EXPORT NodeTrackerManipulator : public MatrixManipulator
|
||||
namespace osgGA {
|
||||
|
||||
|
||||
class OSGGA_EXPORT NodeTrackerManipulator : public OrbitManipulator
|
||||
{
|
||||
typedef OrbitManipulator inherited;
|
||||
|
||||
public:
|
||||
|
||||
NodeTrackerManipulator();
|
||||
NodeTrackerManipulator( int flags = DEFAULT_SETTINGS );
|
||||
|
||||
virtual const char* className() const { return "NodeTrackerManipulator"; }
|
||||
NodeTrackerManipulator( const NodeTrackerManipulator& om,
|
||||
const osg::CopyOp& copyOp = osg::CopyOp::SHALLOW_COPY );
|
||||
|
||||
void setTrackNodePath(const osg::NodePath& nodePath) { _trackNodePath.setNodePath(nodePath); }
|
||||
void setTrackNodePath(const osg::ObserverNodePath& nodePath) { _trackNodePath = nodePath; }
|
||||
osg::ObserverNodePath& getTrackNodePath() { return _trackNodePath; }
|
||||
META_Object( osgGA, NodeTrackerManipulator );
|
||||
|
||||
typedef std::vector< osg::observer_ptr<osg::Node> > ObserverNodePath;
|
||||
|
||||
void setTrackNodePath(const osg::NodePath& nodePath);
|
||||
void setTrackNodePath(const ObserverNodePath& nodePath) { _trackNodePath = nodePath; }
|
||||
ObserverNodePath& getTrackNodePath() { return _trackNodePath; }
|
||||
|
||||
void setTrackNode(osg::Node* node);
|
||||
osg::Node* getTrackNode();
|
||||
const osg::Node* getTrackNode() const;
|
||||
osg::Node* getTrackNode() { return _trackNodePath.empty() ? 0 : _trackNodePath.back().get(); }
|
||||
const osg::Node* getTrackNode() const { return _trackNodePath.empty() ? 0 : _trackNodePath.back().get(); }
|
||||
|
||||
enum TrackerMode
|
||||
enum TrackerMode
|
||||
{
|
||||
/** Track the center of the node's bounding sphere, but not rotations of the node.
|
||||
/** Track the center of the node's bounding sphere, but not rotations of the node.
|
||||
* For databases which have a CoordinateSystemNode, the orientation is kept relative the coordinate frame if the center of the node.
|
||||
*/
|
||||
NODE_CENTER,
|
||||
@@ -50,12 +57,12 @@ class OSGGA_EXPORT NodeTrackerManipulator : public MatrixManipulator
|
||||
*/
|
||||
NODE_CENTER_AND_ROTATION
|
||||
};
|
||||
|
||||
|
||||
void setTrackerMode(TrackerMode mode);
|
||||
TrackerMode getTrackerMode() const { return _trackerMode; }
|
||||
|
||||
|
||||
enum RotationMode
|
||||
enum RotationMode
|
||||
{
|
||||
/** Use a trackball style manipulation of the view direction w.r.t the tracked orientation.
|
||||
*/
|
||||
@@ -64,106 +71,43 @@ class OSGGA_EXPORT NodeTrackerManipulator : public MatrixManipulator
|
||||
*/
|
||||
ELEVATION_AZIM
|
||||
};
|
||||
|
||||
|
||||
void setRotationMode(RotationMode mode);
|
||||
RotationMode getRotationMode() const { return _rotationMode; }
|
||||
RotationMode getRotationMode() const;
|
||||
|
||||
|
||||
/** set the position of the matrix manipulator using a 4x4 Matrix.*/
|
||||
virtual void setByMatrix(const osg::Matrixd& matrix);
|
||||
|
||||
/** set the position of the matrix manipulator using a 4x4 Matrix.*/
|
||||
virtual void setByInverseMatrix(const osg::Matrixd& matrix) { setByMatrix(osg::Matrixd::inverse(matrix)); }
|
||||
|
||||
/** get the position of the manipulator as 4x4 Matrix.*/
|
||||
virtual osg::Matrixd getMatrix() const;
|
||||
|
||||
/** get the position of the manipulator as a inverse matrix of the manipulator, typically used as a model view matrix.*/
|
||||
virtual osg::Matrixd getInverseMatrix() const;
|
||||
|
||||
/** Get the FusionDistanceMode. Used by SceneView for setting up stereo convergence.*/
|
||||
virtual osgUtil::SceneView::FusionDistanceMode getFusionDistanceMode() const { return osgUtil::SceneView::USE_FUSION_DISTANCE_VALUE; }
|
||||
|
||||
/** Get the FusionDistanceValue. Used by SceneView for setting up stereo convergence.*/
|
||||
virtual float getFusionDistanceValue() const { return _distance; }
|
||||
|
||||
/** Attach a node to the manipulator.
|
||||
Automatically detaches previously attached node.
|
||||
setNode(NULL) detaches previously nodes.
|
||||
Is ignored by manipulators which do not require a reference model.*/
|
||||
virtual void setNode(osg::Node*);
|
||||
|
||||
/** Return node if attached.*/
|
||||
virtual const osg::Node* getNode() const;
|
||||
|
||||
/** Return node if attached.*/
|
||||
virtual osg::Node* getNode();
|
||||
|
||||
virtual void computeHomePosition();
|
||||
|
||||
/** Move the camera to the default position.
|
||||
May be ignored by manipulators if home functionality is not appropriate.*/
|
||||
virtual void home(const GUIEventAdapter& ea,GUIActionAdapter& us);
|
||||
|
||||
/** Start/restart the manipulator.*/
|
||||
virtual void init(const GUIEventAdapter& ea,GUIActionAdapter& us);
|
||||
|
||||
/** handle events, return true if handled, false otherwise.*/
|
||||
virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& us);
|
||||
|
||||
/** Get the keyboard and mouse usage of this manipulator.*/
|
||||
virtual void getUsage(osg::ApplicationUsage& usage) const;
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~NodeTrackerManipulator();
|
||||
virtual bool performMovementLeftMouseButton(const double dt, const double dx, const double dy);
|
||||
virtual bool performMovementMiddleMouseButton(const double dt, const double dx, const double dy);
|
||||
virtual bool performMovementRightMouseButton(const double dt, const double dx, const double dy);
|
||||
|
||||
/** Reset the internal GUIEvent stack.*/
|
||||
void flushMouseEventStack();
|
||||
osg::NodePath getNodePath() const;
|
||||
|
||||
/** Add the current mouse GUIEvent to internal stack.*/
|
||||
void addMouseEvent(const GUIEventAdapter& ea);
|
||||
bool validateNodePath() const;
|
||||
|
||||
void computeNodeWorldToLocal(osg::Matrixd& worldToLocal) const;
|
||||
void computeNodeLocalToWorld(osg::Matrixd& localToWorld) const;
|
||||
|
||||
void computeNodeCenterAndRotation(osg::Vec3d& center, osg::Quat& rotation) const;
|
||||
|
||||
void computePosition(const osg::Vec3d& eye,const osg::Vec3d& lv,const osg::Vec3d& up);
|
||||
|
||||
/** For the give mouse movement calculate the movement of the camera.
|
||||
Return true is camera has moved and a redraw is required.*/
|
||||
bool calcMovement();
|
||||
|
||||
void trackball(osg::Vec3& axis,double& angle, double p1x, double p1y, double p2x, double p2y);
|
||||
double tb_project_to_sphere(double r, double x, double y);
|
||||
|
||||
|
||||
/** Check the speed at which the mouse is moving.
|
||||
If speed is below a threshold then return false, otherwise return true.*/
|
||||
bool isMouseMoving();
|
||||
|
||||
|
||||
void clampOrientation();
|
||||
|
||||
|
||||
// Internal event stack comprising last two mouse events.
|
||||
osg::ref_ptr<const GUIEventAdapter> _ga_t1;
|
||||
osg::ref_ptr<const GUIEventAdapter> _ga_t0;
|
||||
|
||||
osg::observer_ptr<osg::Node> _node;
|
||||
|
||||
osg::ObserverNodePath _trackNodePath;
|
||||
ObserverNodePath _trackNodePath;
|
||||
|
||||
TrackerMode _trackerMode;
|
||||
RotationMode _rotationMode;
|
||||
|
||||
bool _thrown;
|
||||
|
||||
osg::Quat _nodeRotation;
|
||||
osg::Quat _rotation;
|
||||
float _distance;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* OSGGA_NODE_TRACKER_MANIPULATOR */
|
||||
|
||||
116
include/osgGA/OrbitManipulator
Normal file
116
include/osgGA/OrbitManipulator
Normal file
@@ -0,0 +1,116 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 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.
|
||||
*/
|
||||
|
||||
#ifndef OSGGA_ORBIT_MANIPULATOR
|
||||
#define OSGGA_ORBIT_MANIPULATOR 1
|
||||
|
||||
#include <osgGA/StandardManipulator>
|
||||
|
||||
|
||||
namespace osgGA {
|
||||
|
||||
|
||||
/** OrbitManipulator is base class for camera control based on focal center,
|
||||
distance from the center, and orientation of distance vector to the eye.
|
||||
This is the base class for trackball style manipulators.*/
|
||||
class OSGGA_EXPORT OrbitManipulator : public StandardManipulator
|
||||
{
|
||||
typedef StandardManipulator inherited;
|
||||
|
||||
public:
|
||||
|
||||
OrbitManipulator( int flags = DEFAULT_SETTINGS );
|
||||
OrbitManipulator( const OrbitManipulator& om,
|
||||
const osg::CopyOp& copyOp = osg::CopyOp::SHALLOW_COPY );
|
||||
|
||||
META_Object( osgGA, OrbitManipulator );
|
||||
|
||||
virtual void setByMatrix( const osg::Matrixd& matrix );
|
||||
virtual void setByInverseMatrix( const osg::Matrixd& matrix );
|
||||
virtual osg::Matrixd getMatrix() const;
|
||||
virtual osg::Matrixd getInverseMatrix() const;
|
||||
|
||||
virtual void setTransformation( const osg::Vec3d& eye, const osg::Quat& rotation );
|
||||
virtual void setTransformation( const osg::Vec3d& center, const osg::Vec3d& eye, const osg::Vec3d& up );
|
||||
virtual void getTransformation( osg::Vec3d& eye, osg::Quat& rotation ) const;
|
||||
virtual void getTransformation( osg::Vec3d& center, osg::Vec3d& eye, osg::Vec3d& up ) const;
|
||||
|
||||
virtual void setCenter( const osg::Vec3d& center );
|
||||
const osg::Vec3d& getCenter() const;
|
||||
virtual void setRotation( const osg::Quat& rotation );
|
||||
const osg::Quat& getRotation() const;
|
||||
virtual void setDistance( double distance );
|
||||
double getDistance() const;
|
||||
|
||||
virtual void setTrackballSize( const double& size );
|
||||
inline double getTrackballSize() const;
|
||||
virtual void setWheelZoomFactor( double wheelZoomFactor );
|
||||
inline double getWheelZoomFactor() const;
|
||||
|
||||
virtual void setMinimumDistance( const double& minimumDistance, bool relativeToModelSize = NULL );
|
||||
double getMinimumDistance( bool *relativeToModelSize = NULL ) const;
|
||||
|
||||
virtual osgUtil::SceneView::FusionDistanceMode getFusionDistanceMode() const;
|
||||
virtual float getFusionDistanceValue() const;
|
||||
|
||||
protected:
|
||||
|
||||
virtual bool handleMouseWheel( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
|
||||
|
||||
virtual bool performMovementLeftMouseButton( const double dt, const double dx, const double dy );
|
||||
virtual bool performMovementMiddleMouseButton( const double dt, const double dx, const double dy );
|
||||
virtual bool performMovementRightMouseButton( const double dt, const double dx, const double dy );
|
||||
virtual bool performMouseDeltaMovement( const float dx, const float dy );
|
||||
virtual void applyAnimationStep( const double currentProgress, const double prevProgress );
|
||||
|
||||
virtual void rotateTrackball( const float px0, const float py0, const float px1, const float py1 );
|
||||
virtual void rotateWithFixedVertical( const float dx, const float dy );
|
||||
virtual void rotateWithFixedVertical( const float dx, const float dy, const osg::Vec3f& up );
|
||||
virtual void panModel( const float dx, const float dy, const float dz = 0.f );
|
||||
virtual void zoomModel( const float dy, bool pushForwardIfNeeded = true );
|
||||
void trackball( osg::Vec3d& axis, float& angle, float p1x, float p1y, float p2x, float p2y );
|
||||
float tb_project_to_sphere( float r, float x, float y );
|
||||
virtual bool startAnimationByMousePointerIntersection( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
|
||||
|
||||
osg::Vec3d _center;
|
||||
osg::Quat _rotation;
|
||||
double _distance;
|
||||
|
||||
double _trackballSize;
|
||||
double _wheelZoomFactor;
|
||||
|
||||
double _minimumDistance;
|
||||
static int _minimumDistanceFlagIndex;
|
||||
|
||||
class OrbitAnimationData : public AnimationData {
|
||||
public:
|
||||
osg::Vec3d _movement;
|
||||
void start( const osg::Vec3d& movement, const double startTime );
|
||||
};
|
||||
virtual void allocAnimationData() { _animationData = new OrbitAnimationData(); }
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// inline functions
|
||||
//
|
||||
|
||||
/** Get the size of the trackball relative to the model size. */
|
||||
inline double OrbitManipulator::getTrackballSize() const { return _trackballSize; }
|
||||
/** Get the mouse wheel zoom factor.*/
|
||||
inline double OrbitManipulator::getWheelZoomFactor() const { return _wheelZoomFactor; }
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif /* OSGGA_ORBIT_MANIPULATOR */
|
||||
186
include/osgGA/StandardManipulator
Normal file
186
include/osgGA/StandardManipulator
Normal file
@@ -0,0 +1,186 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 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 reused 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/MatrixManipulator>
|
||||
|
||||
|
||||
namespace osgGA {
|
||||
|
||||
|
||||
/** StandardManipulator class provides basic functionality
|
||||
for user controlled manipulation.*/
|
||||
class OSGGA_EXPORT StandardManipulator : public MatrixManipulator
|
||||
{
|
||||
typedef MatrixManipulator inherited;
|
||||
|
||||
public:
|
||||
|
||||
// flags
|
||||
enum {
|
||||
UPDATE_MODEL_SIZE = 0x01,
|
||||
COMPUTE_HOME_USING_BBOX = 0x02,
|
||||
PROCESS_MOUSE_WHEEL = 0x04,
|
||||
SET_CENTER_ON_WHEEL_UP = 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& center, const osg::Vec3d& eye, const osg::Vec3d& up ) = 0;
|
||||
virtual void getTransformation( osg::Vec3d& eye, osg::Quat& rotation ) const = 0;
|
||||
virtual void getTransformation( osg::Vec3d& center, osg::Vec3d& eye, 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;
|
||||
|
||||
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 dt, const double dx, const double dy );
|
||||
virtual bool performMovementMiddleMouseButton( const double dt, const double dx, const double dy );
|
||||
virtual bool performMovementRightMouseButton( const double dt, 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;
|
||||
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;
|
||||
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;
|
||||
|
||||
/** The approximate amount of time it is currently taking to draw a frame.
|
||||
* This is used to compute the delta in translation/rotation during a thrown display update.
|
||||
* It allows us to match an delta in position/rotation independent of the rendering frame rate.
|
||||
*/
|
||||
double _delta_frame_time;
|
||||
|
||||
/** The time the last frame started.
|
||||
* Used when _rate_sensitive is true so that we can match display update rate to rotation/translation rate.
|
||||
*/
|
||||
double _last_frame_time;
|
||||
|
||||
// scene data
|
||||
osg::ref_ptr< osg::Node > _node;
|
||||
double _modelSize;
|
||||
bool _verticalAxisFixed;
|
||||
|
||||
// animation stuff
|
||||
class 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);
|
||||
}
|
||||
|
||||
/// Returns whether manipulator preserves camera's "UP" vector.
|
||||
inline bool StandardManipulator::getVerticalAxisFixed() const
|
||||
{
|
||||
return _verticalAxisFixed;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif /* OSGGA_CAMERA_MANIPULATOR */
|
||||
@@ -1,140 +1,64 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 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
|
||||
* 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
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef OSGGA_TERRAINMANIPULATOR
|
||||
#define OSGGA_TERRAINMANIPULATOR 1
|
||||
#ifndef OSGGA_TERRAIN_MANIPULATOR
|
||||
#define OSGGA_TERRAIN_MANIPULATOR 1
|
||||
|
||||
#include <osgGA/MatrixManipulator>
|
||||
#include <osg/Quat>
|
||||
#include <osgGA/OrbitManipulator>
|
||||
|
||||
namespace osgGA{
|
||||
|
||||
class OSGGA_EXPORT TerrainManipulator : public MatrixManipulator
|
||||
namespace osgGA {
|
||||
|
||||
|
||||
class OSGGA_EXPORT TerrainManipulator : public OrbitManipulator
|
||||
{
|
||||
public:
|
||||
typedef OrbitManipulator inherited;
|
||||
|
||||
TerrainManipulator();
|
||||
public:
|
||||
|
||||
virtual const char* className() const { return "Terrain"; }
|
||||
TerrainManipulator( int flags = DEFAULT_SETTINGS );
|
||||
TerrainManipulator( const TerrainManipulator& tm,
|
||||
const osg::CopyOp& copyOp = osg::CopyOp::SHALLOW_COPY );
|
||||
|
||||
META_Object( osgGA, TerrainManipulator );
|
||||
|
||||
enum RotationMode
|
||||
{
|
||||
ELEVATION_HEADING_ROLL,
|
||||
ELEVATION_HEADING
|
||||
};
|
||||
enum RotationMode
|
||||
{
|
||||
ELEVATION_AZIM_ROLL,
|
||||
ELEVATION_AZIM
|
||||
};
|
||||
|
||||
void setRotationMode(RotationMode mode);
|
||||
RotationMode getRotationMode() const { return _rotationMode; }
|
||||
virtual void setRotationMode(RotationMode mode);
|
||||
RotationMode getRotationMode() const;
|
||||
|
||||
virtual void setByMatrix( const osg::Matrixd& matrix );
|
||||
|
||||
/** set the position of the matrix manipulator using a 4x4 Matrix.*/
|
||||
virtual void setByMatrix(const osg::Matrixd& matrix);
|
||||
virtual void setTransformation( const osg::Vec3d& eye, const osg::Vec3d& center, const osg::Vec3d& up );
|
||||
|
||||
/** set the position of the matrix manipulator using a 4x4 Matrix.*/
|
||||
virtual void setByInverseMatrix(const osg::Matrixd& matrix) { setByMatrix(osg::Matrixd::inverse(matrix)); }
|
||||
virtual void setNode( osg::Node* node );
|
||||
|
||||
/** get the position of the manipulator as 4x4 Matrix.*/
|
||||
virtual osg::Matrixd getMatrix() const;
|
||||
protected:
|
||||
|
||||
/** get the position of the manipulator as a inverse matrix of the manipulator, typically used as a model view matrix.*/
|
||||
virtual osg::Matrixd getInverseMatrix() const;
|
||||
virtual bool performMovementMiddleMouseButton( const double dt, const double dx, const double dy );
|
||||
virtual bool performMovementRightMouseButton( const double dt, const double dx, const double dy );
|
||||
|
||||
/** Get the FusionDistanceMode. Used by SceneView for setting up stereo convergence.*/
|
||||
virtual osgUtil::SceneView::FusionDistanceMode getFusionDistanceMode() const { return osgUtil::SceneView::USE_FUSION_DISTANCE_VALUE; }
|
||||
|
||||
/** Get the FusionDistanceValue. Used by SceneView for setting up stereo convergence.*/
|
||||
virtual float getFusionDistanceValue() const { return _distance; }
|
||||
|
||||
/** Set the distance of the trackball. */
|
||||
void setDistance(double distance) { _distance = distance; }
|
||||
|
||||
/** Get the distance of the trackball. */
|
||||
double getDistance() const { return _distance; }
|
||||
|
||||
|
||||
/** Attach a node to the manipulator.
|
||||
Automatically detaches previously attached node.
|
||||
setNode(NULL) detaches previously nodes.
|
||||
Is ignored by manipulators which do not require a reference model.*/
|
||||
virtual void setNode(osg::Node*);
|
||||
|
||||
/** Return node if attached.*/
|
||||
virtual const osg::Node* getNode() const;
|
||||
|
||||
/** Return node if attached.*/
|
||||
virtual osg::Node* getNode();
|
||||
|
||||
/** Move the camera to the default position.
|
||||
May be ignored by manipulators if home functionality is not appropriate.*/
|
||||
virtual void home(const GUIEventAdapter& ea,GUIActionAdapter& us);
|
||||
|
||||
/** Start/restart the manipulator.*/
|
||||
virtual void init(const GUIEventAdapter& ea,GUIActionAdapter& us);
|
||||
|
||||
/** handle events, return true if handled, false otherwise.*/
|
||||
virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& us);
|
||||
|
||||
/** Get the keyboard and mouse usage of this manipulator.*/
|
||||
virtual void getUsage(osg::ApplicationUsage& usage) const;
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~TerrainManipulator();
|
||||
|
||||
bool intersect(const osg::Vec3d& start, const osg::Vec3d& end, osg::Vec3d& intersection) const;
|
||||
|
||||
/** Reset the internal GUIEvent stack.*/
|
||||
void flushMouseEventStack();
|
||||
/** Add the current mouse GUIEvent to internal stack.*/
|
||||
void addMouseEvent(const GUIEventAdapter& ea);
|
||||
|
||||
void computePosition(const osg::Vec3d& eye,const osg::Vec3d& lv,const osg::Vec3d& up);
|
||||
|
||||
/** For the give mouse movement calculate the movement of the camera.
|
||||
Return true is camera has moved and a redraw is required.*/
|
||||
bool calcMovement();
|
||||
|
||||
void trackball(osg::Vec3& axis,double& angle, double p1x, double p1y, double p2x, double p2y);
|
||||
double tb_project_to_sphere(double r, double x, double y);
|
||||
|
||||
|
||||
/** Check the speed at which the mouse is moving.
|
||||
If speed is below a threshold then return false, otherwise return true.*/
|
||||
bool isMouseMoving();
|
||||
|
||||
|
||||
void clampOrientation();
|
||||
|
||||
|
||||
// Internal event stack comprising last two mouse events.
|
||||
osg::ref_ptr<const GUIEventAdapter> _ga_t1;
|
||||
osg::ref_ptr<const GUIEventAdapter> _ga_t0;
|
||||
|
||||
osg::observer_ptr<osg::Node> _node;
|
||||
|
||||
RotationMode _rotationMode;
|
||||
|
||||
bool _thrown;
|
||||
|
||||
osg::Vec3d _center;
|
||||
osg::Quat _rotation;
|
||||
double _distance;
|
||||
osg::Vec3d _previousUp;
|
||||
bool intersect( const osg::Vec3d& start, const osg::Vec3d& end, osg::Vec3d& intersection ) const;
|
||||
void clampOrientation();
|
||||
|
||||
osg::Vec3d _previousUp;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* OSGGA_TERRAIN_MANIPULATOR */
|
||||
|
||||
@@ -1,174 +1,40 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 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
|
||||
* 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
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef OSGGA_TRACKBALLMANIPULATOR
|
||||
#define OSGGA_TRACKBALLMANIPULATOR 1
|
||||
#ifndef OSGGA_TRACKBALL_MANIPULATOR
|
||||
#define OSGGA_TRACKBALL_MANIPULATOR 1
|
||||
|
||||
#include <osgGA/MatrixManipulator>
|
||||
#include <osg/Quat>
|
||||
#include <osgGA/OrbitManipulator>
|
||||
|
||||
namespace osgGA{
|
||||
|
||||
class OSGGA_EXPORT TrackballManipulator : public MatrixManipulator
|
||||
namespace osgGA {
|
||||
|
||||
|
||||
class OSGGA_EXPORT TrackballManipulator : public OrbitManipulator
|
||||
{
|
||||
public:
|
||||
TrackballManipulator();
|
||||
typedef OrbitManipulator inherited;
|
||||
|
||||
virtual const char* className() const { return "Trackball"; }
|
||||
public:
|
||||
|
||||
/** set the position of the matrix manipulator using a 4x4 Matrix.*/
|
||||
virtual void setByMatrix(const osg::Matrixd& matrix);
|
||||
TrackballManipulator( int flags = DEFAULT_SETTINGS );
|
||||
TrackballManipulator( const TrackballManipulator& tm,
|
||||
const osg::CopyOp& copyOp = osg::CopyOp::SHALLOW_COPY );
|
||||
|
||||
/** set the position of the matrix manipulator using a 4x4 Matrix.*/
|
||||
virtual void setByInverseMatrix(const osg::Matrixd& matrix) { setByMatrix(osg::Matrixd::inverse(matrix)); }
|
||||
|
||||
/** get the position of the manipulator as 4x4 Matrix.*/
|
||||
virtual osg::Matrixd getMatrix() const;
|
||||
|
||||
/** get the position of the manipulator as a inverse matrix of the manipulator, typically used as a model view matrix.*/
|
||||
virtual osg::Matrixd getInverseMatrix() const;
|
||||
|
||||
/** Get the FusionDistanceMode. Used by SceneView for setting up stereo convergence.*/
|
||||
virtual osgUtil::SceneView::FusionDistanceMode getFusionDistanceMode() const { return osgUtil::SceneView::USE_FUSION_DISTANCE_VALUE; }
|
||||
|
||||
/** Get the FusionDistanceValue. Used by SceneView for setting up stereo convergence.*/
|
||||
virtual float getFusionDistanceValue() const { return _distance; }
|
||||
|
||||
/** Attach a node to the manipulator.
|
||||
Automatically detaches previously attached node.
|
||||
setNode(NULL) detaches previously nodes.
|
||||
Is ignored by manipulators which do not require a reference model.*/
|
||||
virtual void setNode(osg::Node*);
|
||||
|
||||
/** Return node if attached.*/
|
||||
virtual const osg::Node* getNode() const;
|
||||
|
||||
/** Return node if attached.*/
|
||||
virtual osg::Node* getNode();
|
||||
|
||||
/** Move the camera to the default position.
|
||||
May be ignored by manipulators if home functionality is not appropriate.*/
|
||||
virtual void home(const GUIEventAdapter& ea,GUIActionAdapter& us);
|
||||
virtual void home(double);
|
||||
|
||||
/** Start/restart the manipulator.*/
|
||||
virtual void init(const GUIEventAdapter& ea,GUIActionAdapter& us);
|
||||
|
||||
/** handle events, return true if handled, false otherwise.*/
|
||||
virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& us);
|
||||
|
||||
/** Get the keyboard and mouse usage of this manipulator.*/
|
||||
virtual void getUsage(osg::ApplicationUsage& usage) const;
|
||||
|
||||
|
||||
/** set the minimum distance (as ratio) the eye point can be zoomed in towards the
|
||||
center before the center is pushed forward.*/
|
||||
void setMinimumZoomScale(double minimumZoomScale) { _minimumZoomScale=minimumZoomScale; }
|
||||
|
||||
/** get the minimum distance (as ratio) the eye point can be zoomed in */
|
||||
double getMinimumZoomScale() const { return _minimumZoomScale; }
|
||||
|
||||
/** set the mouse scroll wheel zoom delta.
|
||||
* Range -1.0 to +1.0, -ve value inverts wheel direction and zero switches off scroll wheel. */
|
||||
void setScroolWheelZoomDelta(double zoomDelta) { _zoomDelta = zoomDelta; }
|
||||
|
||||
/** get the mouse scroll wheel zoom delta. */
|
||||
double getScroolWheelZoomDelta() const { return _zoomDelta; }
|
||||
|
||||
/** Set the center of the trackball. */
|
||||
void setCenter(const osg::Vec3d& center) { _center = center; }
|
||||
|
||||
/** Get the center of the trackball. */
|
||||
const osg::Vec3d& getCenter() const { return _center; }
|
||||
|
||||
/** Set the rotation of the trackball. */
|
||||
void setRotation(const osg::Quat& rotation) { _rotation = rotation; }
|
||||
|
||||
/** Get the rotation of the trackball. */
|
||||
const osg::Quat& getRotation() const { return _rotation; }
|
||||
|
||||
/** Set the distance of the trackball. */
|
||||
void setDistance(double distance) { _distance = distance; }
|
||||
|
||||
/** Get the distance of the trackball. */
|
||||
double getDistance() const { return _distance; }
|
||||
|
||||
/** Set the size of the trackball. */
|
||||
void setTrackballSize(float size);
|
||||
|
||||
/** Get the size of the trackball. */
|
||||
float getTrackballSize() const { return _trackballSize; }
|
||||
|
||||
/** Set the 'allow throw' flag. Releasing the mouse button while moving the camera results in a throw. */
|
||||
void setAllowThrow(bool allowThrow) { _allowThrow = allowThrow; }
|
||||
|
||||
/** Returns true if the camera can be thrown, false otherwise. This defaults to true. */
|
||||
bool getAllowThrow() const { return _allowThrow; }
|
||||
protected:
|
||||
|
||||
virtual ~TrackballManipulator();
|
||||
|
||||
/** Reset the internal GUIEvent stack.*/
|
||||
void flushMouseEventStack();
|
||||
/** Add the current mouse GUIEvent to internal stack.*/
|
||||
void addMouseEvent(const GUIEventAdapter& ea);
|
||||
|
||||
void computePosition(const osg::Vec3& eye,const osg::Vec3& lv,const osg::Vec3& up);
|
||||
|
||||
/** For the give mouse movement calculate the movement of the camera.
|
||||
Return true is camera has moved and a redraw is required.*/
|
||||
bool calcMovement();
|
||||
|
||||
void trackball(osg::Vec3& axis,float& angle, float p1x, float p1y, float p2x, float p2y);
|
||||
float tb_project_to_sphere(float r, float x, float y);
|
||||
|
||||
|
||||
/** Check the speed at which the mouse is moving.
|
||||
If speed is below a threshold then return false, otherwise return true.*/
|
||||
bool isMouseMoving();
|
||||
|
||||
// Internal event stack comprising last two mouse events.
|
||||
osg::ref_ptr<const GUIEventAdapter> _ga_t1;
|
||||
osg::ref_ptr<const GUIEventAdapter> _ga_t0;
|
||||
|
||||
osg::observer_ptr<osg::Node> _node;
|
||||
|
||||
double _modelScale;
|
||||
double _minimumZoomScale;
|
||||
|
||||
bool _allowThrow;
|
||||
bool _thrown;
|
||||
|
||||
/** The approximate amount of time it is currently taking to draw a frame.
|
||||
* This is used to compute the delta in translation/rotation during a thrown display update.
|
||||
* It allows us to match an delta in position/rotation independent of the rendering frame rate.
|
||||
*/
|
||||
double _delta_frame_time;
|
||||
|
||||
/** The time the last frame started.
|
||||
* Used when _rate_sensitive is true so that we can match display update rate to rotation/translation rate.
|
||||
*/
|
||||
double _last_frame_time;
|
||||
|
||||
osg::Vec3d _center;
|
||||
osg::Quat _rotation;
|
||||
double _distance;
|
||||
float _trackballSize;
|
||||
float _zoomDelta;
|
||||
META_Object( osgGA, TrackballManipulator );
|
||||
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* OSGGA_TRACKBALL_MANIPULATOR */
|
||||
|
||||
@@ -109,7 +109,7 @@ class OSGGA_EXPORT UFOManipulator : public osgGA::MatrixManipulator
|
||||
void getUsage(osg::ApplicationUsage& usage) const;
|
||||
|
||||
/** Report the current position as LookAt vectors */
|
||||
void getCurrentPositionAsLookAt( osg::Vec3 &eye, osg::Vec3 ¢er, osg::Vec3 &up );
|
||||
void getCurrentPositionAsLookAt( osg::Vec3d& eye, osg::Vec3d& center, osg::Vec3d& up );
|
||||
|
||||
|
||||
void setMinHeight( double in_min_height ) { _minHeightAboveGround = in_min_height; }
|
||||
|
||||
Reference in New Issue
Block a user