|
class KeySwitchManipulatorExt:public osgGA::KeySwitchMatrixManipulator
{
public:
virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& us);
private:
osg::Vec3f eye;
osg::Vec3f center;
osg::Vec3f up;
};
bool KeySwitchManipulatorExt::handle(const GUIEventAdapter& ea,GUIActionAdapter& us)
{
bool resu=false;
osgViewer::View* view=dynamic_cast<osgViewer::View*>(&us);
if (!ea.getHandled()&&ea.getEventType()==GUIEventAdapter:EFT_MOUSE_BUTTON||ea.getEventType()==GUIEventAdapter::MOVE)
{
std::string str=getCurrentMatrixManipulator()->className();
if ("Trackball"==str)
{
view->getCamera()->getViewMatrixAsLookAt(eye,center,up);
}
}
resu=KeySwitchMatrixManipulator::handle(ea,us);
if (ea.getEventType()==GUIEventAdapter::KEYDOWN)
{
std::string str1=getCurrentMatrixManipulator()->className();
if ("Terrain"==str1)
{
view->getCamera()->setViewMatrixAsLookAt(eye,center,up);
}
}
return resu;
}
这是我重写keyswitchmatrixmanipulator的handle函数,我想当控制器是Trackball时,记录当前相机视点位置,切换到Terrain控制器时不要改变相机视点的位置,但是这样做仍然无效,相机的位置还是会回到原来Terrain控制器时的那个位置,这是什么原因? |
|