diff --git a/include/osgGA/AnimationPathManipulator b/include/osgGA/AnimationPathManipulator index 303b89bf2..c01d0cfd0 100644 --- a/include/osgGA/AnimationPathManipulator +++ b/include/osgGA/AnimationPathManipulator @@ -41,6 +41,21 @@ class OSGGA_EXPORT AnimationPathManipulator : public CameraManipulator virtual const char* className() const { return "AnimationPath"; } + void setTimeScale(double s) { _timeScale = s; } + double getTimeScale() const { return _timeScale; } + + void setTimeOffset(double o) { _timeOffset = o; } + double getTimeOffset() const { return _timeOffset; } + + struct AnimationCompletedCallback : public virtual osg::Referenced + { + virtual void completed(const AnimationPathManipulator* apm) = 0; + }; + + void setAnimationCompletedCallback(AnimationCompletedCallback* acc) { _animationCompletedCallback = acc; } + AnimationCompletedCallback* getAnimationCompletedCallback() { return _animationCompletedCallback.get(); } + const AnimationCompletedCallback* getAnimationCompletedCallback() const { return _animationCompletedCallback.get(); } + void setPrintOutTimingInfo(bool printOutTimingInfo) { _printOutTimingInfo=printOutTimingInfo; } bool getPrintOutTimingInfo() const { return _printOutTimingInfo; } @@ -87,6 +102,9 @@ class OSGGA_EXPORT AnimationPathManipulator : public CameraManipulator double _timeOffset; double _timeScale; + + osg::ref_ptr _animationCompletedCallback; + double _pauseTime; bool _isPaused; diff --git a/src/osgGA/AnimationPathManipulator.cpp b/src/osgGA/AnimationPathManipulator.cpp index c870f3769..d29f52ee9 100644 --- a/src/osgGA/AnimationPathManipulator.cpp +++ b/src/osgGA/AnimationPathManipulator.cpp @@ -24,8 +24,8 @@ AnimationPathManipulator::AnimationPathManipulator( const std::string& filename _animationPath = new osg::AnimationPath; _animationPath->setLoopMode(osg::AnimationPath::LOOP); - _timeOffset = 0.0f; - _timeScale = 1.0f; + _timeOffset = 0.0; + _timeScale = 1.0; _isPaused = false; @@ -85,7 +85,6 @@ bool AnimationPathManipulator::handle(const osgGA::GUIEventAdapter& ea,osgGA::GU if (ea.getKey()==' ') { _isPaused = false; - _timeScale = 1.0; home(ea,us); us.requestRedraw(); @@ -149,45 +148,47 @@ void AnimationPathManipulator::getUsage(osg::ApplicationUsage& usage) const { usage.addKeyboardMouseBinding("AnimationPath: Space","Reset the viewing position to start of animation"); usage.addKeyboardMouseBinding("AnimationPath: p","Pause/resume animation."); - usage.addKeyboardMouseBinding("AnimationPath: <","Slow down animation speed."); - usage.addKeyboardMouseBinding("AnimationPath: <","Speed up animation speed."); + usage.addKeyboardMouseBinding("AnimationPath: (","Slow down animation speed."); + usage.addKeyboardMouseBinding("AnimationPath: )","Speed up animation speed."); } void AnimationPathManipulator::handleFrame( double time ) { osg::AnimationPath::ControlPoint cp; - + double animTime = (time+_timeOffset)*_timeScale; _animationPath->getInterpolatedControlPoint( animTime, cp ); if (_numOfFramesSinceStartOfTimedPeriod==-1) - { + { _realStartOfTimedPeriod = time; _animStartOfTimedPeriod = animTime; } - + ++_numOfFramesSinceStartOfTimedPeriod; - - if (_printOutTimingInfo) + + double animDelta = (animTime-_animStartOfTimedPeriod); + if (animDelta>=_animationPath->getPeriod()) { - double animDelta = (animTime-_animStartOfTimedPeriod); - if (animDelta>=_animationPath->getPeriod()) + if (_animationCompletedCallback.valid()) { + _animationCompletedCallback->completed(this); + } + if (_printOutTimingInfo) + { double delta = time-_realStartOfTimedPeriod; - double frameRate = (double)_numOfFramesSinceStartOfTimedPeriod/delta; OSG_NOTICE <<"AnimatonPath completed in "<