diff --git a/include/gepetto/gui/pick-handler.hh b/include/gepetto/gui/pick-handler.hh index 429f5635db0c19605a3bb741e3cb8c5ed03d2df0..2d5f1b2efd4f8dbc467be4615cbcb24df48c0b57 100644 --- a/include/gepetto/gui/pick-handler.hh +++ b/include/gepetto/gui/pick-handler.hh @@ -24,7 +24,7 @@ namespace gepetto { virtual bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa ); - void getUsage (osg::ApplicationUsage &usage); + void getUsage (osg::ApplicationUsage &usage) const; private: std::list <graphics::NodePtr_t> computeIntersection (osgGA::GUIActionAdapter& aa, diff --git a/src/gui/pick-handler.cc b/src/gui/pick-handler.cc index 786a40660ea9b8280eb67d3223189cfe1206b876..453abf70647cd65dc3eb586b93e1426e4975fa4f 100644 --- a/src/gui/pick-handler.cc +++ b/src/gui/pick-handler.cc @@ -6,6 +6,8 @@ #include <osgUtil/IntersectionVisitor> #include <osgUtil/LineSegmentIntersector> +#include <osgGA/TrackballManipulator> +#include <osgGA/KeySwitchMatrixManipulator> #include <osgViewer/Viewer> @@ -76,7 +78,7 @@ namespace gepetto { return false; } - void PickHandler::getUsage (osg::ApplicationUsage& usage) + void PickHandler::getUsage (osg::ApplicationUsage& usage) const { usage.addKeyboardMouseBinding ("Right click", "Select node"); usage.addKeyboardMouseBinding ('z', "Move camera on selected node"); @@ -147,13 +149,29 @@ namespace gepetto { osg::Vec3f eye, center, up; viewer->getCameraManipulator()->getInverseMatrix () .getLookAt (eye, center, up); - if (zoom) { - eye.normalize(); - eye *= 1 + bs.radius (); + + osgGA::TrackballManipulator* tbm = dynamic_cast<osgGA::TrackballManipulator*>(viewer->getCameraManipulator()); + if (!tbm) { + osgGA::KeySwitchMatrixManipulator* ksm = dynamic_cast<osgGA::KeySwitchMatrixManipulator*>(viewer->getCameraManipulator()); + if (ksm) { + tbm = dynamic_cast<osgGA::TrackballManipulator*>(ksm->getCurrentMatrixManipulator()); + } + } + if (tbm) { + tbm->setCenter(bs.center()); + if (zoom) tbm->setDistance(3 * bs.radius()); + } else { + if (zoom) { + osg::Vec3f tmp = center - eye; + tmp.normalize(); + eye = bs.center() - tmp * 3 * bs.radius(); + } else { + eye += bs.center() - center; + } + viewer->getCameraManipulator()->setByInverseMatrix ( + osg::Matrixd::lookAt (eye, bs.center(), up) + ); } - viewer->getCameraManipulator()->setByInverseMatrix ( - osg::Matrixd::lookAt (eye, bs.center(), up) - ); } } }