From 22cf4c18c338f2ae6bbaae31f1e699f6413cde6c Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 23 Jan 2015 13:50:12 +0000 Subject: [PATCH] Added MultiTextureControl event handling of shift 012 i.e. ')', '!', '"' and 'A' to toggle full on for each of the respective or all texture units. git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk@14674 16af8721-9629-0410-8352-f15c8da7e697 --- examples/osgterrain/CMakeLists.txt | 2 +- examples/osgterrain/osgterrain.cpp | 53 +++++++++++++++++++++++++++--- 2 files changed, 49 insertions(+), 6 deletions(-) diff --git a/examples/osgterrain/CMakeLists.txt b/examples/osgterrain/CMakeLists.txt index a942afd07..89b723654 100644 --- a/examples/osgterrain/CMakeLists.txt +++ b/examples/osgterrain/CMakeLists.txt @@ -2,7 +2,7 @@ SET(TARGET_SRC osgterrain.cpp ) -SET(TARGET_ADDED_LIBRARIES osgTerrain ) +SET(TARGET_ADDED_LIBRARIES osgTerrain osgFX) #### end var setup ### SETUP_EXAMPLE(osgterrain) diff --git a/examples/osgterrain/osgterrain.cpp b/examples/osgterrain/osgterrain.cpp index 625bc269e..bc160fba2 100644 --- a/examples/osgterrain/osgterrain.cpp +++ b/examples/osgterrain/osgterrain.cpp @@ -36,6 +36,8 @@ #include #include +#include + #include @@ -79,8 +81,9 @@ T* findTopMostNodeOfType(osg::Node* node) class TerrainHandler : public osgGA::GUIEventHandler { public: - TerrainHandler(osgTerrain::Terrain* terrain): - _terrain(terrain) {} + TerrainHandler(osgTerrain::Terrain* terrain, osgFX::MultiTextureControl* mtc): + _terrain(terrain), + _mtc(mtc) {} bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa) { @@ -112,6 +115,26 @@ public: osg::notify(osg::NOTICE)<<"Vertical scale "<<_terrain->getVerticalScale()< _terrain; -}; + void assignTextureWeightToSingleTextureUnit(unsigned int unit) + { + if (!_mtc) return; + for(unsigned int i=0; i<_mtc->getNumTextureWeights(); ++i) + { + _mtc->setTextureWeight(i, (i==unit) ? 1.0f : 0.0f); + } + } + void assignedToAll() + { + if (!_mtc && _mtc->getNumTextureWeights()>0) return; + float div = 1.0f/static_cast(_mtc->getNumTextureWeights()); + for(unsigned int i=0; i<_mtc->getNumTextureWeights(); ++i) + { + _mtc->setTextureWeight(i, div); + } + } + + osg::ref_ptr _terrain; + osg::ref_ptr _mtc; +}; class CleanTechniqueReadFileCallback : public osgDB::ReadFileCallback { @@ -285,6 +327,7 @@ int main(int argc, char** argv) terrain->setVerticalScale(verticalScale); terrain->setBlendingPolicy(blendingPolicy); + if (useDisplacementMappingTechnique) { terrain->setTerrainTechniquePrototype(new osgTerrain::DisplacementMappingTechnique()); @@ -292,7 +335,7 @@ int main(int argc, char** argv) // register our custom handler for adjust Terrain settings - viewer.addEventHandler(new TerrainHandler(terrain.get())); + viewer.addEventHandler(new TerrainHandler(terrain.get(), findTopMostNodeOfType(rootnode.get()))); // add a viewport to the viewer and attach the scene graph. viewer.setSceneData( rootnode.get() );