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
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -36,6 +36,8 @@
|
||||
#include <osgTerrain/DisplacementMappingTechnique>
|
||||
#include <osgTerrain/Layer>
|
||||
|
||||
#include <osgFX/MultiTextureControl>
|
||||
|
||||
|
||||
#include <iostream>
|
||||
|
||||
@@ -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()<<std::endl;
|
||||
return true;
|
||||
}
|
||||
else if (ea.getKey()=='!') // shift 1
|
||||
{
|
||||
assignTextureWeightToSingleTextureUnit(1);
|
||||
return true;
|
||||
}
|
||||
else if (ea.getKey()=='"') // shift 1
|
||||
{
|
||||
assignTextureWeightToSingleTextureUnit(2);
|
||||
return true;
|
||||
}
|
||||
else if (ea.getKey()==')') // shift 1
|
||||
{
|
||||
assignTextureWeightToSingleTextureUnit(0);
|
||||
return true;
|
||||
}
|
||||
else if (ea.getKey()=='A')
|
||||
{
|
||||
assignedToAll();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -124,9 +147,28 @@ protected:
|
||||
|
||||
~TerrainHandler() {}
|
||||
|
||||
osg::ref_ptr<osgTerrain::Terrain> _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<float>(_mtc->getNumTextureWeights());
|
||||
for(unsigned int i=0; i<_mtc->getNumTextureWeights(); ++i)
|
||||
{
|
||||
_mtc->setTextureWeight(i, div);
|
||||
}
|
||||
}
|
||||
|
||||
osg::ref_ptr<osgTerrain::Terrain> _terrain;
|
||||
osg::ref_ptr<osgFX::MultiTextureControl> _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<osgFX::MultiTextureControl>(rootnode.get())));
|
||||
|
||||
// add a viewport to the viewer and attach the scene graph.
|
||||
viewer.setSceneData( rootnode.get() );
|
||||
|
||||
Reference in New Issue
Block a user