openscenegraph
DriveManipulator
Go to the documentation of this file.
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_DRIVEMANIPULATOR
15#define OSGGA_DRIVEMANIPULATOR 1
16
17#include <osgGA/CameraManipulator>
18#include <osg/Quat>
19
20namespace osgGA{
21
22/**
23DriveManipulator is a camera manipulator which provides drive-like
24functionality. By default, the left mouse button accelerates, the right
25mouse button decelerates, and the middle mouse button (or left and
26right simultaneously) stops dead.
27*/
28
29class OSGGA_EXPORT DriveManipulator : public CameraManipulator
30{
31 public:
32
33 DriveManipulator();
34
35 virtual const char* className() const { return "Drive"; }
36
37 /** Get the position of the matrix manipulator using a 4x4 Matrix.*/
38 virtual void setByMatrix(const osg::Matrixd& matrix);
39
40 /** Set the position of the matrix manipulator using a 4x4 Matrix.*/
41 virtual void setByInverseMatrix(const osg::Matrixd& matrix) { setByMatrix(osg::Matrixd::inverse(matrix)); }
42
43 /** Get the position of the manipulator as 4x4 Matrix.*/
44 virtual osg::Matrixd getMatrix() const;
45
46 /** Get the position of the manipulator as a inverse matrix of the manipulator, typically used as a model view matrix.*/
47 virtual osg::Matrixd getInverseMatrix() const;
48
49 virtual void setNode(osg::Node*);
50
51 virtual const osg::Node* getNode() const;
52
53 virtual osg::Node* getNode();
54
55 virtual void computeHomePosition();
56
57 virtual void home(const GUIEventAdapter& ea,GUIActionAdapter& us);
58
59 virtual void init(const GUIEventAdapter& ea,GUIActionAdapter& us);
60
61 virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& us);
62
63 /** Get the keyboard and mouse usage of this manipulator.*/
64 virtual void getUsage(osg::ApplicationUsage& usage) const;
65
66 void setModelScale( double in_ms ) { _modelScale = in_ms; }
67 double getModelScale() const { return _modelScale; }
68
69 void setVelocity( double in_vel ) { _velocity = in_vel; }
70 double getVelocity() const { return _velocity; }
71
72 void setHeight( double in_h ) { _height = in_h; }
73 double getHeight() const { return _height; }
74
75 protected:
76
77 virtual ~DriveManipulator();
78
79 bool intersect(const osg::Vec3d& start, const osg::Vec3d& end, osg::Vec3d& intersection, osg::Vec3d& normal) const;
80
81 /** Reset the internal GUIEvent stack.*/
82 void flushMouseEventStack();
83
84 /** Add the current mouse GUIEvent to internal stack.*/
85 void addMouseEvent(const GUIEventAdapter& ea);
86
87 void computePosition(const osg::Vec3d& eye,const osg::Vec3d& lv,const osg::Vec3d& up);
88
89 /** For the given mouse movement calculate the movement of the camera.
90 * Return true if camera has moved and a redraw is required.
91 */
92 bool calcMovement();
93
94 // Internal event stack comprising last two mouse events.
95 osg::ref_ptr<const GUIEventAdapter> _ga_t1;
96 osg::ref_ptr<const GUIEventAdapter> _ga_t0;
97
98 osg::observer_ptr<osg::Node> _node;
99
100 double _modelScale;
101 double _velocity;
102 double _height;
103 double _buffer;
104
105 enum SpeedControlMode {
106 USE_MOUSE_Y_FOR_SPEED,
107 USE_MOUSE_BUTTONS_FOR_SPEED
108 };
109
110 SpeedControlMode _speedMode;
111
112 osg::Vec3d _eye;
113 osg::Quat _rotation;
114 double _pitch;
115 double _distance;
116
117 bool _pitchUpKeyPressed;
118 bool _pitchDownKeyPressed;
119};
120
121}
122
123#endif