OpenSceneGraph/include/osgGA/KeySwitchMatrixManipulator
2004-04-30 09:04:10 +00:00

127 lines
5.0 KiB
C++

/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield
*
* 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.
*/
#ifndef OSGUTIL_KEYSWITCMATRIXMANIPULATOR
#define OSGUTIL_KEYSWITCMATRIXMANIPULATOR 1
#include <osgGA/Export>
#include <osgGA/MatrixManipulator>
#include <osgGA/GUIEventHandler>
#include <osgGA/GUIEventHandlerVisitor>
namespace osgGA{
class GUIEventAdapter;
class GUIActionAdapter;
/**
KeySwitchMatrixManipulator is a decorator which allows the type of camera manipulator
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.
*/
class OSGGA_EXPORT KeySwitchMatrixManipulator : public MatrixManipulator
{
public:
typedef std::pair<std::string, osg::ref_ptr<MatrixManipulator> > NamedManipulator;
typedef std::map<int, NamedManipulator> KeyManipMap;
virtual const char* className() const { return "KeySwitchMatrixManipulator"; }
/**
Add a camera manipulator with an associated name, and a key to
trigger the switch,
*/
void addMatrixManipulator(int key, std::string name, MatrixManipulator *cm);
/**
Add a camera manipulator with an autogenerated keybinding which is '1' + previous number of camera's registerd.
*/
void addNumberedMatrixManipulator(MatrixManipulator *cm);
unsigned int getNumMatrixManipulators() const { return _manips.size(); }
void selectMatrixManipulator(unsigned int num);
/** 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; }
/** Get the current active manipulators.*/
MatrixManipulator* getCurrentMatrixManipulator() { return _current.get(); }
/** Get the const current active manipulators.*/
const MatrixManipulator* getCurrentMatrixManipulator() const { return _current.get(); }
/** Get manipulator assigned to a specified key.*/
MatrixManipulator* getMatrixManipulator(unsigned int key);
/** Get const manipulator assigned to a specified key.*/
const MatrixManipulator* getMatrixManipulator(unsigned int key) const;
// Overrides from MatrixManipulator...
/** Set the coordinate frame which tells the manipulator which way is up, east and north.*/
virtual void setCoordinateFrame(const osg::CoordinateFrame& cf) { _coordinateFrame = cf; _current->setCoordinateFrame(cf); }
/** Set the position of the matrix manipulator using a 4x4 Matrix.*/
virtual void setByMatrix(const osg::Matrixd& matrix) { _current->setByMatrix(matrix); }
/** set the position of the matrix manipulator using a 4x4 Matrix.*/
virtual void setByInverseMatrix(const osg::Matrixd& matrix) { _current->setByInverseMatrix(matrix); }
/** get the position of the manipulator as 4x4 Matrix.*/
virtual osg::Matrixd getMatrix() const { return _current->getMatrix(); }
/** get the position of the manipulator as a inverse matrix of the manipulator, typically used as a model view matrix.*/
virtual osg::Matrixd getInverseMatrix() const { return _current->getInverseMatrix(); }
/** Get the FusionDistanceMode. Used by SceneView for setting up setereo convergence.*/
virtual osgUtil::SceneView::FusionDistanceMode getFusionDistanceMode() const { return _current->getFusionDistanceMode(); }
/** Get the FusionDistanceValue. Used by SceneView for setting up setereo convergence.*/
virtual float getFusionDistanceValue() const { return _current->getFusionDistanceValue(); }
virtual void setNode(osg::Node* n);
virtual const osg::Node* getNode() const { return _current->getNode(); }
virtual osg::Node* getNode() { return _current->getNode(); }
virtual void home(const GUIEventAdapter& ee,GUIActionAdapter& aa) { _current->home(ee,aa); }
virtual void init(const GUIEventAdapter& ee,GUIActionAdapter& aa) { _current->init(ee,aa); }
virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& us);
/** Get the keyboard and mouse usage of this manipulator.*/
virtual void getUsage(osg::ApplicationUsage& usage) const;
private:
KeyManipMap _manips;
osg::ref_ptr<MatrixManipulator> _current;
};
};
#endif