From 15e5bdbcaefaaa5db317275a4638e0354f6b83b1 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 9 Jul 2008 19:28:00 +0000 Subject: [PATCH] Added range of camera manipulators and a center of screen test intersection that is insticated by pressing 'c' key --- examples/osgpick/osgpick.cpp | 53 ++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/examples/osgpick/osgpick.cpp b/examples/osgpick/osgpick.cpp index c829ff4f6..4322d197d 100644 --- a/examples/osgpick/osgpick.cpp +++ b/examples/osgpick/osgpick.cpp @@ -26,6 +26,17 @@ #include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + #include #include #include @@ -72,6 +83,18 @@ bool PickHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapte if (view) pick(view,ea); return false; } + case(osgGA::GUIEventAdapter::KEYDOWN): + { + if (ea.getKey()=='c') + { + osgViewer::View* view = dynamic_cast(&aa); + osg::ref_ptr event = new osgGA::GUIEventAdapter(ea); + event->setX((ea.getXmin()+ea.getXmax())*0.5); + event->setY((ea.getYmin()+ea.getYmax())*0.5); + if (view) pick(view,*event); + } + return false; + } default: return false; } @@ -255,6 +278,36 @@ int main( int argc, char **argv ) { osgViewer::Viewer viewer; + + // add all the camera manipulators + { + osg::ref_ptr keyswitchManipulator = new osgGA::KeySwitchMatrixManipulator; + + keyswitchManipulator->addMatrixManipulator( '1', "Trackball", new osgGA::TrackballManipulator() ); + keyswitchManipulator->addMatrixManipulator( '2', "Flight", new osgGA::FlightManipulator() ); + keyswitchManipulator->addMatrixManipulator( '3', "Drive", new osgGA::DriveManipulator() ); + + unsigned int num = keyswitchManipulator->getNumMatrixManipulators(); + keyswitchManipulator->addMatrixManipulator( '4', "Terrain", new osgGA::TerrainManipulator() ); + + std::string pathfile; + char keyForAnimationPath = '5'; + while (arguments.read("-p",pathfile)) + { + osgGA::AnimationPathManipulator* apm = new osgGA::AnimationPathManipulator(pathfile); + if (apm || !apm->valid()) + { + num = keyswitchManipulator->getNumMatrixManipulators(); + keyswitchManipulator->addMatrixManipulator( keyForAnimationPath, "Path", apm ); + ++keyForAnimationPath; + } + } + + keyswitchManipulator->selectMatrixManipulator(num); + + viewer.setCameraManipulator( keyswitchManipulator.get() ); + } + // add the handler for doing the picking viewer.addEventHandler(new PickHandler(updateText.get()));