mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 13:38:02 +02:00
AnimTests: added tests for accumulateTime
This commit is contained in:
parent
073cec41c4
commit
15f3894001
2 changed files with 90 additions and 2 deletions
|
@ -13,6 +13,7 @@
|
||||||
#include "AnimBlendLinear.h"
|
#include "AnimBlendLinear.h"
|
||||||
#include "AnimationLogging.h"
|
#include "AnimationLogging.h"
|
||||||
#include "AnimVariant.h"
|
#include "AnimVariant.h"
|
||||||
|
#include "AnimUtil.h"
|
||||||
|
|
||||||
#include <../QTestExtensions.h>
|
#include <../QTestExtensions.h>
|
||||||
|
|
||||||
|
@ -73,8 +74,8 @@ void AnimTests::testClipEvaulate() {
|
||||||
|
|
||||||
// does it loop?
|
// does it loop?
|
||||||
triggers.clear();
|
triggers.clear();
|
||||||
clip.evaluate(vars, framesToSec(11.0f), triggers);
|
clip.evaluate(vars, framesToSec(12.0f), triggers);
|
||||||
QCOMPARE_WITH_ABS_ERROR(clip._frame, 3.0f, EPSILON);
|
QCOMPARE_WITH_ABS_ERROR(clip._frame, 3.0f, EPSILON); // Note: frame 3 and not 4, because extra frame between start and end.
|
||||||
|
|
||||||
// did we receive a loop trigger?
|
// did we receive a loop trigger?
|
||||||
QVERIFY(std::find(triggers.begin(), triggers.end(), "myClipNodeOnLoop") != triggers.end());
|
QVERIFY(std::find(triggers.begin(), triggers.end(), "myClipNodeOnLoop") != triggers.end());
|
||||||
|
@ -238,3 +239,87 @@ void AnimTests::testVariant() {
|
||||||
QVERIFY(m[1].z == -7.0f);
|
QVERIFY(m[1].z == -7.0f);
|
||||||
QVERIFY(m[3].w == 16.0f);
|
QVERIFY(m[3].w == 16.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AnimTests::testAccumulateTime() {
|
||||||
|
|
||||||
|
float startFrame = 0.0f;
|
||||||
|
float endFrame = 10.0f;
|
||||||
|
float timeScale = 1.0f;
|
||||||
|
testAccumulateTimeWithParameters(startFrame, endFrame, timeScale);
|
||||||
|
|
||||||
|
startFrame = 5.0f;
|
||||||
|
endFrame = 15.0f;
|
||||||
|
timeScale = 1.0f;
|
||||||
|
testAccumulateTimeWithParameters(startFrame, endFrame, timeScale);
|
||||||
|
|
||||||
|
startFrame = 0.0f;
|
||||||
|
endFrame = 10.0f;
|
||||||
|
timeScale = 0.5f;
|
||||||
|
testAccumulateTimeWithParameters(startFrame, endFrame, timeScale);
|
||||||
|
|
||||||
|
startFrame = 5.0f;
|
||||||
|
endFrame = 15.0f;
|
||||||
|
timeScale = 2.0f;
|
||||||
|
testAccumulateTimeWithParameters(startFrame, endFrame, timeScale);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AnimTests::testAccumulateTimeWithParameters(float startFrame, float endFrame, float timeScale) const {
|
||||||
|
|
||||||
|
float dt = (1.0f / 30.0f) / timeScale; // sec
|
||||||
|
QString id = "testNode";
|
||||||
|
AnimNode::Triggers triggers;
|
||||||
|
bool loopFlag = false;
|
||||||
|
|
||||||
|
float resultFrame = accumulateTime(startFrame, endFrame, timeScale, startFrame, dt, loopFlag, id, triggers);
|
||||||
|
QVERIFY(resultFrame == startFrame + 1.0f);
|
||||||
|
QVERIFY(triggers.empty());
|
||||||
|
triggers.clear();
|
||||||
|
|
||||||
|
resultFrame = accumulateTime(startFrame, endFrame, timeScale, resultFrame, dt, loopFlag, id, triggers);
|
||||||
|
QVERIFY(resultFrame == startFrame + 2.0f);
|
||||||
|
QVERIFY(triggers.empty());
|
||||||
|
triggers.clear();
|
||||||
|
|
||||||
|
resultFrame = accumulateTime(startFrame, endFrame, timeScale, resultFrame, dt, loopFlag, id, triggers);
|
||||||
|
QVERIFY(resultFrame == startFrame + 3.0f);
|
||||||
|
QVERIFY(triggers.empty());
|
||||||
|
triggers.clear();
|
||||||
|
|
||||||
|
// test onDone trigger and frame clamping.
|
||||||
|
resultFrame = accumulateTime(startFrame, endFrame, timeScale, endFrame - 1.0f, dt, loopFlag, id, triggers);
|
||||||
|
QVERIFY(resultFrame == endFrame);
|
||||||
|
QVERIFY(!triggers.empty() && triggers[0] == "testNodeOnDone");
|
||||||
|
triggers.clear();
|
||||||
|
|
||||||
|
resultFrame = accumulateTime(startFrame, endFrame, timeScale, endFrame - 0.5f, dt, loopFlag, id, triggers);
|
||||||
|
QVERIFY(resultFrame == endFrame);
|
||||||
|
QVERIFY(!triggers.empty() && triggers[0] == "testNodeOnDone");
|
||||||
|
triggers.clear();
|
||||||
|
|
||||||
|
// test onLoop trigger and looping frame logic
|
||||||
|
loopFlag = true;
|
||||||
|
|
||||||
|
// should NOT trigger loop even though we stop at last frame, because there is an extra frame between end and start frames.
|
||||||
|
resultFrame = accumulateTime(startFrame, endFrame, timeScale, endFrame - 1.0f, dt, loopFlag, id, triggers);
|
||||||
|
QVERIFY(resultFrame == endFrame);
|
||||||
|
QVERIFY(triggers.empty());
|
||||||
|
triggers.clear();
|
||||||
|
|
||||||
|
// now we should hit loop trigger
|
||||||
|
resultFrame = accumulateTime(startFrame, endFrame, timeScale, resultFrame, dt, loopFlag, id, triggers);
|
||||||
|
QVERIFY(resultFrame == startFrame);
|
||||||
|
QVERIFY(!triggers.empty() && triggers[0] == "testNodeOnLoop");
|
||||||
|
triggers.clear();
|
||||||
|
|
||||||
|
// should NOT trigger loop, even though we move past the end frame, because of extra frame between end and start.
|
||||||
|
resultFrame = accumulateTime(startFrame, endFrame, timeScale, endFrame - 0.5f, dt, loopFlag, id, triggers);
|
||||||
|
QVERIFY(resultFrame == endFrame + 0.5f);
|
||||||
|
QVERIFY(triggers.empty());
|
||||||
|
triggers.clear();
|
||||||
|
|
||||||
|
// now we should hit loop trigger
|
||||||
|
resultFrame = accumulateTime(startFrame, endFrame, timeScale, resultFrame, dt, loopFlag, id, triggers);
|
||||||
|
QVERIFY(resultFrame == startFrame + 0.5f);
|
||||||
|
QVERIFY(!triggers.empty() && triggers[0] == "testNodeOnLoop");
|
||||||
|
triggers.clear();
|
||||||
|
}
|
||||||
|
|
|
@ -15,6 +15,8 @@
|
||||||
|
|
||||||
class AnimTests : public QObject {
|
class AnimTests : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
void testAccumulateTimeWithParameters(float startFrame, float endFrame, float timeScale) const;
|
||||||
private slots:
|
private slots:
|
||||||
void initTestCase();
|
void initTestCase();
|
||||||
void cleanupTestCase();
|
void cleanupTestCase();
|
||||||
|
@ -23,6 +25,7 @@ private slots:
|
||||||
void testClipEvaulateWithVars();
|
void testClipEvaulateWithVars();
|
||||||
void testLoader();
|
void testLoader();
|
||||||
void testVariant();
|
void testVariant();
|
||||||
|
void testAccumulateTime();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_AnimTests_h
|
#endif // hifi_AnimTests_h
|
||||||
|
|
Loading…
Reference in a new issue