Removed all KeySwitchCameraManipulator class, replacing it

with the KeySwitchMatrixManipulator
This commit is contained in:
Robert Osfield
2003-05-19 20:18:37 +00:00
parent 940ce67133
commit 00e94b86d8
3 changed files with 47 additions and 35 deletions

View File

@@ -11,11 +11,11 @@
* OpenSceneGraph Public License for more details.
*/
#ifndef OSGUTIL_KEYSWITCCAMERAMANIPULATORHER
#define OSGUTIL_KEYSWITCHCAMERAMANIPULATORER 1
#ifndef OSGUTIL_KEYSWITCMATRIXMANIPULATOR
#define OSGUTIL_KEYSWITCMATRIXMANIPULATOR 1
#include <osgGA/Export>
#include <osgGA/CameraManipulator>
#include <osgGA/MatrixManipulator>
#include <osgGA/GUIEventHandler>
#include <osgGA/GUIEventHandlerVisitor>
@@ -25,51 +25,64 @@ class GUIEventAdapter;
class GUIActionAdapter;
/**
KeySwitchCameraManipulator is a decorator which allows the type of camera manipulator
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 KeySwitchCameraManipulator : public CameraManipulator
class OSGGA_EXPORT KeySwitchMatrixManipulator : public MatrixManipulator
{
public:
virtual const char* className() { return "KeySwitchCamera"; }
virtual const char* className() { return "KeySwitchMatrixManipulator"; }
/**
Add a camera manipulator with an associated name, and a key to
trigger the switch,
*/
void addCameraManipulator(int key, std::string name, CameraManipulator *cm);
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 addNumberedCameraManipulator(CameraManipulator *cm);
void addNumberedMatrixManipulator(MatrixManipulator *cm);
unsigned int getNumCameraManipualtors() const { return _manips.size(); }
unsigned int getNumMatrixManipualtors() const { return _manips.size(); }
void selectCameraManipulator(unsigned int num);
void selectMatrixManipulator(unsigned int num);
CameraManipulator* getCurrentCameraManipulator() { return _current.get(); }
MatrixManipulator* getCurrentMatrixManipulator() { return _current.get(); }
const CameraManipulator* getCurrentCameraManipulator() const { return _current.get(); }
const MatrixManipulator* getCurrentMatrixManipulator() const { return _current.get(); }
CameraManipulator* getCameraManipulator(unsigned int num);
MatrixManipulator* getMatrixManipulator(unsigned int num);
const CameraManipulator* getCameraManipulator(unsigned int num) const;
const MatrixManipulator* getMatrixManipulator(unsigned int num) const;
// Overrides from CameraManipulator...
// Overrides from MatrixManipulator...
virtual void setCamera(osg::Camera* c) { _current->setCamera(c); }
/** set the position of the matrix manipulator using a 4x4 Matrix.*/
virtual void setByMatrix(const osg::Matrix& matrix) { _current->setByMatrix(matrix); }
virtual const osg::Camera * getCamera() const { return _current->getCamera(); }
/** set the position of the matrix manipulator using a 4x4 Matrix.*/
virtual void setByInverseMatrix(const osg::Matrix& matrix) { _current->setByInverseMatrix(matrix); }
/** get the position of the manipulator as 4x4 Matrix.*/
virtual osg::Matrix 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::Matrix 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 osg::Camera * getCamera() { return _current->getCamera(); }
virtual void setNode(osg::Node* n);
@@ -88,11 +101,11 @@ public:
private:
typedef std::pair<std::string, osg::ref_ptr<CameraManipulator> > NamedManipulator;
typedef std::pair<std::string, osg::ref_ptr<MatrixManipulator> > NamedManipulator;
typedef std::map<int, NamedManipulator> KeyManipMap;
KeyManipMap _manips;
osg::ref_ptr<CameraManipulator> _current;
osg::ref_ptr<MatrixManipulator> _current;
};
};

View File

@@ -1,27 +1,26 @@
#include <osgGA/KeySwitchCameraManipulator>
#include <osgGA/KeySwitchMatrixManipulator>
#include <osg/Notify>
using namespace osgGA;
void KeySwitchCameraManipulator::addCameraManipulator(int key, std::string name, CameraManipulator *cm)
void KeySwitchMatrixManipulator::addMatrixManipulator(int key, std::string name, MatrixManipulator *cm)
{
if(!cm) return;
_manips[key]=std::make_pair(name,osg::ref_ptr<CameraManipulator>(cm));
_manips[key]=std::make_pair(name,osg::ref_ptr<MatrixManipulator>(cm));
if(!_current.valid()){
_current=cm;
_current->setNode(_current->getNode());
_current->setCamera(_current->getCamera());
}
}
void KeySwitchCameraManipulator::addNumberedCameraManipulator(CameraManipulator *cm)
void KeySwitchMatrixManipulator::addNumberedMatrixManipulator(MatrixManipulator *cm)
{
if(!cm) return;
addCameraManipulator('1'+_manips.size(),cm->className(),cm);
addMatrixManipulator('1'+_manips.size(),cm->className(),cm);
}
void KeySwitchCameraManipulator::selectCameraManipulator(unsigned int num)
void KeySwitchMatrixManipulator::selectMatrixManipulator(unsigned int num)
{
unsigned int manipNo = 0;
KeyManipMap::iterator itr;
@@ -38,13 +37,13 @@ void KeySwitchCameraManipulator::selectCameraManipulator(unsigned int num)
if ( !itr->second.second->getNode() ) {
itr->second.second->setNode(_current->getNode());
}
itr->second.second->setCamera(_current->getCamera());
itr->second.second->setByMatrix(_current->getMatrix());
}
_current = itr->second.second;
}
}
void KeySwitchCameraManipulator::setNode(osg::Node* node)
void KeySwitchMatrixManipulator::setNode(osg::Node* node)
{
for(KeyManipMap::iterator itr=_manips.begin();
itr!=_manips.end();
@@ -55,21 +54,21 @@ void KeySwitchCameraManipulator::setNode(osg::Node* node)
}
}
CameraManipulator* KeySwitchCameraManipulator::getCameraManipulator(unsigned int num)
MatrixManipulator* KeySwitchMatrixManipulator::getMatrixManipulator(unsigned int num)
{
KeyManipMap::iterator itr = _manips.find(num);
if (itr!=_manips.end()) return itr->second.second.get();
else return 0;
}
const CameraManipulator* KeySwitchCameraManipulator::getCameraManipulator(unsigned int num) const
const MatrixManipulator* KeySwitchMatrixManipulator::getMatrixManipulator(unsigned int num) const
{
KeyManipMap::const_iterator itr = _manips.find(num);
if (itr!=_manips.end()) return itr->second.second.get();
else return 0;
}
bool KeySwitchCameraManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& aa)
bool KeySwitchMatrixManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& aa)
{
if(ea.getEventType()==GUIEventAdapter::KEYDOWN){
@@ -79,7 +78,7 @@ bool KeySwitchCameraManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapt
if ( !it->second.second->getNode() ) {
it->second.second->setNode(_current->getNode());
}
it->second.second->setCamera(_current->getCamera());
it->second.second->setByMatrix(_current->getMatrix());
it->second.second->init(ea,aa);
_current = it->second.second;
@@ -91,7 +90,7 @@ bool KeySwitchCameraManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapt
return _current->handle(ea,aa);
}
void KeySwitchCameraManipulator::getUsage(osg::ApplicationUsage& usage) const
void KeySwitchMatrixManipulator::getUsage(osg::ApplicationUsage& usage) const
{
for(KeyManipMap::const_iterator itr=_manips.begin();
itr!=_manips.end();

View File

@@ -85,7 +85,7 @@ public:
};
Edge() {}
Edge(Vertex_index ib, Vertex_index ie) : ib_(ib), ie_(ie), ibs_(std::min(ib, ie)), ies_(std::max(ib, ie)), duplicate_(false) {}
Edge(Vertex_index ib, Vertex_index ie) : ib_(ib), ie_(ie), ibs_(osg::minimum(ib, ie)), ies_(osg::maximum(ib, ie)), duplicate_(false) {}
// first endpoint
inline Vertex_index ib() const { return ib_; }