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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-17 18:00:50 +08:00
|
|
|
void KeySwitchCameraManipulator::addNumberedCameraManipulator(CameraManipulator *cm)
|
|
|
|
{
|
|
|
|
if(!cm) return;
|
|
|
|
addCameraManipulator('1'+_manips.size(),"camera",cm);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-05-09 18:31:03 +08:00
|
|
|
bool KeySwitchCameraManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& aa)
|
|
|
|
{
|
|
|
|
if(ea.getEventType()==GUIEventAdapter::KEYBOARD){
|
|
|
|
|
|
|
|
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;
|
2002-05-10 06:48:15 +08:00
|
|
|
std::cout<<"***Switching to manipulator: "<<(*it).second.first<<std::endl;
|
2002-05-09 18:31:03 +08:00
|
|
|
it->second.second->setNode(_current->getNode());
|
|
|
|
it->second.second->setCamera(_current->getCamera());
|
|
|
|
it->second.second->init(ea,aa);
|
|
|
|
_current = it->second.second;
|
|
|
|
|
|
|
|
//_cameraManipChangeCallbacks.notify(this);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return _current->handle(ea,aa);
|
|
|
|
}
|
|
|
|
|
|
|
|
// void KeySwitchCameraManipulator::addCallback(Callback* c)
|
|
|
|
// {
|
|
|
|
// _cameraManipChangeCallbacks.addCallback(c);
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// void KeySwitchCameraManipulator::removeCallback(Callback* c)
|
|
|
|
// {
|
|
|
|
// _cameraManipChangeCallbacks.removeCallback(c);
|
|
|
|
// }
|