2006-07-18 23:21:48 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
2003-01-22 00:45:36 +08:00
|
|
|
*
|
|
|
|
* This library is open source and may be redistributed and/or modified under
|
|
|
|
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
2002-07-17 04:07:32 +08:00
|
|
|
|
2003-05-20 04:18:37 +08:00
|
|
|
#ifndef OSGUTIL_KEYSWITCMATRIXMANIPULATOR
|
|
|
|
#define OSGUTIL_KEYSWITCMATRIXMANIPULATOR 1
|
2002-05-09 18:31:03 +08:00
|
|
|
|
|
|
|
#include <osgGA/Export>
|
2003-05-20 04:18:37 +08:00
|
|
|
#include <osgGA/MatrixManipulator>
|
2002-05-09 18:31:03 +08:00
|
|
|
#include <osgGA/GUIEventHandler>
|
|
|
|
|
|
|
|
namespace osgGA{
|
|
|
|
|
|
|
|
class GUIActionAdapter;
|
|
|
|
|
2002-08-28 22:27:18 +08:00
|
|
|
/**
|
2003-05-20 04:18:37 +08:00
|
|
|
KeySwitchMatrixManipulator is a decorator which allows the type of camera manipulator
|
2002-08-28 22:27:18 +08:00
|
|
|
being used to be switched by pressing a key. E.g. '1' for a TrackballManipultor,
|
|
|
|
'2' for a DriveManipulator, '3' for a FlightManipulator. The manipulators available,
|
|
|
|
and the associated switch keys, can be configured.
|
|
|
|
*/
|
2003-05-20 04:18:37 +08:00
|
|
|
class OSGGA_EXPORT KeySwitchMatrixManipulator : public MatrixManipulator
|
2002-05-09 18:31:03 +08:00
|
|
|
{
|
2002-08-28 22:27:18 +08:00
|
|
|
public:
|
2002-05-09 18:31:03 +08:00
|
|
|
|
2004-04-30 17:04:10 +08:00
|
|
|
typedef std::pair<std::string, osg::ref_ptr<MatrixManipulator> > NamedManipulator;
|
|
|
|
typedef std::map<int, NamedManipulator> KeyManipMap;
|
|
|
|
|
2004-02-05 20:11:06 +08:00
|
|
|
virtual const char* className() const { return "KeySwitchMatrixManipulator"; }
|
2003-02-19 18:43:02 +08:00
|
|
|
|
2002-08-28 22:27:18 +08:00
|
|
|
/**
|
|
|
|
Add a camera manipulator with an associated name, and a key to
|
|
|
|
trigger the switch,
|
|
|
|
*/
|
2003-05-20 04:18:37 +08:00
|
|
|
void addMatrixManipulator(int key, std::string name, MatrixManipulator *cm);
|
2002-05-09 18:31:03 +08:00
|
|
|
|
2005-11-18 01:44:48 +08:00
|
|
|
/**
|
|
|
|
Add a camera manipulator with an autogenerated keybinding which is '1' + previous number of camera's registerd.
|
|
|
|
*/
|
2003-05-20 04:18:37 +08:00
|
|
|
void addNumberedMatrixManipulator(MatrixManipulator *cm);
|
2002-07-17 18:00:50 +08:00
|
|
|
|
2003-08-19 22:05:53 +08:00
|
|
|
unsigned int getNumMatrixManipulators() const { return _manips.size(); }
|
2003-01-22 23:30:17 +08:00
|
|
|
|
2003-05-20 04:18:37 +08:00
|
|
|
void selectMatrixManipulator(unsigned int num);
|
2003-01-22 23:30:17 +08:00
|
|
|
|
2004-04-30 17:04:10 +08:00
|
|
|
/** Get the complete list of manipulators attached to this keyswitch manipulator.*/
|
|
|
|
KeyManipMap& getKeyManipMap() { return _manips; }
|
|
|
|
|
|
|
|
/** Get the const complete list of manipulators attached to this keyswitch manipulator.*/
|
|
|
|
const KeyManipMap& getKeyManipMap() const { return _manips; }
|
|
|
|
|
2003-01-22 23:30:17 +08:00
|
|
|
|
2004-04-30 17:04:10 +08:00
|
|
|
/** Get the current active manipulators.*/
|
2003-05-20 04:18:37 +08:00
|
|
|
MatrixManipulator* getCurrentMatrixManipulator() { return _current.get(); }
|
2003-01-17 22:12:25 +08:00
|
|
|
|
2004-04-30 17:04:10 +08:00
|
|
|
/** Get the const current active manipulators.*/
|
2003-05-20 04:18:37 +08:00
|
|
|
const MatrixManipulator* getCurrentMatrixManipulator() const { return _current.get(); }
|
2003-01-17 22:12:25 +08:00
|
|
|
|
2003-03-20 05:14:50 +08:00
|
|
|
|
2005-11-14 19:00:36 +08:00
|
|
|
/** Get manipulator assigned to a specified index.*/
|
|
|
|
MatrixManipulator* getMatrixManipulatorWithIndex(unsigned int key);
|
|
|
|
|
|
|
|
/** Get const manipulator assigned to a specified index.*/
|
|
|
|
const MatrixManipulator* getMatrixManipulatorWithIndex(unsigned int key) const;
|
|
|
|
|
2004-04-30 17:04:10 +08:00
|
|
|
/** Get manipulator assigned to a specified key.*/
|
2005-11-14 19:00:36 +08:00
|
|
|
MatrixManipulator* getMatrixManipulatorWithKey(unsigned int key);
|
2003-03-20 05:14:50 +08:00
|
|
|
|
2004-04-30 17:04:10 +08:00
|
|
|
/** Get const manipulator assigned to a specified key.*/
|
2005-11-14 19:00:36 +08:00
|
|
|
const MatrixManipulator* getMatrixManipulatorWithKey(unsigned int key) const;
|
2003-03-20 05:14:50 +08:00
|
|
|
|
|
|
|
|
2003-05-20 04:18:37 +08:00
|
|
|
// Overrides from MatrixManipulator...
|
2002-05-09 18:31:03 +08:00
|
|
|
|
2004-07-09 23:21:33 +08:00
|
|
|
/** set the minimum distance (as ratio) the eye point can be zoomed in towards the
|
|
|
|
center before the center is pushed forward.*/
|
|
|
|
virtual void setMinimumDistance(float minimumDistance);
|
|
|
|
|
2004-05-06 19:01:16 +08:00
|
|
|
/** set the coordinate frame which callback tells the manipulator which way is up, east and north.*/
|
|
|
|
virtual void setCoordinateFrameCallback(CoordinateFrameCallback* cb);
|
2003-01-17 22:12:25 +08:00
|
|
|
|
2004-04-30 17:04:10 +08:00
|
|
|
/** Set the position of the matrix manipulator using a 4x4 Matrix.*/
|
2003-09-06 06:35:34 +08:00
|
|
|
virtual void setByMatrix(const osg::Matrixd& matrix) { _current->setByMatrix(matrix); }
|
2002-05-09 18:31:03 +08:00
|
|
|
|
2003-05-20 04:18:37 +08:00
|
|
|
/** set the position of the matrix manipulator using a 4x4 Matrix.*/
|
2003-09-06 06:35:34 +08:00
|
|
|
virtual void setByInverseMatrix(const osg::Matrixd& matrix) { _current->setByInverseMatrix(matrix); }
|
2003-05-20 04:18:37 +08:00
|
|
|
|
|
|
|
/** get the position of the manipulator as 4x4 Matrix.*/
|
2003-09-06 06:35:34 +08:00
|
|
|
virtual osg::Matrixd getMatrix() const { return _current->getMatrix(); }
|
2003-05-20 04:18:37 +08:00
|
|
|
|
|
|
|
/** get the position of the manipulator as a inverse matrix of the manipulator, typically used as a model view matrix.*/
|
2003-09-06 06:35:34 +08:00
|
|
|
virtual osg::Matrixd getInverseMatrix() const { return _current->getInverseMatrix(); }
|
2003-05-20 04:18:37 +08:00
|
|
|
|
2007-12-11 01:30:18 +08:00
|
|
|
/** Get the FusionDistanceMode. Used by SceneView for setting up stereo convergence.*/
|
2003-05-20 04:18:37 +08:00
|
|
|
virtual osgUtil::SceneView::FusionDistanceMode getFusionDistanceMode() const { return _current->getFusionDistanceMode(); }
|
|
|
|
|
2007-12-11 01:30:18 +08:00
|
|
|
/** Get the FusionDistanceValue. Used by SceneView for setting up stereo convergence.*/
|
2003-05-20 04:18:37 +08:00
|
|
|
virtual float getFusionDistanceValue() const { return _current->getFusionDistanceValue(); }
|
2002-05-09 18:31:03 +08:00
|
|
|
|
|
|
|
|
2003-04-08 21:10:47 +08:00
|
|
|
virtual void setNode(osg::Node* n);
|
2002-05-09 18:31:03 +08:00
|
|
|
|
|
|
|
virtual const osg::Node* getNode() const { return _current->getNode(); }
|
|
|
|
|
|
|
|
virtual osg::Node* getNode() { return _current->getNode(); }
|
|
|
|
|
2004-09-01 18:18:46 +08:00
|
|
|
virtual void setHomePosition(const osg::Vec3d& eye, const osg::Vec3d& center, const osg::Vec3d& up, bool autoComputeHomePosition=false);
|
2004-07-13 03:54:54 +08:00
|
|
|
|
|
|
|
virtual void setAutoComputeHomePosition(bool flag);
|
|
|
|
|
|
|
|
virtual void computeHomePosition();
|
|
|
|
|
2007-01-10 21:52:22 +08:00
|
|
|
virtual void home(const GUIEventAdapter& ee,GUIActionAdapter& aa) { if (_current.valid()) _current->home(ee,aa); }
|
2002-05-09 18:31:03 +08:00
|
|
|
|
2007-01-10 21:52:22 +08:00
|
|
|
virtual void init(const GUIEventAdapter& ee,GUIActionAdapter& aa) { if (_current.valid()) _current->init(ee,aa); }
|
2002-05-09 18:31:03 +08:00
|
|
|
|
|
|
|
virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& us);
|
|
|
|
|
2003-02-19 18:43:02 +08:00
|
|
|
/** Get the keyboard and mouse usage of this manipulator.*/
|
|
|
|
virtual void getUsage(osg::ApplicationUsage& usage) const;
|
|
|
|
|
2002-08-28 22:27:18 +08:00
|
|
|
private:
|
2002-05-09 18:31:03 +08:00
|
|
|
|
|
|
|
KeyManipMap _manips;
|
|
|
|
|
2003-05-20 04:18:37 +08:00
|
|
|
osg::ref_ptr<MatrixManipulator> _current;
|
2002-05-09 18:31:03 +08:00
|
|
|
};
|
|
|
|
|
2007-04-06 23:36:13 +08:00
|
|
|
}
|
2002-05-09 18:31:03 +08:00
|
|
|
|
|
|
|
#endif
|