Added LODScaleHandler

This commit is contained in:
Robert Osfield
2008-02-28 20:02:43 +00:00
parent 1dfffc0494
commit ca513efc1d
3 changed files with 94 additions and 5 deletions

View File

@@ -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<osg::Node> loadedModel = osgDB::readNodeFiles(arguments);
if (!loadedModel)

View File

@@ -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<osgGA::MatrixManipulator> _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

View File

@@ -15,6 +15,8 @@
#include <float.h>
#include <fstream>
#include <sstream>
#include <osgViewer/Viewer>
#include <osgViewer/ViewerEventHandlers>
@@ -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<osgViewer::View*>(&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 = "<<camera->getLODScale()<<std::endl;
return true;
}
else if (ea.getKey() == _keyEventDecreaseLODScale)
{
camera->setLODScale(camera->getLODScale()/1.1);
osg::notify(osg::NOTICE)<<"LODScale = "<<camera->getLODScale()<<std::endl;
return true;
}
break;
}
default:
break;
}
return false;
}
void LODScaleHandler::getUsage(osg::ApplicationUsage& usage) const
{
{
std::ostringstream ostr;
ostr<<char(_keyEventIncreaseLODScale);
usage.addKeyboardMouseBinding(ostr.str(),"Increase LODScale.");
}
{
std::ostringstream ostr;
ostr<<char(_keyEventDecreaseLODScale);
usage.addKeyboardMouseBinding(ostr.str(),"Decrease LODScale.");
}
}
}