diff options
author | Sean Harmer <sean.harmer@kdab.com> | 2017-03-15 10:13:00 +0000 |
---|---|---|
committer | Sean Harmer <sean.harmer@kdab.com> | 2017-03-19 12:45:12 +0000 |
commit | fb44c0de7226a41c400c73fe33009b0d46f806d3 (patch) | |
tree | 3d74a55b91a4a2e2c3382c055657007116d8d05f /src/animation | |
parent | fd39bbaca2fe8e29bb9b603340ed94c7480b6da5 (diff) |
Add function to calculate phase of animation from global time
When we come to evaluate animation blend trees, the resulting
duration of the blend tree will also be blended. This means that we
can't just map from global time to local time of each leaf node clip.
Instead we need to evaluate the clips at a consistent phase. This way
we can safely blend a 3 second walk animation cycle with a 2 second
run animation cycle safely. So long as the animator lines up the
foot falls at consistent phases.
We will therefore need to be able to calculate the phase from the
current global time and the blend tree's duration before we can
eventually evaluate the clips at the phase.
Change-Id: I7bce231cdc2eee8cb873f2c98c6c8c2e05533c8c
Reviewed-by: Mike Krus <mike.krus@kdab.com>
Diffstat (limited to 'src/animation')
-rw-r--r-- | src/animation/backend/animationutils.cpp | 9 | ||||
-rw-r--r-- | src/animation/backend/animationutils_p.h | 5 |
2 files changed, 14 insertions, 0 deletions
diff --git a/src/animation/backend/animationutils.cpp b/src/animation/backend/animationutils.cpp index 5474e5ab0..8ded15a78 100644 --- a/src/animation/backend/animationutils.cpp +++ b/src/animation/backend/animationutils.cpp @@ -103,6 +103,15 @@ double localTimeFromGlobalTime(double t_global, return t_local; } +double phaseFromGlobalTime(double t_global, double t_start_global, + double playbackRate, double duration, + int loopCount, int ¤tLoop) +{ + const double t_local = localTimeFromGlobalTime(t_global, t_start_global, playbackRate, + duration, loopCount, currentLoop); + return t_local / duration; +} + QVector<int> channelComponentsToIndices(const Channel &channel, int dataType, int offset) { #if defined Q_COMPILER_UNIFORM_INIT diff --git a/src/animation/backend/animationutils_p.h b/src/animation/backend/animationutils_p.h index d3a6a3902..25cf651d6 100644 --- a/src/animation/backend/animationutils_p.h +++ b/src/animation/backend/animationutils_p.h @@ -146,6 +146,11 @@ double localTimeFromGlobalTime(double t_global, double t_start_global, double playbackRate, double duration, int loopCount, int ¤tLoop); +Q_AUTOTEST_EXPORT +double phaseFromGlobalTime(double t_global, double t_start_global, + double playbackRate, double duration, + int loopCount, int ¤tLoop); + } // Animation } // Qt3DAnimation |