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

Revision 5328, 3.6 kB (checked in by robert, 8 years ago)

Updated copyright years.

  • 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_GliderMANIPULATOR
15#define OSGGA_GliderMANIPULATOR 1
16
17#include <osgGA/MatrixManipulator>
18#include <osg/Quat>
19
20/**
21GliderManipulator is a MatrixManipulator which provides Glider simulator-like
22updating of the camera position & orientation. By default, the left mouse
23button accelerates, the right mouse button decelerates, and the middle mouse
24button (or left and right simultaneously) stops dead.
25*/
26
27class GliderManipulator : public osgGA::MatrixManipulator
28{
29    public:
30
31        GliderManipulator();
32
33        virtual const char* className() const { return "Glider"; }
34
35        /** set the position of the matrix manipulator using a 4x4 Matrix.*/
36        virtual void setByMatrix(const osg::Matrixd& matrix);
37
38        /** set the position of the matrix manipulator using a 4x4 Matrix.*/
39        virtual void setByInverseMatrix(const osg::Matrixd& matrix) { setByMatrix(osg::Matrixd::inverse(matrix)); }
40
41        /** get the position of the manipulator as 4x4 Matrix.*/
42        virtual osg::Matrixd getMatrix() const;
43
44        /** get the position of the manipulator as a inverse matrix of the manipulator, typically used as a model view matrix.*/
45        virtual osg::Matrixd getInverseMatrix() const;
46
47
48        virtual void setNode(osg::Node*);
49
50        virtual const osg::Node* getNode() const;
51
52        virtual osg::Node* getNode();
53
54        virtual void home(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& us);
55
56        virtual void init(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& us);
57
58        virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& us);
59
60        /** Get the keyboard and mouse usage of this manipulator.*/
61        virtual void getUsage(osg::ApplicationUsage& usage) const;
62
63        enum YawControlMode {
64                YAW_AUTOMATICALLY_WHEN_BANKED,
65                NO_AUTOMATIC_YAW
66        };
67
68        /**        Configure the Yaw control for the Glider model.        */
69        void setYawControlMode(YawControlMode ycm) { _yawMode = ycm; }
70
71    protected:
72
73        virtual ~GliderManipulator();
74
75        /** Reset the internal GUIEvent stack.*/
76        void flushMouseEventStack();
77        /** Add the current mouse GUIEvent to internal stack.*/
78        void addMouseEvent(const osgGA::GUIEventAdapter& ea);
79
80        void computePosition(const osg::Vec3& eye,const osg::Vec3& lv,const osg::Vec3& up);
81
82        /** For the give mouse movement calculate the movement of the camera.
83            Return true is camera has moved and a redraw is required.*/
84        bool calcMovement();
85
86
87        // Internal event stack comprising last three mouse events.
88        osg::ref_ptr<const osgGA::GUIEventAdapter> _ga_t1;
89        osg::ref_ptr<const osgGA::GUIEventAdapter> _ga_t0;
90
91        osg::ref_ptr<osg::Node>       _node;
92
93        float _modelScale;
94        float _velocity;
95
96        YawControlMode _yawMode;
97       
98        osg::Vec3   _eye;
99        osg::Quat   _rotation;
100        float       _distance;
101
102};
103
104#endif
Note: See TracBrowser for help on using the browser.