root/OpenSceneGraph/trunk/examples/osghangglide/GliderManipulator.h @ 6941

Revision 6941, 3.9 kB (checked in by robert, 7 years ago)

From Martin Lavery and Robert Osfield, Updated examples to use a variation of the MIT License

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/* -*-c++-*-
2*
3*  OpenSceneGraph example, osghangglide.
4*
5*  Permission is hereby granted, free of charge, to any person obtaining a copy
6*  of this software and associated documentation files (the "Software"), to deal
7*  in the Software without restriction, including without limitation the rights
8*  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9*  copies of the Software, and to permit persons to whom the Software is
10*  furnished to do so, subject to the following conditions:
11*
12*  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13*  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14*  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15*  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16*  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17*  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
18*  THE SOFTWARE.
19*/
20 
21#ifndef OSGGA_GliderMANIPULATOR
22#define OSGGA_GliderMANIPULATOR 1
23
24#include <osgGA/MatrixManipulator>
25#include <osg/Quat>
26
27/**
28GliderManipulator is a MatrixManipulator which provides Glider simulator-like
29updating of the camera position & orientation. By default, the left mouse
30button accelerates, the right mouse button decelerates, and the middle mouse
31button (or left and right simultaneously) stops dead.
32*/
33
34class GliderManipulator : public osgGA::MatrixManipulator
35{
36    public:
37
38        GliderManipulator();
39
40        virtual const char* className() const { return "Glider"; }
41
42        /** set the position of the matrix manipulator using a 4x4 Matrix.*/
43        virtual void setByMatrix(const osg::Matrixd& matrix);
44
45        /** set the position of the matrix manipulator using a 4x4 Matrix.*/
46        virtual void setByInverseMatrix(const osg::Matrixd& matrix) { setByMatrix(osg::Matrixd::inverse(matrix)); }
47
48        /** get the position of the manipulator as 4x4 Matrix.*/
49        virtual osg::Matrixd getMatrix() const;
50
51        /** get the position of the manipulator as a inverse matrix of the manipulator, typically used as a model view matrix.*/
52        virtual osg::Matrixd getInverseMatrix() const;
53
54
55        virtual void setNode(osg::Node*);
56
57        virtual const osg::Node* getNode() const;
58
59        virtual osg::Node* getNode();
60
61        virtual void home(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& us);
62
63        virtual void init(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& us);
64
65        virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& us);
66
67        /** Get the keyboard and mouse usage of this manipulator.*/
68        virtual void getUsage(osg::ApplicationUsage& usage) const;
69
70        enum YawControlMode {
71                YAW_AUTOMATICALLY_WHEN_BANKED,
72                NO_AUTOMATIC_YAW
73        };
74
75        /**        Configure the Yaw control for the Glider model.        */
76        void setYawControlMode(YawControlMode ycm) { _yawMode = ycm; }
77
78    protected:
79
80        virtual ~GliderManipulator();
81
82        /** Reset the internal GUIEvent stack.*/
83        void flushMouseEventStack();
84        /** Add the current mouse GUIEvent to internal stack.*/
85        void addMouseEvent(const osgGA::GUIEventAdapter& ea);
86
87        void computePosition(const osg::Vec3& eye,const osg::Vec3& lv,const osg::Vec3& up);
88
89        /** For the give mouse movement calculate the movement of the camera.
90            Return true is camera has moved and a redraw is required.*/
91        bool calcMovement();
92
93
94        // Internal event stack comprising last three mouse events.
95        osg::ref_ptr<const osgGA::GUIEventAdapter> _ga_t1;
96        osg::ref_ptr<const osgGA::GUIEventAdapter> _ga_t0;
97
98        osg::ref_ptr<osg::Node>       _node;
99
100        float _modelScale;
101        float _velocity;
102
103        YawControlMode _yawMode;
104       
105        osg::Vec3   _eye;
106        osg::Quat   _rotation;
107        float       _distance;
108
109};
110
111#endif
Note: See TracBrowser for help on using the browser.