From ca513efc1d2acd339580efbaa7c85dcac8e6a5fb Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 28 Feb 2008 20:02:43 +0000 Subject: [PATCH] Added LODScaleHandler --- applications/osgviewer/osgviewer.cpp | 3 ++ include/osgViewer/ViewerEventHandlers | 37 ++++++++++++++--- src/osgViewer/ViewerEventHandlers.cpp | 59 +++++++++++++++++++++++++++ 3 files changed, 94 insertions(+), 5 deletions(-) diff --git a/applications/osgviewer/osgviewer.cpp b/applications/osgviewer/osgviewer.cpp index 7e99a2a49..e3730c600 100644 --- a/applications/osgviewer/osgviewer.cpp +++ b/applications/osgviewer/osgviewer.cpp @@ -118,6 +118,9 @@ int main(int argc, char** argv) // add the record camera path handler viewer.addEventHandler(new osgViewer::RecordCameraPathHandler); + // add the LOD Scale handler + viewer.addEventHandler(new osgViewer::LODScaleHandler); + // load the data osg::ref_ptr loadedModel = osgDB::readNodeFiles(arguments); if (!loadedModel) diff --git a/include/osgViewer/ViewerEventHandlers b/include/osgViewer/ViewerEventHandlers index f8ebbd5cd..34c764809 100644 --- a/include/osgViewer/ViewerEventHandlers +++ b/include/osgViewer/ViewerEventHandlers @@ -216,11 +216,11 @@ protected: }; /** -Event handler allowing the user to record the animation "path" of a camera. In it's current -implementation, this handler cannot guarantee the final view matrix is correct; it is -conceivable that the matrix may be one frame off. Eh--not a big deal! :) -TODO: Write the file as we go, not when it's all done. -TODO: Create an osgviewer on-screen indication that animation is taking place. + * Event handler allowing the user to record the animation "path" of a camera. In it's current + * implementation, this handler cannot guarantee the final view matrix is correct; it is + * conceivable that the matrix may be one frame off. Eh--not a big deal! :) + * TODO: Write the file as we go, not when it's all done. + * TODO: Create an osgviewer on-screen indication that animation is taking place. */ class OSGVIEWER_EXPORT RecordCameraPathHandler : public osgGA::GUIEventHandler { @@ -257,6 +257,33 @@ protected: osg::ref_ptr _oldManipulator; }; +/** Event handler for increase/decreasing LODScale.*/ +class OSGVIEWER_EXPORT LODScaleHandler : public osgGA::GUIEventHandler +{ + public: + + LODScaleHandler(); + + void setKeyEventIncreaseLODScale(int key) { _keyEventIncreaseLODScale = key; } + int getKeyEventIncreaseLODScale() const { return _keyEventIncreaseLODScale; } + + void setKeyEventDecreaseLODScale(int key) { _keyEventDecreaseLODScale = key; } + int getKeyEventDecreaseLODScale() const { return _keyEventDecreaseLODScale; } + + bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa); + + /** Get the keyboard and mouse usage of this manipulator.*/ + virtual void getUsage(osg::ApplicationUsage& usage) const; + + protected: + + + int _keyEventIncreaseLODScale; + int _keyEventDecreaseLODScale; + + +}; + } #endif diff --git a/src/osgViewer/ViewerEventHandlers.cpp b/src/osgViewer/ViewerEventHandlers.cpp index a079f3888..148101613 100644 --- a/src/osgViewer/ViewerEventHandlers.cpp +++ b/src/osgViewer/ViewerEventHandlers.cpp @@ -15,6 +15,8 @@ #include #include +#include + #include #include @@ -515,4 +517,61 @@ bool RecordCameraPathHandler::handle(const osgGA::GUIEventAdapter &ea, osgGA::GU return false; } +LODScaleHandler::LODScaleHandler(): + _keyEventIncreaseLODScale('*'), + _keyEventDecreaseLODScale('/') +{ +} + +bool LODScaleHandler::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa) +{ + osgViewer::View* view = dynamic_cast(&aa); + osg::Camera* camera = view ? view->getCamera() : 0; + if (!camera) return false; + + if (ea.getHandled()) return false; + + switch(ea.getEventType()) + { + case(osgGA::GUIEventAdapter::KEYUP): + { + if (ea.getKey() == _keyEventIncreaseLODScale) + { + camera->setLODScale(camera->getLODScale()*1.1); + osg::notify(osg::NOTICE)<<"LODScale = "<getLODScale()<setLODScale(camera->getLODScale()/1.1); + osg::notify(osg::NOTICE)<<"LODScale = "<getLODScale()<