From Jean-Sebastien Guay, "I changed osgGA::StateSetManipulator to mirror the

osgViewer::StatsHandler and other handlers which allow you to change the
key(s) you would press to get them to do something. Pretty simple change
but useful in our context and possibly in others too."
This commit is contained in:
Robert Osfield 2008-03-05 11:33:55 +00:00
parent bc406c8bf0
commit 6e89dc0d94
2 changed files with 43 additions and 39 deletions

View File

@ -69,6 +69,19 @@ public:
void cyclePolygonMode();
void setKeyEventToggleBackfaceCulling(int key) { _keyEventToggleBackfaceCulling = key; }
int getKeyEventToggleBackfaceCulling() const { return _keyEventToggleBackfaceCulling; }
void setKeyEventToggleLighting(int key) { _keyEventToggleLighting = key; }
int getKeyEventToggleLighting() const { return _keyEventToggleLighting; }
void setKeyEventToggleTexturing(int key) { _keyEventToggleTexturing = key; }
int getKeyEventToggleTexturing() const { return _keyEventToggleTexturing; }
void setKeyEventCyclePolygonMode(int key) { _keyEventCyclePolygonMode = key; }
int getKeyEventCyclePolygonMode() const { return _keyEventCyclePolygonMode; }
protected:
virtual ~StateSetManipulator();
@ -81,6 +94,11 @@ protected:
bool _texture;
unsigned int _maxNumOfTextureUnits;
int _keyEventToggleBackfaceCulling;
int _keyEventToggleLighting;
int _keyEventToggleTexturing;
int _keyEventCyclePolygonMode;
osg::PolygonMode* getOrCreatePolygonMode();
};

View File

@ -21,7 +21,11 @@ StateSetManipulator::StateSetManipulator(osg::StateSet* stateset):
_backface(false),
_lighting(false),
_texture(false),
_maxNumOfTextureUnits(4)
_maxNumOfTextureUnits(4),
_keyEventToggleBackfaceCulling('b'),
_keyEventToggleLighting('l'),
_keyEventToggleTexturing('t'),
_keyEventCyclePolygonMode('w')
{
setStateSet(stateset);
}
@ -72,62 +76,44 @@ bool StateSetManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& aa)
if (ea.getHandled()) return false;
if(ea.getEventType()==GUIEventAdapter::KEYDOWN)
if (ea.getEventType()==osgGA::GUIEventAdapter::KEYDOWN)
{
switch( ea.getKey() )
if ( ea.getKey() == _keyEventToggleBackfaceCulling )
{
setBackfaceEnabled(!getBackfaceEnabled());
aa.requestRedraw();
return true;
}
if ( ea.getKey() == _keyEventToggleLighting )
{
case 'b' :
setBackfaceEnabled(!getBackfaceEnabled());
aa.requestRedraw();
return true;
break;
case 'l' :
setLightingEnabled(!getLightingEnabled());
aa.requestRedraw();
return true;
break;
case 't' :
}
if ( ea.getKey() == _keyEventToggleTexturing )
{
setTextureEnabled(!getTextureEnabled());
aa.requestRedraw();
return true;
break;
case 'w' :
}
if ( ea.getKey() == _keyEventCyclePolygonMode )
{
cyclePolygonMode();
aa.requestRedraw();
break;
#if COMPILE_TEXENVFILTER_USAGE
case 'm' :
{
osg::TexEnvFilter* texenvfilter = dynamic_cast<osg::TexEnvFilter*>(_stateset->getTextureAttribute(0,osg::StateAttribute::TEXENVFILTER));
if (!texenvfilter)
{
texenvfilter = new osg::TexEnvFilter;
_stateset->setTextureAttribute(0,texenvfilter);
}
// cycle through the available modes.
texenvfilter->setLodBias(texenvfilter->getLodBias()+0.1);
aa.requestRedraw();
}
break;
#endif
return true;
}
}
return false;
}
void StateSetManipulator::getUsage(osg::ApplicationUsage& usage) const
{
usage.addKeyboardMouseBinding("b","Toggle backface culling");
usage.addKeyboardMouseBinding("l","Toggle lighting");
usage.addKeyboardMouseBinding("t","Toggle texturing");
usage.addKeyboardMouseBinding("w","Toggle polygon fill mode between fill, line (wire frame) and points");
usage.addKeyboardMouseBinding(reinterpret_cast<const char*>(&_keyEventToggleBackfaceCulling),"Toggle backface culling");
usage.addKeyboardMouseBinding(reinterpret_cast<const char*>(&_keyEventToggleLighting),"Toggle lighting");
usage.addKeyboardMouseBinding(reinterpret_cast<const char*>(&_keyEventToggleTexturing),"Toggle texturing");
usage.addKeyboardMouseBinding(reinterpret_cast<const char*>(&_keyEventCyclePolygonMode),"Toggle polygon fill mode between fill, line (wire frame) and points");
}