diff options
author | Paul Lemire <paul.lemire@kdab.com> | 2020-03-27 11:47:20 +0100 |
---|---|---|
committer | Paul Lemire <paul.lemire@kdab.com> | 2020-03-30 07:27:33 +0100 |
commit | 08281b3661547688b19cdaa52d5cf7bbdc171f56 (patch) | |
tree | 7dc52b973bad09f909912baf939765bf0b24ecc4 /src/animation | |
parent | 62d11afb41e0c3b8a21b4a307cebdfc406ecdf98 (diff) |
Properly stop running animations when using a negative playrate
When reaching a normalized time of 0 they would otherwise continue
to run
Change-Id: Idaea755d3a12f9c9da9c25732c2221e9b3f9f4c7
Reviewed-by: Mike Krus <mike.krus@kdab.com>
Diffstat (limited to 'src/animation')
-rw-r--r-- | src/animation/backend/animationutils.cpp | 8 | ||||
-rw-r--r-- | src/animation/backend/animationutils_p.h | 12 | ||||
-rw-r--r-- | src/animation/backend/evaluateblendclipanimatorjob.cpp | 2 | ||||
-rw-r--r-- | src/animation/frontend/qclock.cpp | 5 |
4 files changed, 18 insertions, 9 deletions
diff --git a/src/animation/backend/animationutils.cpp b/src/animation/backend/animationutils.cpp index 3f386d92a..a5656e230 100644 --- a/src/animation/backend/animationutils.cpp +++ b/src/animation/backend/animationutils.cpp @@ -80,7 +80,8 @@ ClipEvaluationData evaluationDataForClip(AnimationClip *clip, animatorData.playbackRate, clip->duration(), animatorData.loopCount, result.currentLoop); result.isFinalFrame = isFinalFrame(result.localTime, clip->duration(), - result.currentLoop, animatorData.loopCount); + result.currentLoop, animatorData.loopCount, + animatorData.playbackRate); const bool hasNormalizedTime = isValidNormalizedTime(animatorData.normalizedLocalTime); result.normalizedLocalTime = hasNormalizedTime ? animatorData.normalizedLocalTime : result.localTime / clip->duration(); @@ -112,9 +113,10 @@ double localTimeFromElapsedTime(double t_current_local, t_local = std::fmod(t_local, duration); // Ensure we clamp to end of final loop - if (int(loopNumber) == loopCount) { + + if (int(loopNumber) == loopCount || int(loopNumber) < 0) { loopNumber = loopCount - 1; - t_local = duration; + t_local = playbackRate >= 0.0 ? duration : 0.0; } } diff --git a/src/animation/backend/animationutils_p.h b/src/animation/backend/animationutils_p.h index 8c71e704a..0501d9598 100644 --- a/src/animation/backend/animationutils_p.h +++ b/src/animation/backend/animationutils_p.h @@ -318,11 +318,15 @@ AnimatorEvaluationData evaluationDataForAnimator(Animator animator, inline bool isFinalFrame(double localTime, double duration, int currentLoop, - int loopCount) + int loopCount, + double playbackRate) { - return (localTime >= duration && - loopCount != 0 && - currentLoop >= loopCount - 1); + // We must be on the final loop and + // - if playing forward, localTime must be equal or above the duration + // - if playing backward, localTime must be equal or below 0 + if (playbackRate >= 0.0) + return (loopCount != 0 && currentLoop >= loopCount - 1 && localTime >= duration); + return (loopCount != 0 && currentLoop <= 0 && localTime <= 0); } inline bool isValidNormalizedTime(float t) diff --git a/src/animation/backend/evaluateblendclipanimatorjob.cpp b/src/animation/backend/evaluateblendclipanimatorjob.cpp index 765531902..8a5f1e533 100644 --- a/src/animation/backend/evaluateblendclipanimatorjob.cpp +++ b/src/animation/backend/evaluateblendclipanimatorjob.cpp @@ -129,7 +129,7 @@ void EvaluateBlendClipAnimatorJob::run() blendedClipAnimator->setCurrentLoop(animatorData.currentLoop); // Prepare the change record - const bool finalFrame = isFinalFrame(localTime, duration, animatorData.currentLoop, animatorData.loopCount); + const bool finalFrame = isFinalFrame(localTime, duration, animatorData.currentLoop, animatorData.loopCount, animatorData.playbackRate); const QVector<MappingData> mappingData = blendedClipAnimator->mappingData(); auto record = prepareAnimationRecord(blendedClipAnimator->peerId(), mappingData, diff --git a/src/animation/frontend/qclock.cpp b/src/animation/frontend/qclock.cpp index f38c21807..519edd388 100644 --- a/src/animation/frontend/qclock.cpp +++ b/src/animation/frontend/qclock.cpp @@ -63,7 +63,10 @@ QClock::~QClock() /*! \property Qt3DAnimation::QClock::playbackRate - The playback speed of the animation. + The playback speed of the animation. The playback speed can be negative. + When that is the case the animation will be played back from the current + normalized time value back to 0 and for the number of loops it had been + played for with a positive playback rate. */ double QClock::playbackRate() const |