From 31e526f25345bf90467a5ea6a151bef0a8bd9919 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 29 Mar 2010 08:49:20 +0000 Subject: [PATCH] Added TerainHandler event handler to provide 'v'/'V' and 'r'/'R' key controls for change vertical scale and sample ratio respectively. --- examples/osgterrain/osgterrain.cpp | 55 ++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/examples/osgterrain/osgterrain.cpp b/examples/osgterrain/osgterrain.cpp index c2f4a9a36..dd52dac85 100644 --- a/examples/osgterrain/osgterrain.cpp +++ b/examples/osgterrain/osgterrain.cpp @@ -73,6 +73,58 @@ T* findTopMostNodeOfType(osg::Node* node) return fnotv._foundNode; } +// class to handle events with a pick +class TerrainHandler : public osgGA::GUIEventHandler { +public: + + TerrainHandler(osgTerrain::Terrain* terrain): + _terrain(terrain) {} + + bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa) + { + switch(ea.getEventType()) + { + case(osgGA::GUIEventAdapter::KEYDOWN): + { + if (ea.getKey()=='r') + { + _terrain->setSampleRatio(_terrain->getSampleRatio()*0.5); + osg::notify(osg::NOTICE)<<"Sample ratio "<<_terrain->getSampleRatio()<setSampleRatio(_terrain->getSampleRatio()/0.5); + osg::notify(osg::NOTICE)<<"Sample ratio "<<_terrain->getSampleRatio()<setVerticalScale(_terrain->getVerticalScale()*1.25); + osg::notify(osg::NOTICE)<<"Vertical scale "<<_terrain->getVerticalScale()<setVerticalScale(_terrain->getVerticalScale()/1.25); + osg::notify(osg::NOTICE)<<"Vertical scale "<<_terrain->getVerticalScale()< _terrain; +}; + int main(int argc, char** argv) { osg::ArgumentParser arguments(&argc, argv); @@ -156,6 +208,9 @@ int main(int argc, char** argv) terrain->setVerticalScale(verticalScale); terrain->setBlendingPolicy(blendingPolicy); + // register our custom handler for adjust Terrain settings + viewer.addEventHandler(new TerrainHandler(terrain)); + // add a viewport to the viewer and attach the scene graph. viewer.setSceneData( rootnode );