1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
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.
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.
14#ifndef OSGGA_DRIVEMANIPULATOR
15#define OSGGA_DRIVEMANIPULATOR 1
17#include <osgGA/CameraManipulator>
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.
29class OSGGA_EXPORT DriveManipulator : public CameraManipulator
35 virtual const char* className() const { return "Drive"; }
37 /** Get the position of the matrix manipulator using a 4x4 Matrix.*/
38 virtual void setByMatrix(const osg::Matrixd& matrix);
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)); }
43 /** Get the position of the manipulator as 4x4 Matrix.*/
44 virtual osg::Matrixd getMatrix() const;
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;
49 virtual void setNode(osg::Node*);
51 virtual const osg::Node* getNode() const;
53 virtual osg::Node* getNode();
55 virtual void computeHomePosition();
57 virtual void home(const GUIEventAdapter& ea,GUIActionAdapter& us);
59 virtual void init(const GUIEventAdapter& ea,GUIActionAdapter& us);
61 virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& us);
63 /** Get the keyboard and mouse usage of this manipulator.*/
64 virtual void getUsage(osg::ApplicationUsage& usage) const;
66 void setModelScale( double in_ms ) { _modelScale = in_ms; }
67 double getModelScale() const { return _modelScale; }
69 void setVelocity( double in_vel ) { _velocity = in_vel; }
70 double getVelocity() const { return _velocity; }
72 void setHeight( double in_h ) { _height = in_h; }
73 double getHeight() const { return _height; }
77 virtual ~DriveManipulator();
79 bool intersect(const osg::Vec3d& start, const osg::Vec3d& end, osg::Vec3d& intersection, osg::Vec3d& normal) const;
81 /** Reset the internal GUIEvent stack.*/
82 void flushMouseEventStack();
84 /** Add the current mouse GUIEvent to internal stack.*/
85 void addMouseEvent(const GUIEventAdapter& ea);
87 void computePosition(const osg::Vec3d& eye,const osg::Vec3d& lv,const osg::Vec3d& up);
89 /** For the given mouse movement calculate the movement of the camera.
90 * Return true if camera has moved and a redraw is required.
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;
98 osg::observer_ptr<osg::Node> _node;
105 enum SpeedControlMode {
106 USE_MOUSE_Y_FOR_SPEED,
107 USE_MOUSE_BUTTONS_FOR_SPEED
110 SpeedControlMode _speedMode;
117 bool _pitchUpKeyPressed;
118 bool _pitchDownKeyPressed;