diff options
author | Paul Lemire <paul.lemire@kdab.com> | 2021-11-23 09:27:43 +0100 |
---|---|---|
committer | Paul Lemire <paul.lemire@kdab.com> | 2021-11-24 07:26:04 +0100 |
commit | 7b23cb1ca5b32fcf24f889e79cec756786f86233 (patch) | |
tree | 0485822aaf98eb8b953b74896d13c01d9479de7e | |
parent | 34c37671d63da2a195fee34b5a6409294b19d510 (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
Pick-to: 6.2 5.15
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
-rw-r--r-- | src/animation/backend/animationclip.cpp | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/animation/backend/animationclip.cpp b/src/animation/backend/animationclip.cpp index d4a1f133a..24b41a50f 100644 --- a/src/animation/backend/animationclip.cpp +++ b/src/animation/backend/animationclip.cpp @@ -358,14 +358,17 @@ float AnimationClip::findDuration() { // Iterate over the contained fcurves and find the longest one 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() |