summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire@kdab.com>2021-11-23 09:27:43 +0100
committerPaul Lemire <paul.lemire@kdab.com>2021-11-24 08:31:00 +0000
commite34fd22bab044c1a9eb1bbed8206bfa9afee5a9e (patch)
treec629a30e36925060fbcaa71d92808da0f29e5778
parentfdba23fe5ed5eb87a6bab7bc16d04b7e240a4d7e (diff)
AnimationClip: fix the way we compute the duration
We wrongly assumed the start time of a clip was always 0. In practice this might not be the case. Therefore, we now compute duration as tEnd - tStart. Change-Id: I13ca860f3366c2aba5e978cb0c955e7bb2e7bc39 Reviewed-by: Sean Harmer <sean.harmer@kdab.com> (cherry picked from commit 7b23cb1ca5b32fcf24f889e79cec756786f86233) Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
-rw-r--r--src/animation/backend/animationclip.cpp13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/animation/backend/animationclip.cpp b/src/animation/backend/animationclip.cpp
index a95e14d74..f051d68d9 100644
--- a/src/animation/backend/animationclip.cpp
+++ b/src/animation/backend/animationclip.cpp
@@ -354,15 +354,18 @@ void AnimationClip::clearData()
float AnimationClip::findDuration()
{
// Iterate over the contained fcurves and find the longest one
- double tMax = 0.0;
+ float tMax = 0.f;
+ float tMin = 1.0f;
for (const Channel &channel : qAsConst(m_channels)) {
for (const ChannelComponent &channelComponent : qAsConst(channel.channelComponents)) {
- const float t = channelComponent.fcurve.endTime();
- if (t > tMax)
- tMax = t;
+ const float tStart = channelComponent.fcurve.startTime();
+ const float tEnd = channelComponent.fcurve.endTime();
+ tMax = std::max(tEnd, tMax);
+ tMin = std::min(tStart, tMin);
}
}
- return tMax;
+ // We can't have a negative duration
+ return std::max(tMax - tMin, 0.0f);
}
int AnimationClip::findChannelComponentCount()