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

Revision 10913, 5.0 kB (checked in by robert, 5 years ago)

Added set/getDistance() method

  • 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        /** Set the distance of the trackball. */
60        void setDistance(double distance) { _distance = distance; }
61
62        /** Get the distance of the trackball. */
63        double getDistance() const { return _distance; }
64
65
66        /** Attach a node to the manipulator.
67            Automatically detaches previously attached node.
68            setNode(NULL) detaches previously nodes.
69            Is ignored by manipulators which do not require a reference model.*/
70        virtual void setNode(osg::Node*);
71
72        /** Return node if attached.*/
73        virtual const osg::Node* getNode() const;
74
75        /** Return node if attached.*/
76        virtual osg::Node* getNode();
77
78        /** Move the camera to the default position.
79            May be ignored by manipulators if home functionality is not appropriate.*/
80        virtual void home(const GUIEventAdapter& ea,GUIActionAdapter& us);
81       
82        /** Start/restart the manipulator.*/
83        virtual void init(const GUIEventAdapter& ea,GUIActionAdapter& us);
84
85        /** handle events, return true if handled, false otherwise.*/
86        virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& us);
87
88        /** Get the keyboard and mouse usage of this manipulator.*/
89        virtual void getUsage(osg::ApplicationUsage& usage) const;
90
91    protected:
92
93        virtual ~TerrainManipulator();
94       
95        bool intersect(const osg::Vec3d& start, const osg::Vec3d& end, osg::Vec3d& intersection) const;
96
97        /** Reset the internal GUIEvent stack.*/
98        void flushMouseEventStack();
99        /** Add the current mouse GUIEvent to internal stack.*/
100        void addMouseEvent(const GUIEventAdapter& ea);
101
102        void computePosition(const osg::Vec3d& eye,const osg::Vec3d& lv,const osg::Vec3d& up);
103
104        /** For the give mouse movement calculate the movement of the camera.
105            Return true is camera has moved and a redraw is required.*/
106        bool calcMovement();
107       
108        void trackball(osg::Vec3& axis,double& angle, double p1x, double p1y, double p2x, double p2y);
109        double tb_project_to_sphere(double r, double x, double y);
110
111
112        /** Check the speed at which the mouse is moving.
113            If speed is below a threshold then return false, otherwise return true.*/
114        bool isMouseMoving();
115
116
117        void clampOrientation();
118
119
120        // Internal event stack comprising last two mouse events.
121        osg::ref_ptr<const GUIEventAdapter> _ga_t1;
122        osg::ref_ptr<const GUIEventAdapter> _ga_t0;
123
124        osg::ref_ptr<osg::Node> _node;
125
126        RotationMode            _rotationMode;
127
128        bool                    _thrown;
129       
130        osg::Vec3d              _center;
131        osg::Quat               _rotation;
132        double                  _distance;
133        osg::Vec3d              _previousUp;
134
135};
136
137}
138
139#endif
140
Note: See TracBrowser for help on using the browser.