summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/animation/backend/animationutils.cpp9
-rw-r--r--src/animation/backend/animationutils_p.h5
-rw-r--r--tests/auto/animation/animationutils/tst_animationutils.cpp165
3 files changed, 179 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 &currentLoop)
+{
+ 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 &currentLoop);
+Q_AUTOTEST_EXPORT
+double phaseFromGlobalTime(double t_global, double t_start_global,
+ double playbackRate, double duration,
+ int loopCount, int &currentLoop);
+
} // Animation
} // Qt3DAnimation
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");