From 5c030413f3c6d42f82941d26addb39da0c30006f Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 12 Jan 2007 11:38:24 +0000 Subject: [PATCH] Added osgGA Trackball, Flight and Drive camera manipulators, and StateSetManipulator to the osgViewer path in osgviewer --- applications/osgviewer/osgviewer.cpp | 36 +++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/applications/osgviewer/osgviewer.cpp b/applications/osgviewer/osgviewer.cpp index 4a19d8052..56955dcc7 100644 --- a/applications/osgviewer/osgviewer.cpp +++ b/applications/osgviewer/osgviewer.cpp @@ -13,6 +13,10 @@ #include #include +/////////////////////////////////////////////////////////////////////////// +// +// osgProducer version (see osgViewer version in next section below) + #include int main_osgProducer(osg::ArgumentParser& arguments) { @@ -124,12 +128,42 @@ int main_osgProducer(osg::ArgumentParser& arguments) return 0; } +/////////////////////////////////////////////////////////////////////////// +// +// osgViewer version + #include +#include +#include +#include +#include +#include + + int main_osgViewer(osg::ArgumentParser& arguments) { osgViewer::Viewer viewer; - viewer.setSceneData( osgDB::readNodeFiles(arguments)); + // set up 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() ); + + viewer.setCameraManipulator( keyswitchManipulator.get() ); + } + + // add the state manipulator + { + osg::ref_ptr statesetManipulator = new osgGA::StateSetManipulator; + statesetManipulator->setStateSet(viewer.getCamera()->getOrCreateStateSet()); + + viewer.addEventHandler( statesetManipulator.get() ); + } + + viewer.setSceneData( osgDB::readNodeFiles(arguments) ); return viewer.run(); }