root/OpenSceneGraph/trunk/include/osgGA/TerrainManipulator @ 10255

Revision 10255, 4.7 kB (checked in by robert, 5 years ago)

Changed TerrainManipulator? to use HEADING rather than AZIM to keep it consistent with SphericalManipulator?

  • 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_TERRAINMANIPULATOR
15#define OSGGA_TERRAINMANIPULATOR 1
16
17#include <osgGA/MatrixManipulator>
18#include <osg/Quat>
19
20namespace osgGA{
21
22class OSGGA_EXPORT TerrainManipulator : public MatrixManipulator
23{
24    public:
25
26        TerrainManipulator();
27
28        virtual const char* className() const { return "Terrain"; }
29
30
31        enum RotationMode
32        {
33            ELEVATION_HEADING_ROLL,
34            ELEVATION_HEADING
35        };
36
37        void setRotationMode(RotationMode mode);
38        RotationMode getRotationMode() const { return _rotationMode; }
39
40
41        /** set the position of the matrix manipulator using a 4x4 Matrix.*/
42        virtual void setByMatrix(const osg::Matrixd& matrix);
43
44        /** set the position of the matrix manipulator using a 4x4 Matrix.*/
45        virtual void setByInverseMatrix(const osg::Matrixd& matrix) { setByMatrix(osg::Matrixd::inverse(matrix)); }
46
47        /** get the position of the manipulator as 4x4 Matrix.*/
48        virtual osg::Matrixd getMatrix() const;
49
50        /** get the position of the manipulator as a inverse matrix of the manipulator, typically used as a model view matrix.*/
51        virtual osg::Matrixd getInverseMatrix() const;
52
53        /** Get the FusionDistanceMode. Used by SceneView for setting up stereo convergence.*/
54        virtual osgUtil::SceneView::FusionDistanceMode getFusionDistanceMode() const { return osgUtil::SceneView::USE_FUSION_DISTANCE_VALUE; }
55
56        /** Get the FusionDistanceValue. Used by SceneView for setting up stereo convergence.*/
57        virtual float getFusionDistanceValue() const { return _distance; }
58
59        /** Attach a node to the manipulator.
60            Automatically detaches previously attached node.
61            setNode(NULL) detaches previously nodes.
62            Is ignored by manipulators which do not require a reference model.*/
63        virtual void setNode(osg::Node*);
64
65        /** Return node if attached.*/
66        virtual const osg::Node* getNode() const;
67
68        /** Return node if attached.*/
69        virtual osg::Node* getNode();
70
71        /** Move the camera to the default position.
72            May be ignored by manipulators if home functionality is not appropriate.*/
73        virtual void home(const GUIEventAdapter& ea,GUIActionAdapter& us);
74       
75        /** Start/restart the manipulator.*/
76        virtual void init(const GUIEventAdapter& ea,GUIActionAdapter& us);
77
78        /** handle events, return true if handled, false otherwise.*/
79        virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& us);
80
81        /** Get the keyboard and mouse usage of this manipulator.*/
82        virtual void getUsage(osg::ApplicationUsage& usage) const;
83
84    protected:
85
86        virtual ~TerrainManipulator();
87       
88        bool intersect(const osg::Vec3d& start, const osg::Vec3d& end, osg::Vec3d& intersection) const;
89
90        /** Reset the internal GUIEvent stack.*/
91        void flushMouseEventStack();
92        /** Add the current mouse GUIEvent to internal stack.*/
93        void addMouseEvent(const GUIEventAdapter& ea);
94
95        void computePosition(const osg::Vec3d& eye,const osg::Vec3d& lv,const osg::Vec3d& up);
96
97        /** For the give mouse movement calculate the movement of the camera.
98            Return true is camera has moved and a redraw is required.*/
99        bool calcMovement();
100       
101        void trackball(osg::Vec3& axis,double& angle, double p1x, double p1y, double p2x, double p2y);
102        double tb_project_to_sphere(double r, double x, double y);
103
104
105        /** Check the speed at which the mouse is moving.
106            If speed is below a threshold then return false, otherwise return true.*/
107        bool isMouseMoving();
108
109
110        void clampOrientation();
111
112
113        // Internal event stack comprising last two mouse events.
114        osg::ref_ptr<const GUIEventAdapter> _ga_t1;
115        osg::ref_ptr<const GUIEventAdapter> _ga_t0;
116
117        osg::ref_ptr<osg::Node> _node;
118
119        RotationMode            _rotationMode;
120
121        bool                    _thrown;
122       
123        osg::Vec3d              _center;
124        osg::Quat               _rotation;
125        double                  _distance;
126        osg::Vec3d              _previousUp;
127
128};
129
130}
131
132#endif
133
Note: See TracBrowser for help on using the browser.