diff options
author | Paul Lemire <paul.lemire@kdab.com> | 2021-11-23 09:27:43 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-11-24 08:08:47 +0000 |
commit | c9bc7eda384e108441e5a99dc54d7ef99f4fba90 (patch) | |
tree | 749177fb7f8f2ed6d94d1d9a0c3626d1269bbc5a | |
parent | dd85de4bd493b332fb0b4f2b04625c6ab2227b91 (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: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-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() |