1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version. The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * OpenSceneGraph Public License for more details.
14#ifndef OSGGA_UFO_MANIPULATOR_DEF
15#define OSGGA_UFO_MANIPULATOR_DEF 1
19#include <osgGA/CameraManipulator>
24 \class osgGA::UFOManipulator
25 \brief A UFO manipulator driven with keybindings.
27 The UFOManipulator is better suited for applications that employ
28 architectural walk-throughs, or situations where the eyepoint motion
29 model must move slowly, deliberately and well controlled.
31 The UFO Manipulator allows the following movements with the listed
33 \param UpArrow Acceleration forward.
34 \param DownArrow Acceleration backward (or deceleration forward).
35 \param LeftArrow Rotate view and direction of travel to the left.
36 \param RightArrow Rotate view and direction of travel to the right.
37 \param SpaceBar Brake. Gradually decelerates linear and rotational movement.
38 \param Shift/UpArrow Accelerate up.
39 \param Shift/DownArrow Accelerate down.
40 \param Shift/LeftArrow Accelerate (linearly) left.
41 \param Shift/RightArrow Accelerate (linearly) right.
42 \param Shift/SpaceBar Instant brake. Immediately stop all linear and rotational movement.
44When the Shift key is released, up, down, linear left and/or linear right movement is decelerated.
46 \param Ctrl/UpArrow Rotate view (but not direction of travel) up.
47 \param Ctrl/DownArrow Rotate view (but not direction of travel) down.
48 \param Ctrl/LeftArrow Rotate view (but not direction of travel) left.
49 \param Ctrl/RightArrow Rotate view (but not direction of travel) right.
50 \param Ctrl/Return Straightens out the view offset.
56class OSGGA_EXPORT UFOManipulator : public osgGA::CameraManipulator
60 /** Default constructor */
64 \return returns constant "UFO"
66 virtual const char* className() const;
68 /** Set the current position with a matrix
69 \param matrix A viewpoint matrix.
71 virtual void setByMatrix( const osg::Matrixd &matrix ) ;
73 /** Set the current position with the inverse matrix
74 \param invmat The inverse of a viewpoint matrix
76 virtual void setByInverseMatrix( const osg::Matrixd &invmat);
78 /** Get the current viewmatrix */
79 virtual osg::Matrixd getMatrix() const;
81 /** Get the current inverse view matrix */
82 virtual osg::Matrixd getInverseMatrix() const ;
84 /** Set the subgraph this manipulator is driving the eye through.
85 \param node root of subgraph
87 virtual void setNode(osg::Node* node);
89 /** Get the root node of the subgraph this manipulator is driving the eye through (const)*/
90 virtual const osg::Node* getNode() const;
92 /** Get the root node of the subgraph this manipulator is driving the eye through */
93 virtual osg::Node* getNode();
95 /** Computes the home position based on the extents and scale of the
96 scene graph rooted at node */
97 virtual void computeHomePosition();
99 /** Sets the viewpoint matrix to the home position */
100 virtual void home(const osgGA::GUIEventAdapter&, osgGA::GUIActionAdapter&) ;
103 virtual void init(const GUIEventAdapter& ,GUIActionAdapter&);
105 /** Handles incoming osgGA events */
106 bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter &aa);
108 /** Reports Usage parameters to the application */
109 void getUsage(osg::ApplicationUsage& usage) const;
111 /** Report the current position as LookAt vectors */
112 void getCurrentPositionAsLookAt( osg::Vec3d& eye, osg::Vec3d& center, osg::Vec3d& up );
115 void setMinHeight( double in_min_height ) { _minHeightAboveGround = in_min_height; }
116 double getMinHeight() const { return _minHeightAboveGround; }
118 void setMinDistance( double in_min_dist ) { _minDistanceInFront = in_min_dist; }
119 double getMinDistance() const { return _minDistanceInFront; }
121 void setForwardSpeed( double in_fs ) { _forwardSpeed = in_fs; }
122 double getForwardSpeed() const { return _forwardSpeed; }
124 void setSideSpeed( double in_ss ) { _sideSpeed = in_ss; }
125 double getSideSpeed() const { return _sideSpeed; }
127 void setRotationSpeed( double in_rot_speed ) { _directionRotationRate = in_rot_speed; }
128 double getRotationSpeed() const { return _directionRotationRate; }
133 virtual ~UFOManipulator();
135 bool intersect(const osg::Vec3d& start, const osg::Vec3d& end, osg::Vec3d& intersection) const;
137 osg::observer_ptr<osg::Node> _node;
138 osg::Matrixd _matrix;
139 osg::Matrixd _inverseMatrix;
140 osg::Matrixd _offset;
142 double _minHeightAboveGround;
143 double _minDistanceInFront;
145 double _speedEpsilon;
146 double _forwardSpeed;
149 double _speedAccelerationFactor;
150 double _speedDecelerationFactor;
152 bool _decelerateUpSideRate;
154 double _directionRotationEpsilon;
155 double _directionRotationRate;
156 double _directionRotationAcceleration;
157 double _directionRotationDeceleration;
159 double _viewOffsetDelta;
160 double _pitchOffsetRate;
162 double _yawOffsetRate;
167 osg::Vec3d _direction;
168 osg::Vec3d _position;
173 bool _decelerateOffsetRate;
175 bool _straightenOffset;
178 void _keyDown( const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &);
179 void _keyUp( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter &);
180 void _frame(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter &);
182 void _adjustPosition();