2002-05-09 18:31:03 +08:00
|
|
|
#include <osgGA/KeySwitchCameraManipulator>
|
|
|
|
#include <osg/Notify>
|
|
|
|
|
|
|
|
using namespace osgGA;
|
|
|
|
|
|
|
|
void KeySwitchCameraManipulator::addCameraManipulator(int key, std::string name, CameraManipulator *cm)
|
|
|
|
{
|
|
|
|
if(!cm) return;
|
|
|
|
|
|
|
|
_manips[key]=std::make_pair(name,osg::ref_ptr<CameraManipulator>(cm));
|
|
|
|
if(!_current.valid()){
|
|
|
|
_current=cm;
|
2003-01-20 19:52:34 +08:00
|
|
|
_current->setNode(_current->getNode());
|
|
|
|
_current->setCamera(_current->getCamera());
|
2002-05-09 18:31:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-17 18:00:50 +08:00
|
|
|
void KeySwitchCameraManipulator::addNumberedCameraManipulator(CameraManipulator *cm)
|
|
|
|
{
|
|
|
|
if(!cm) return;
|
2003-02-19 18:43:02 +08:00
|
|
|
addCameraManipulator('1'+_manips.size(),cm->className(),cm);
|
2002-07-17 18:00:50 +08:00
|
|
|
}
|
|
|
|
|
2003-01-22 23:30:17 +08:00
|
|
|
void KeySwitchCameraManipulator::selectCameraManipulator(unsigned int num)
|
|
|
|
{
|
|
|
|
unsigned int manipNo = 0;
|
|
|
|
KeyManipMap::iterator itr;
|
|
|
|
for(itr=_manips.begin();
|
|
|
|
manipNo!=num && itr!=_manips.end();
|
|
|
|
++itr,++manipNo)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
if (itr!=_manips.end())
|
|
|
|
{
|
|
|
|
if (_current.valid())
|
|
|
|
{
|
2003-04-08 21:10:47 +08:00
|
|
|
if ( !itr->second.second->getNode() ) {
|
|
|
|
itr->second.second->setNode(_current->getNode());
|
|
|
|
}
|
2003-01-22 23:30:17 +08:00
|
|
|
itr->second.second->setCamera(_current->getCamera());
|
|
|
|
}
|
|
|
|
_current = itr->second.second;
|
|
|
|
}
|
|
|
|
}
|
2002-07-17 18:00:50 +08:00
|
|
|
|
2003-04-08 21:10:47 +08:00
|
|
|
void KeySwitchCameraManipulator::setNode(osg::Node* node)
|
|
|
|
{
|
|
|
|
for(KeyManipMap::iterator itr=_manips.begin();
|
|
|
|
itr!=_manips.end();
|
|
|
|
++itr)
|
|
|
|
{
|
|
|
|
|
|
|
|
itr->second.second->setNode(node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-20 05:14:50 +08:00
|
|
|
CameraManipulator* KeySwitchCameraManipulator::getCameraManipulator(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
|
|
|
|
{
|
|
|
|
KeyManipMap::const_iterator itr = _manips.find(num);
|
|
|
|
if (itr!=_manips.end()) return itr->second.second.get();
|
|
|
|
else return 0;
|
|
|
|
}
|
|
|
|
|
2002-05-09 18:31:03 +08:00
|
|
|
bool KeySwitchCameraManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& aa)
|
|
|
|
{
|
2003-01-14 22:25:56 +08:00
|
|
|
if(ea.getEventType()==GUIEventAdapter::KEYDOWN){
|
2002-05-09 18:31:03 +08:00
|
|
|
|
|
|
|
KeyManipMap::iterator it=_manips.find(ea.getKey());
|
|
|
|
if(it != _manips.end()){
|
2002-05-10 03:02:35 +08:00
|
|
|
osg::notify(osg::INFO)<<"Switching to manipulator: "<<(*it).second.first<<std::endl;
|
2003-04-08 21:10:47 +08:00
|
|
|
if ( !it->second.second->getNode() ) {
|
|
|
|
it->second.second->setNode(_current->getNode());
|
|
|
|
}
|
2002-05-09 18:31:03 +08:00
|
|
|
it->second.second->setCamera(_current->getCamera());
|
|
|
|
it->second.second->init(ea,aa);
|
|
|
|
_current = it->second.second;
|
|
|
|
|
|
|
|
//_cameraManipChangeCallbacks.notify(this);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return _current->handle(ea,aa);
|
|
|
|
}
|
2003-02-19 18:43:02 +08:00
|
|
|
|
|
|
|
void KeySwitchCameraManipulator::getUsage(osg::ApplicationUsage& usage) const
|
|
|
|
{
|
|
|
|
for(KeyManipMap::const_iterator itr=_manips.begin();
|
|
|
|
itr!=_manips.end();
|
|
|
|
++itr)
|
|
|
|
{
|
2003-02-20 05:37:12 +08:00
|
|
|
std::string key; key += (char)(itr->first);
|
|
|
|
std::string explanation(std::string("Select '")+itr->second.first+std::string("' camera manipulator"));
|
2003-02-19 18:43:02 +08:00
|
|
|
if (_current==itr->second.second) explanation += " (default)";
|
|
|
|
|
|
|
|
usage.addKeyboardMouseBinding(key,explanation);
|
|
|
|
itr->second.second->getUsage(usage);
|
|
|
|
}
|
|
|
|
}
|