Added support for CompositeViewer to WindowSizeHandler, ThreadingHandler, RecordCameraPathManipulator and HelpHandler.

This commit is contained in:
Robert Osfield 2007-09-30 19:27:31 +00:00
parent 4cf73d4c87
commit 48f19b72bd
2 changed files with 39 additions and 26 deletions

View File

@ -148,9 +148,7 @@ int main( int argc, char **argv )
osgViewer::View* view = new osgViewer::View; osgViewer::View* view = new osgViewer::View;
view->setSceneData(osgDB::readNodeFile("fountain.osg")); view->setSceneData(osgDB::readNodeFile("fountain.osg"));
osg::ref_ptr<osgViewer::StatsHandler> statsHandler = new osgViewer::StatsHandler; view->addEventHandler( new osgViewer::StatsHandler );
view->addEventHandler( statsHandler.get() );
view->setUpViewAcrossAllScreens(); view->setUpViewAcrossAllScreens();
view->setCameraManipulator(new osgGA::TrackballManipulator); view->setCameraManipulator(new osgGA::TrackballManipulator);
@ -186,8 +184,7 @@ int main( int argc, char **argv )
view->setSceneData(scene.get()); view->setSceneData(scene.get());
view->setCameraManipulator(new osgGA::TrackballManipulator); view->setCameraManipulator(new osgGA::TrackballManipulator);
osg::ref_ptr<osgViewer::StatsHandler> statsHandler = new osgViewer::StatsHandler; view->addEventHandler( new osgViewer::StatsHandler );
view->addEventHandler( statsHandler.get() );
// add the handler for doing the picking // add the handler for doing the picking
@ -251,6 +248,9 @@ int main( int argc, char **argv )
view->addEventHandler( new osgViewer::StatsHandler ); view->addEventHandler( new osgViewer::StatsHandler );
view->addEventHandler( new osgViewer::HelpHandler ); view->addEventHandler( new osgViewer::HelpHandler );
view->addEventHandler( new osgViewer::WindowSizeHandler );
view->addEventHandler( new osgViewer::ThreadingHandler );
view->addEventHandler( new osgViewer::RecordCameraPathHandler );
} }
// view two // view two

View File

@ -62,7 +62,10 @@ void WindowSizeHandler::getUsage(osg::ApplicationUsage &usage) const
bool WindowSizeHandler::handle(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa) bool WindowSizeHandler::handle(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa)
{ {
osgViewer::Viewer *viewer = dynamic_cast<osgViewer::Viewer *>(&aa); osgViewer::View* view = dynamic_cast<osgViewer::View*>(&aa);
if (!view) return false;
osgViewer::ViewerBase* viewer = view->getViewerBase();
if (viewer == NULL) if (viewer == NULL)
{ {
@ -282,9 +285,13 @@ void ThreadingHandler::getUsage(osg::ApplicationUsage &usage) const
bool ThreadingHandler::handle(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa) bool ThreadingHandler::handle(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa)
{ {
osgViewer::Viewer *viewer = dynamic_cast<osgViewer::Viewer*>(&aa); osgViewer::View* view = dynamic_cast<osgViewer::View*>(&aa);
if (!view) return false;
if (viewer == NULL) osgViewer::ViewerBase* viewerBase = view->getViewerBase();
osgViewer::Viewer* viewer = dynamic_cast<Viewer*>(viewerBase);
if (viewerBase == NULL)
{ {
return false; return false;
} }
@ -301,32 +308,38 @@ bool ThreadingHandler::handle(const osgGA::GUIEventAdapter &ea, osgGA::GUIAction
{ {
_tickOrLastKeyPress = osg::Timer::instance()->tick(); _tickOrLastKeyPress = osg::Timer::instance()->tick();
switch(viewer->getThreadingModel()) switch(viewerBase->getThreadingModel())
{ {
case(osgViewer::Viewer::SingleThreaded): case(osgViewer::ViewerBase::SingleThreaded):
viewer->setThreadingModel(osgViewer::Viewer::CullDrawThreadPerContext); viewerBase->setThreadingModel(osgViewer::ViewerBase::CullDrawThreadPerContext);
osg::notify(osg::NOTICE)<<"Threading model 'CullDrawThreadPerContext' selected."<<std::endl; osg::notify(osg::NOTICE)<<"Threading model 'CullDrawThreadPerContext' selected."<<std::endl;
break; break;
case(osgViewer::Viewer::CullDrawThreadPerContext): case(osgViewer::ViewerBase::CullDrawThreadPerContext):
viewer->setThreadingModel(osgViewer::Viewer::DrawThreadPerContext); viewerBase->setThreadingModel(osgViewer::ViewerBase::DrawThreadPerContext);
osg::notify(osg::NOTICE)<<"Threading model 'DrawThreadPerContext' selected."<<std::endl; osg::notify(osg::NOTICE)<<"Threading model 'DrawThreadPerContext' selected."<<std::endl;
break; break;
case(osgViewer::Viewer::DrawThreadPerContext): case(osgViewer::ViewerBase::DrawThreadPerContext):
viewer->setThreadingModel(osgViewer::Viewer::CullThreadPerCameraDrawThreadPerContext); viewerBase->setThreadingModel(osgViewer::ViewerBase::CullThreadPerCameraDrawThreadPerContext);
osg::notify(osg::NOTICE)<<"Threading model 'CullThreadPerCameraDrawThreadPerContext' selected."<<std::endl; osg::notify(osg::NOTICE)<<"Threading model 'CullThreadPerCameraDrawThreadPerContext' selected."<<std::endl;
break; break;
case(osgViewer::Viewer::CullThreadPerCameraDrawThreadPerContext): case(osgViewer::ViewerBase::CullThreadPerCameraDrawThreadPerContext):
viewer->setThreadingModel(osgViewer::Viewer::SingleThreaded); viewerBase->setThreadingModel(osgViewer::ViewerBase::SingleThreaded);
osg::notify(osg::NOTICE)<<"Threading model 'SingleThreaded' selected."<<std::endl; osg::notify(osg::NOTICE)<<"Threading model 'SingleThreaded' selected."<<std::endl;
break; break;
case(osgViewer::Viewer::AutomaticSelection): #if 1
viewer->setThreadingModel(viewer->suggestBestThreadingModel()); case(osgViewer::ViewerBase::AutomaticSelection):
viewerBase->setThreadingModel(osgViewer::ViewerBase::SingleThreaded);
osg::notify(osg::NOTICE)<<"Threading model 'AutomaticSelection' selected."<<std::endl; osg::notify(osg::NOTICE)<<"Threading model 'AutomaticSelection' selected."<<std::endl;
#else
case(osgViewer::ViewerBase::AutomaticSelection):
viewerBase->setThreadingModel(viewer->suggestBestThreadingModel());
osg::notify(osg::NOTICE)<<"Threading model 'AutomaticSelection' selected."<<std::endl;
#endif
break; break;
} }
return true; return true;
} }
if (_changeEndBarrierPosition == true && ea.getKey() == _keyEventChangeEndBarrierPosition) if (viewer && _changeEndBarrierPosition == true && ea.getKey() == _keyEventChangeEndBarrierPosition)
{ {
switch(viewer->getEndBarrierPosition()) switch(viewer->getEndBarrierPosition())
{ {
@ -376,9 +389,9 @@ void RecordCameraPathHandler::getUsage(osg::ApplicationUsage &usage) const
bool RecordCameraPathHandler::handle(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa) bool RecordCameraPathHandler::handle(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &aa)
{ {
osgViewer::Viewer* viewer = dynamic_cast<osgViewer::Viewer*>(&aa); osgViewer::View* view = dynamic_cast<osgViewer::View*>(&aa);
if (viewer == NULL) if (view == NULL)
{ {
return false; return false;
} }
@ -396,7 +409,7 @@ bool RecordCameraPathHandler::handle(const osgGA::GUIEventAdapter &ea, osgGA::GU
// calculating when the next insert should happen. // calculating when the next insert should happen.
if (_currentlyRecording && _delta >= _interval) if (_currentlyRecording && _delta >= _interval)
{ {
const osg::Matrixd& m = viewer->getCamera()->getInverseViewMatrix(); const osg::Matrixd& m = view->getCamera()->getInverseViewMatrix();
_animPath->insert(osg::Timer::instance()->delta_s(_animStartTime, time), osg::AnimationPath::ControlPoint(m.getTrans(), m.getRotate())); _animPath->insert(osg::Timer::instance()->delta_s(_animStartTime, time), osg::AnimationPath::ControlPoint(m.getTrans(), m.getRotate()));
_delta = 0.0f; _delta = 0.0f;
} }
@ -474,8 +487,8 @@ bool RecordCameraPathHandler::handle(const osgGA::GUIEventAdapter &ea, osgGA::GU
// around of the original MatrixManipulator to restore later. // around of the original MatrixManipulator to restore later.
if (_animPathManipulator.valid() && _animPathManipulator->valid()) if (_animPathManipulator.valid() && _animPathManipulator->valid())
{ {
_oldManipulator = viewer->getCameraManipulator(); _oldManipulator = view->getCameraManipulator();
viewer->setCameraManipulator(_animPathManipulator.get()); view->setCameraManipulator(_animPathManipulator.get());
_currentlyPlaying = true; _currentlyPlaying = true;
} }
} }
@ -484,7 +497,7 @@ bool RecordCameraPathHandler::handle(const osgGA::GUIEventAdapter &ea, osgGA::GU
else else
{ {
// Restore the old manipulator if necessary and stop playback. // Restore the old manipulator if necessary and stop playback.
if(_oldManipulator.valid()) viewer->setCameraManipulator(_oldManipulator.get()); if(_oldManipulator.valid()) view->setCameraManipulator(_oldManipulator.get());
_currentlyPlaying = false; _currentlyPlaying = false;
_oldManipulator = 0; _oldManipulator = 0;
} }