2012-03-22 01:36:20 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
2005-03-11 14:09:16 +08:00
|
|
|
*
|
2012-03-22 01:36:20 +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
|
2005-03-11 14:09:16 +08:00
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
2012-03-22 01:36:20 +08:00
|
|
|
*
|
2005-03-11 14:09:16 +08:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2012-03-22 01:36:20 +08:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2005-03-11 14:09:16 +08:00
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef OSGGA_UFO_MANIPULATOR_DEF
|
|
|
|
#define OSGGA_UFO_MANIPULATOR_DEF 1
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
2010-05-27 23:54:37 +08:00
|
|
|
#include <osgGA/CameraManipulator>
|
2005-03-11 14:09:16 +08:00
|
|
|
#include <osg/Node>
|
|
|
|
#include <osg/Matrix>
|
|
|
|
|
2008-10-07 22:19:28 +08:00
|
|
|
/**
|
|
|
|
\class osgGA::UFOManipulator
|
|
|
|
\brief A UFO manipulator driven with keybindings.
|
|
|
|
|
2012-03-22 01:36:20 +08:00
|
|
|
The UFOManipulator is better suited for applications that employ
|
2008-10-07 22:19:28 +08:00
|
|
|
architectural walk-throughs, or situations where the eyepoint motion
|
2012-03-22 01:36:20 +08:00
|
|
|
model must move slowly, deliberately and well controlled.
|
2008-10-07 22:19:28 +08:00
|
|
|
|
|
|
|
The UFO Manipulator allows the following movements with the listed
|
|
|
|
Key combinations:
|
|
|
|
\param UpArrow Acceleration forward.
|
|
|
|
\param DownArrow Acceleration backward (or deceleration forward).
|
|
|
|
\param LeftArrow Rotate view and direction of travel to the left.
|
|
|
|
\param RightArrow Rotate view and direction of travel to the right.
|
|
|
|
\param SpaceBar Brake. Gradually decelerates linear and rotational movement.
|
|
|
|
\param Shift/UpArrow Accelerate up.
|
|
|
|
\param Shift/DownArrow Accelerate down.
|
|
|
|
\param Shift/LeftArrow Accelerate (linearly) left.
|
|
|
|
\param Shift/RightArrow Accelerate (linearly) right.
|
|
|
|
\param Shift/SpaceBar Instant brake. Immediately stop all linear and rotational movement.
|
|
|
|
|
|
|
|
When the Shift key is released, up, down, linear left and/or linear right movement is decelerated.
|
|
|
|
|
|
|
|
\param Ctrl/UpArrow Rotate view (but not direction of travel) up.
|
|
|
|
\param Ctrl/DownArrow Rotate view (but not direction of travel) down.
|
|
|
|
\param Ctrl/LeftArrow Rotate view (but not direction of travel) left.
|
|
|
|
\param Ctrl/RightArrow Rotate view (but not direction of travel) right.
|
|
|
|
\param Ctrl/Return Straightens out the view offset.
|
|
|
|
|
|
|
|
*/
|
2005-03-11 14:09:16 +08:00
|
|
|
|
|
|
|
namespace osgGA {
|
|
|
|
|
2010-05-27 23:54:37 +08:00
|
|
|
class OSGGA_EXPORT UFOManipulator : public osgGA::CameraManipulator
|
2005-03-11 14:09:16 +08:00
|
|
|
{
|
|
|
|
|
2005-04-22 22:40:06 +08:00
|
|
|
public:
|
2005-03-11 14:09:16 +08:00
|
|
|
/** Default constructor */
|
2005-04-22 22:40:06 +08:00
|
|
|
UFOManipulator();
|
2005-03-11 14:09:16 +08:00
|
|
|
|
|
|
|
/** return className
|
2005-03-12 01:46:12 +08:00
|
|
|
\return returns constant "UFO"
|
2005-03-11 14:09:16 +08:00
|
|
|
*/
|
|
|
|
virtual const char* className() const;
|
|
|
|
|
2012-03-22 01:36:20 +08:00
|
|
|
/** Set the current position with a matrix
|
2005-03-11 14:09:16 +08:00
|
|
|
\param matrix A viewpoint matrix.
|
|
|
|
*/
|
2005-04-22 22:40:06 +08:00
|
|
|
virtual void setByMatrix( const osg::Matrixd &matrix ) ;
|
2005-03-11 14:09:16 +08:00
|
|
|
|
2007-12-11 01:30:18 +08:00
|
|
|
/** Set the current position with the inverse matrix
|
2005-05-21 05:01:57 +08:00
|
|
|
\param invmat The inverse of a viewpoint matrix
|
2005-03-11 14:09:16 +08:00
|
|
|
*/
|
2005-04-22 22:40:06 +08:00
|
|
|
virtual void setByInverseMatrix( const osg::Matrixd &invmat);
|
2005-03-11 14:09:16 +08:00
|
|
|
|
|
|
|
/** Get the current viewmatrix */
|
2005-04-22 22:40:06 +08:00
|
|
|
virtual osg::Matrixd getMatrix() const;
|
2005-03-11 14:09:16 +08:00
|
|
|
|
|
|
|
/** Get the current inverse view matrix */
|
2005-04-22 22:40:06 +08:00
|
|
|
virtual osg::Matrixd getInverseMatrix() const ;
|
2005-03-11 14:09:16 +08:00
|
|
|
|
|
|
|
/** Set the subgraph this manipulator is driving the eye through.
|
|
|
|
\param node root of subgraph
|
|
|
|
*/
|
2005-05-21 05:01:57 +08:00
|
|
|
virtual void setNode(osg::Node* node);
|
2005-03-11 14:09:16 +08:00
|
|
|
|
|
|
|
/** Get the root node of the subgraph this manipulator is driving the eye through (const)*/
|
|
|
|
virtual const osg::Node* getNode() const;
|
|
|
|
|
|
|
|
/** Get the root node of the subgraph this manipulator is driving the eye through */
|
|
|
|
virtual osg::Node* getNode();
|
|
|
|
|
2012-03-22 01:36:20 +08:00
|
|
|
/** Computes the home position based on the extents and scale of the
|
2005-03-11 14:09:16 +08:00
|
|
|
scene graph rooted at node */
|
|
|
|
virtual void computeHomePosition();
|
|
|
|
|
|
|
|
/** Sets the viewpoint matrix to the home position */
|
|
|
|
virtual void home(const osgGA::GUIEventAdapter&, osgGA::GUIActionAdapter&) ;
|
2005-03-21 07:57:17 +08:00
|
|
|
void home(double);
|
|
|
|
|
|
|
|
virtual void init(const GUIEventAdapter& ,GUIActionAdapter&);
|
2005-03-11 14:09:16 +08:00
|
|
|
|
|
|
|
/** Handles incoming osgGA events */
|
2005-04-22 22:40:06 +08:00
|
|
|
bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter &aa);
|
2005-03-11 14:09:16 +08:00
|
|
|
|
|
|
|
/** Reports Usage parameters to the application */
|
|
|
|
void getUsage(osg::ApplicationUsage& usage) const;
|
|
|
|
|
2005-03-12 13:31:26 +08:00
|
|
|
/** Report the current position as LookAt vectors */
|
2010-05-25 20:05:13 +08:00
|
|
|
void getCurrentPositionAsLookAt( osg::Vec3d& eye, osg::Vec3d& center, osg::Vec3d& up );
|
2005-03-12 13:31:26 +08:00
|
|
|
|
2005-03-11 14:09:16 +08:00
|
|
|
|
2005-11-17 19:03:20 +08:00
|
|
|
void setMinHeight( double in_min_height ) { _minHeightAboveGround = in_min_height; }
|
|
|
|
double getMinHeight() const { return _minHeightAboveGround; }
|
|
|
|
|
|
|
|
void setMinDistance( double in_min_dist ) { _minDistanceInFront = in_min_dist; }
|
|
|
|
double getMinDistance() const { return _minDistanceInFront; }
|
|
|
|
|
|
|
|
void setForwardSpeed( double in_fs ) { _forwardSpeed = in_fs; }
|
|
|
|
double getForwardSpeed() const { return _forwardSpeed; }
|
|
|
|
|
|
|
|
void setSideSpeed( double in_ss ) { _sideSpeed = in_ss; }
|
|
|
|
double getSideSpeed() const { return _sideSpeed; }
|
|
|
|
|
|
|
|
void setRotationSpeed( double in_rot_speed ) { _directionRotationRate = in_rot_speed; }
|
|
|
|
double getRotationSpeed() const { return _directionRotationRate; }
|
|
|
|
|
|
|
|
|
|
|
|
protected:
|
2008-10-07 22:19:28 +08:00
|
|
|
|
|
|
|
virtual ~UFOManipulator();
|
|
|
|
|
|
|
|
bool intersect(const osg::Vec3d& start, const osg::Vec3d& end, osg::Vec3d& intersection) const;
|
|
|
|
|
2010-02-16 04:15:32 +08:00
|
|
|
osg::observer_ptr<osg::Node> _node;
|
2005-04-22 22:40:06 +08:00
|
|
|
float _viewAngle;
|
|
|
|
osg::Matrixd _matrix;
|
|
|
|
osg::Matrixd _inverseMatrix;
|
2005-03-13 13:02:02 +08:00
|
|
|
osg::Matrixd _offset;
|
2005-03-11 14:09:16 +08:00
|
|
|
|
|
|
|
double _minHeightAboveGround;
|
|
|
|
double _minDistanceInFront;
|
|
|
|
|
|
|
|
double _speedEpsilon;
|
|
|
|
double _forwardSpeed;
|
|
|
|
double _sideSpeed;
|
|
|
|
double _upSpeed;
|
|
|
|
double _speedAccelerationFactor;
|
|
|
|
double _speedDecelerationFactor;
|
|
|
|
|
|
|
|
bool _decelerateUpSideRate;
|
|
|
|
|
|
|
|
double _directionRotationEpsilon;
|
|
|
|
double _directionRotationRate;
|
|
|
|
double _directionRotationAcceleration;
|
|
|
|
double _directionRotationDeceleration;
|
|
|
|
|
|
|
|
double _viewOffsetDelta;
|
|
|
|
double _pitchOffsetRate;
|
|
|
|
double _pitchOffset;
|
|
|
|
double _yawOffsetRate;
|
|
|
|
double _yawOffset;
|
|
|
|
|
|
|
|
double _t0;
|
|
|
|
double _dt;
|
2007-12-21 22:21:21 +08:00
|
|
|
osg::Vec3d _direction;
|
|
|
|
osg::Vec3d _position;
|
2005-03-11 14:09:16 +08:00
|
|
|
|
|
|
|
|
|
|
|
bool _shift;
|
|
|
|
bool _ctrl;
|
|
|
|
bool _decelerateOffsetRate;
|
|
|
|
|
|
|
|
bool _straightenOffset;
|
|
|
|
|
|
|
|
void _stop();
|
|
|
|
void _keyDown( const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &);
|
|
|
|
void _keyUp( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter &);
|
|
|
|
void _frame(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter &);
|
|
|
|
|
|
|
|
void _adjustPosition();
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|