From 1ad9979cea96e1317dfe2beaff0eaa4352750e6a Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 25 Aug 2011 15:39:09 +0000 Subject: [PATCH] Added event handling for toggling on/off the light source animation. --- examples/osgshadow/osgshadow.cpp | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/examples/osgshadow/osgshadow.cpp b/examples/osgshadow/osgshadow.cpp index 16074100d..1a62e82ea 100644 --- a/examples/osgshadow/osgshadow.cpp +++ b/examples/osgshadow/osgshadow.cpp @@ -138,6 +138,33 @@ public: }; +class LightAnimationHandler : public osgGA::GUIEventHandler +{ +public: + LightAnimationHandler(bool flag=true): _animating(flag) {} + + void setAnimating(bool flag) { _animating = flag; } + bool getAnimating() const { return _animating; } + + /** Deprecated, Handle events, return true if handled, false otherwise. */ + virtual bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa) + { + if (ea.getEventType() == osgGA::GUIEventAdapter::KEYUP) + { + if (ea.getKey() == 'p' ) + { + _animating = !_animating; + return true; + } + } + + return false; + } + + bool _animating; +}; + + static int ReceivesShadowTraversalMask = 0x1; static int CastsShadowTraversalMask = 0x2; @@ -973,6 +1000,9 @@ int main(int argc, char** argv) } } + osg::ref_ptr lightAnimationHandler = updateLightPosition ? new LightAnimationHandler : 0; + if (lightAnimationHandler) viewer.addEventHandler(lightAnimationHandler.get()); + // osgDB::writeNodeFile(*group,"test.osgt"); @@ -1002,7 +1032,7 @@ int main(int argc, char** argv) } } - if (updateLightPosition) + if (lightAnimationHandler.valid() && lightAnimationHandler ->getAnimating()) { float t = viewer.getFrameStamp()->getSimulationTime();