root/OpenSceneGraph/trunk/include/osgGA/UFOManipulator @ 13041

Revision 13041, 6.6 kB (checked in by robert, 3 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 *
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.
7 *
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.
12*/
13
14#ifndef OSGGA_UFO_MANIPULATOR_DEF
15#define OSGGA_UFO_MANIPULATOR_DEF 1
16
17#include <iostream>
18
19#include <osgGA/CameraManipulator>
20#include <osg/Node>
21#include <osg/Matrix>
22
23/**
24  \class osgGA::UFOManipulator
25  \brief A UFO manipulator driven with keybindings.
26
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.
30
31  The UFO Manipulator allows the following movements with the listed
32  Key combinations:
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.
43
44When the Shift key is released, up, down, linear left and/or linear right movement is decelerated.
45
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.
51
52*/
53
54namespace osgGA {
55
56class OSGGA_EXPORT UFOManipulator : public osgGA::CameraManipulator
57{
58
59    public:
60        /** Default constructor */
61        UFOManipulator();
62
63        /** return className
64          \return returns constant "UFO"
65          */
66        virtual const char* className() const;
67
68        /** Set the current position with a matrix
69          \param matrix  A viewpoint matrix.
70         */
71        virtual void setByMatrix( const osg::Matrixd &matrix ) ;
72
73        /** Set the current position with the inverse matrix
74          \param invmat The inverse of a viewpoint matrix
75          */
76        virtual void setByInverseMatrix( const osg::Matrixd &invmat);
77
78        /** Get the current viewmatrix */
79        virtual osg::Matrixd getMatrix() const;
80
81        /** Get the current inverse view matrix */
82        virtual osg::Matrixd getInverseMatrix() const ;
83
84        /** Set the  subgraph this manipulator is driving the eye through.
85            \param node     root of subgraph
86         */
87        virtual void setNode(osg::Node* node);
88
89        /** Get the root node of the subgraph this manipulator is driving the eye through (const)*/
90        virtual const osg::Node* getNode() const;
91
92        /** Get the root node of the subgraph this manipulator is driving the eye through */
93        virtual osg::Node* getNode();
94
95        /** Computes the home position based on the extents and scale of the
96            scene graph rooted at node */
97        virtual void computeHomePosition();
98
99        /** Sets the viewpoint matrix to the home position */
100        virtual void home(const osgGA::GUIEventAdapter&, osgGA::GUIActionAdapter&) ;
101        void home(double);
102
103        virtual void init(const GUIEventAdapter& ,GUIActionAdapter&);
104
105        /** Handles incoming osgGA events */
106        bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter &aa);
107
108        /** Reports Usage parameters to the application */
109        void getUsage(osg::ApplicationUsage& usage) const;
110
111        /** Report the current position as LookAt vectors */
112        void getCurrentPositionAsLookAt( osg::Vec3d& eye, osg::Vec3d& center, osg::Vec3d& up );
113
114
115        void setMinHeight( double in_min_height ) { _minHeightAboveGround = in_min_height; }
116        double getMinHeight() const { return _minHeightAboveGround; }
117
118        void setMinDistance( double in_min_dist ) { _minDistanceInFront = in_min_dist; }
119        double getMinDistance() const { return _minDistanceInFront; }
120
121        void setForwardSpeed( double in_fs ) { _forwardSpeed = in_fs; }
122        double getForwardSpeed() const { return _forwardSpeed; }
123
124        void setSideSpeed( double in_ss ) { _sideSpeed = in_ss; }
125        double getSideSpeed() const { return _sideSpeed; }
126
127        void setRotationSpeed( double in_rot_speed ) { _directionRotationRate = in_rot_speed; }
128        double getRotationSpeed() const { return _directionRotationRate; }
129
130
131    protected:
132
133        virtual ~UFOManipulator();
134
135        bool intersect(const osg::Vec3d& start, const osg::Vec3d& end, osg::Vec3d& intersection) const;
136
137        osg::observer_ptr<osg::Node> _node;
138        float       _viewAngle;
139        osg::Matrixd _matrix;
140        osg::Matrixd _inverseMatrix;
141        osg::Matrixd _offset;
142
143        double    _minHeightAboveGround;
144        double    _minDistanceInFront;
145
146        double    _speedEpsilon;
147        double    _forwardSpeed;
148        double    _sideSpeed;
149        double    _upSpeed;
150        double    _speedAccelerationFactor;
151        double    _speedDecelerationFactor;
152
153        bool      _decelerateUpSideRate;
154
155        double    _directionRotationEpsilon;
156        double    _directionRotationRate;
157        double    _directionRotationAcceleration;
158        double    _directionRotationDeceleration;
159
160        double    _viewOffsetDelta;
161        double    _pitchOffsetRate;
162        double    _pitchOffset;
163        double    _yawOffsetRate;
164        double    _yawOffset;
165
166        double    _t0;
167        double    _dt;
168        osg::Vec3d _direction;
169        osg::Vec3d _position;
170
171
172        bool _shift;
173        bool _ctrl;
174        bool _decelerateOffsetRate;
175
176        bool _straightenOffset;
177
178        void _stop();
179        void _keyDown( const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &);
180        void _keyUp( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter &);
181        void _frame(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter &);
182
183        void _adjustPosition();
184};
185
186}
187
188#endif
Note: See TracBrowser for help on using the browser.