Added AnimationCompletedCallback, s/getTimeScale and s/getTimeOffset() method to enable finer control of AnimationPathManipulator.
This commit is contained in:
parent
65f95fe3fe
commit
3580108b3a
@ -41,6 +41,21 @@ class OSGGA_EXPORT AnimationPathManipulator : public CameraManipulator
|
|||||||
|
|
||||||
virtual const char* className() const { return "AnimationPath"; }
|
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; }
|
void setPrintOutTimingInfo(bool printOutTimingInfo) { _printOutTimingInfo=printOutTimingInfo; }
|
||||||
bool getPrintOutTimingInfo() const { return _printOutTimingInfo; }
|
bool getPrintOutTimingInfo() const { return _printOutTimingInfo; }
|
||||||
|
|
||||||
@ -87,6 +102,9 @@ class OSGGA_EXPORT AnimationPathManipulator : public CameraManipulator
|
|||||||
|
|
||||||
double _timeOffset;
|
double _timeOffset;
|
||||||
double _timeScale;
|
double _timeScale;
|
||||||
|
|
||||||
|
osg::ref_ptr<AnimationCompletedCallback> _animationCompletedCallback;
|
||||||
|
|
||||||
double _pauseTime;
|
double _pauseTime;
|
||||||
bool _isPaused;
|
bool _isPaused;
|
||||||
|
|
||||||
|
@ -24,8 +24,8 @@ AnimationPathManipulator::AnimationPathManipulator( const std::string& filename
|
|||||||
|
|
||||||
_animationPath = new osg::AnimationPath;
|
_animationPath = new osg::AnimationPath;
|
||||||
_animationPath->setLoopMode(osg::AnimationPath::LOOP);
|
_animationPath->setLoopMode(osg::AnimationPath::LOOP);
|
||||||
_timeOffset = 0.0f;
|
_timeOffset = 0.0;
|
||||||
_timeScale = 1.0f;
|
_timeScale = 1.0;
|
||||||
_isPaused = false;
|
_isPaused = false;
|
||||||
|
|
||||||
|
|
||||||
@ -85,7 +85,6 @@ bool AnimationPathManipulator::handle(const osgGA::GUIEventAdapter& ea,osgGA::GU
|
|||||||
if (ea.getKey()==' ')
|
if (ea.getKey()==' ')
|
||||||
{
|
{
|
||||||
_isPaused = false;
|
_isPaused = false;
|
||||||
_timeScale = 1.0;
|
|
||||||
|
|
||||||
home(ea,us);
|
home(ea,us);
|
||||||
us.requestRedraw();
|
us.requestRedraw();
|
||||||
@ -149,8 +148,8 @@ void AnimationPathManipulator::getUsage(osg::ApplicationUsage& usage) const
|
|||||||
{
|
{
|
||||||
usage.addKeyboardMouseBinding("AnimationPath: Space","Reset the viewing position to start of animation");
|
usage.addKeyboardMouseBinding("AnimationPath: Space","Reset the viewing position to start of animation");
|
||||||
usage.addKeyboardMouseBinding("AnimationPath: p","Pause/resume animation.");
|
usage.addKeyboardMouseBinding("AnimationPath: p","Pause/resume animation.");
|
||||||
usage.addKeyboardMouseBinding("AnimationPath: <","Slow down animation speed.");
|
usage.addKeyboardMouseBinding("AnimationPath: (","Slow down animation speed.");
|
||||||
usage.addKeyboardMouseBinding("AnimationPath: <","Speed up animation speed.");
|
usage.addKeyboardMouseBinding("AnimationPath: )","Speed up animation speed.");
|
||||||
}
|
}
|
||||||
|
|
||||||
void AnimationPathManipulator::handleFrame( double time )
|
void AnimationPathManipulator::handleFrame( double time )
|
||||||
@ -169,25 +168,27 @@ void AnimationPathManipulator::handleFrame( double time )
|
|||||||
|
|
||||||
++_numOfFramesSinceStartOfTimedPeriod;
|
++_numOfFramesSinceStartOfTimedPeriod;
|
||||||
|
|
||||||
if (_printOutTimingInfo)
|
|
||||||
{
|
|
||||||
double animDelta = (animTime-_animStartOfTimedPeriod);
|
double animDelta = (animTime-_animStartOfTimedPeriod);
|
||||||
if (animDelta>=_animationPath->getPeriod())
|
if (animDelta>=_animationPath->getPeriod())
|
||||||
{
|
{
|
||||||
|
if (_animationCompletedCallback.valid())
|
||||||
|
{
|
||||||
|
_animationCompletedCallback->completed(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_printOutTimingInfo)
|
||||||
|
{
|
||||||
double delta = time-_realStartOfTimedPeriod;
|
double delta = time-_realStartOfTimedPeriod;
|
||||||
|
|
||||||
double frameRate = (double)_numOfFramesSinceStartOfTimedPeriod/delta;
|
double frameRate = (double)_numOfFramesSinceStartOfTimedPeriod/delta;
|
||||||
OSG_NOTICE <<"AnimatonPath completed in "<<delta<<" seconds, completing "<<_numOfFramesSinceStartOfTimedPeriod<<" frames,"<<std::endl;
|
OSG_NOTICE <<"AnimatonPath completed in "<<delta<<" seconds, completing "<<_numOfFramesSinceStartOfTimedPeriod<<" frames,"<<std::endl;
|
||||||
OSG_NOTICE <<" average frame rate = "<<frameRate<<std::endl;
|
OSG_NOTICE <<" average frame rate = "<<frameRate<<std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
// reset counters for next loop.
|
// reset counters for next loop.
|
||||||
_realStartOfTimedPeriod = time;
|
_realStartOfTimedPeriod = time;
|
||||||
_animStartOfTimedPeriod = animTime;
|
_animStartOfTimedPeriod = animTime;
|
||||||
|
|
||||||
_numOfFramesSinceStartOfTimedPeriod = 0;
|
_numOfFramesSinceStartOfTimedPeriod = 0;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
cp.getMatrix( _matrix );
|
cp.getMatrix( _matrix );
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user