summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorSean Harmer <sean.harmer@kdab.com>2017-03-15 10:13:00 +0000
committerSean Harmer <sean.harmer@kdab.com>2017-03-19 12:45:12 +0000
commitfb44c0de7226a41c400c73fe33009b0d46f806d3 (patch)
tree3d74a55b91a4a2e2c3382c055657007116d8d05f /tests
parentfd39bbaca2fe8e29bb9b603340ed94c7480b6da5 (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 'tests')
-rw-r--r--tests/auto/animation/animationutils/tst_animationutils.cpp165
1 files changed, 165 insertions, 0 deletions
diff --git a/tests/auto/animation/animationutils/tst_animationutils.cpp b/tests/auto/animation/animationutils/tst_animationutils.cpp
index 7600f4d91..c19be320c 100644
--- a/tests/auto/animation/animationutils/tst_animationutils.cpp
+++ b/tests/auto/animation/animationutils/tst_animationutils.cpp
@@ -360,6 +360,171 @@ private Q_SLOTS:
QCOMPARE(actualLocalTime, expectedLocalTime);
}
+ void checkPhaseFromGlobalTime_data()
+ {
+ QTest::addColumn<double>("globalTime");
+ QTest::addColumn<double>("globalStartTime");
+ QTest::addColumn<double>("playbackRate");
+ QTest::addColumn<double>("duration");
+ QTest::addColumn<int>("loopCount");
+ QTest::addColumn<double>("expectedPhase");
+ QTest::addColumn<int>("expectedCurrentLoop");
+
+ double globalTime;
+ double globalStartTime;
+ double playbackRate;
+ double duration;
+ int loopCount;
+ double expectedPhase;
+ int expectedCurrentLoop;
+
+ globalTime = 0.0;
+ globalStartTime = 0.0;
+ playbackRate = 1.0;
+ duration = 1.0;
+ loopCount = 1;
+ expectedPhase = 0.0;
+ expectedCurrentLoop = 0;
+ QTest::newRow("simple, t_global = 0")
+ << globalTime << globalStartTime << playbackRate << duration << loopCount
+ << expectedPhase << expectedCurrentLoop;
+
+ globalTime = 0.5;
+ globalStartTime = 0.0;
+ playbackRate = 1.0;
+ duration = 1.0;
+ loopCount = 1;
+ expectedPhase = 0.5;
+ expectedCurrentLoop = 0;
+ QTest::newRow("simple, t_global = 0.5")
+ << globalTime << globalStartTime << playbackRate << duration << loopCount
+ << expectedPhase << expectedCurrentLoop;
+
+ globalTime = 1.0;
+ globalStartTime = 0.0;
+ playbackRate = 1.0;
+ duration = 1.0;
+ loopCount = 1;
+ expectedPhase = 1.0;
+ expectedCurrentLoop = 0;
+ QTest::newRow("simple, t_global = 1.0")
+ << globalTime << globalStartTime << playbackRate << duration << loopCount
+ << expectedPhase << expectedCurrentLoop;
+
+ globalTime = -0.5;
+ globalStartTime = 0.0;
+ playbackRate = 1.0;
+ duration = 1.0;
+ loopCount = 1;
+ expectedPhase = 0.0;
+ expectedCurrentLoop = 0;
+ QTest::newRow("simple, t_global = -0.5")
+ << globalTime << globalStartTime << playbackRate << duration << loopCount
+ << expectedPhase << expectedCurrentLoop;
+
+ globalTime = 1.5;
+ globalStartTime = 0.0;
+ playbackRate = 1.0;
+ duration = 1.0;
+ loopCount = 1;
+ expectedPhase = 1.0;
+ expectedCurrentLoop = 0;
+ QTest::newRow("simple, t_global = 1.5")
+ << globalTime << globalStartTime << playbackRate << duration << loopCount
+ << expectedPhase << expectedCurrentLoop;
+
+ globalTime = 0.5;
+ globalStartTime = 0.0;
+ playbackRate = 1.0;
+ duration = 1.0;
+ loopCount = 2;
+ expectedPhase = 0.5;
+ expectedCurrentLoop = 0;
+ QTest::newRow("simple, loopCount = 2, t_global = 0.5")
+ << globalTime << globalStartTime << playbackRate << duration << loopCount
+ << expectedPhase << expectedCurrentLoop;
+
+ globalTime = 1.5;
+ globalStartTime = 0.0;
+ playbackRate = 1.0;
+ duration = 1.0;
+ loopCount = 2;
+ expectedPhase = 0.5;
+ expectedCurrentLoop = 1;
+ QTest::newRow("simple, loopCount = 2, t_global = 1.5")
+ << globalTime << globalStartTime << playbackRate << duration << loopCount
+ << expectedPhase << expectedCurrentLoop;
+
+ globalTime = 3.5;
+ globalStartTime = 0.0;
+ playbackRate = 1.0;
+ duration = 2.0;
+ loopCount = 2;
+ expectedPhase = 0.75;
+ expectedCurrentLoop = 1;
+ QTest::newRow("duration = 2, loopCount = 2, t_global = 3.5")
+ << globalTime << globalStartTime << playbackRate << duration << loopCount
+ << expectedPhase << expectedCurrentLoop;
+
+ globalTime = 4.5;
+ globalStartTime = 0.0;
+ playbackRate = 1.0;
+ duration = 2.0;
+ loopCount = 2;
+ expectedPhase = 1.0;
+ expectedCurrentLoop = 1;
+ QTest::newRow("duration = 2, loopCount = 2, t_global = 4.5")
+ << globalTime << globalStartTime << playbackRate << duration << loopCount
+ << expectedPhase << expectedCurrentLoop;
+
+ globalTime = 1.5;
+ globalStartTime = 0.0;
+ playbackRate = 1.0;
+ duration = 1.0;
+ loopCount = 0;
+ expectedPhase = 0.5;
+ expectedCurrentLoop = 1;
+ QTest::newRow("simple, loopCount = inf, t_global = 1.5")
+ << globalTime << globalStartTime << playbackRate << duration << loopCount
+ << expectedPhase << expectedCurrentLoop;
+
+ globalTime = 10.2;
+ globalStartTime = 0.0;
+ playbackRate = 1.0;
+ duration = 1.0;
+ loopCount = 0;
+ expectedPhase = 0.2;
+ expectedCurrentLoop = 10;
+ QTest::newRow("simple, loopCount = inf, t_global = 10.2")
+ << globalTime << globalStartTime << playbackRate << duration << loopCount
+ << expectedPhase << expectedCurrentLoop;
+ }
+
+ void checkPhaseFromGlobalTime()
+ {
+ // GIVEN
+ QFETCH(double, globalTime);
+ QFETCH(double, globalStartTime);
+ QFETCH(double, playbackRate);
+ QFETCH(double, duration);
+ QFETCH(int, loopCount);
+ QFETCH(double, expectedPhase);
+ QFETCH(int, expectedCurrentLoop);
+
+ // WHEN
+ int actualCurrentLoop = 0;
+ double actualPhase = phaseFromGlobalTime(globalTime,
+ globalStartTime,
+ playbackRate,
+ duration,
+ loopCount,
+ actualCurrentLoop);
+
+ // THEN
+ QCOMPARE(actualCurrentLoop, expectedCurrentLoop);
+ QCOMPARE(actualPhase, expectedPhase);
+ }
+
void checkPreparePropertyChanges_data()
{
QTest::addColumn<Qt3DCore::QNodeId>("animatorId");