Skip to content
Snippets Groups Projects
Commit 4cf58fb3 authored by Joseph Mirabel's avatar Joseph Mirabel Committed by Joseph Mirabel
Browse files

Fix camera motion and zoom via shortcut z and Z

parent af06ed6b
No related branches found
No related tags found
No related merge requests found
......@@ -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,
......
......@@ -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)
);
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment