Merge pull request #5801 from AndrewMeadows/fix-animation-tests

fix animation unit tests
This commit is contained in:
Clément Brisset 2015-09-15 17:53:06 +02:00
commit cb1b70820a
4 changed files with 26 additions and 11 deletions

View file

@ -72,7 +72,7 @@ SwingTwistConstraint::SwingTwistConstraint() :
_swingLimitFunction(), _swingLimitFunction(),
_minTwist(-PI), _minTwist(-PI),
_maxTwist(PI), _maxTwist(PI),
_lastTwistBoundary(0) _lastTwistBoundary(LAST_CLAMP_NO_BOUNDARY)
{ {
} }
@ -249,3 +249,6 @@ bool SwingTwistConstraint::apply(glm::quat& rotation) const {
return false; return false;
} }
void SwingTwistConstraint::clearHistory() {
_lastTwistBoundary = LAST_CLAMP_NO_BOUNDARY;
}

View file

@ -73,6 +73,9 @@ public:
/// \return reference to SwingLimitFunction instance for unit-testing /// \return reference to SwingLimitFunction instance for unit-testing
const SwingLimitFunction& getSwingLimitFunction() const { return _swingLimitFunction; } const SwingLimitFunction& getSwingLimitFunction() const { return _swingLimitFunction; }
/// \brief exposed for unit testing
void clearHistory();
protected: protected:
SwingLimitFunction _swingLimitFunction; SwingLimitFunction _swingLimitFunction;
float _minTwist; float _minTwist;

View file

@ -35,7 +35,6 @@ void makeTestFBXJoints(std::vector<FBXJoint>& fbxJoints) {
joint.freeLineage.clear(); joint.freeLineage.clear();
joint.parentIndex = -1; joint.parentIndex = -1;
joint.distanceToParent = 1.0f; joint.distanceToParent = 1.0f;
joint.boneRadius = 1.0f;
joint.translation = origin; // T joint.translation = origin; // T
joint.preTransform = glm::mat4(); // Roff * Rp joint.preTransform = glm::mat4(); // Roff * Rp
@ -96,11 +95,11 @@ void makeTestFBXJoints(std::vector<FBXJoint>& fbxJoints) {
void AnimInverseKinematicsTests::testSingleChain() { void AnimInverseKinematicsTests::testSingleChain() {
std::vector<FBXJoint> fbxJoints; std::vector<FBXJoint> fbxJoints;
AnimPose offset; makeTestFBXJoints(fbxJoints);
makeTestFBXJoints(fbxJoints, offset);
// create a skeleton and doll // create a skeleton and doll
AnimSkeleton* skeleton = new AnimSkeleton(fbxJoints); AnimPose offset;
AnimSkeleton* skeleton = new AnimSkeleton(fbxJoints, offset);
AnimSkeleton::Pointer skeletonPtr(skeleton); AnimSkeleton::Pointer skeletonPtr(skeleton);
AnimInverseKinematics ikDoll("doll"); AnimInverseKinematics ikDoll("doll");
ikDoll.setSkeleton(skeletonPtr); ikDoll.setSkeleton(skeletonPtr);
@ -130,10 +129,13 @@ void AnimInverseKinematicsTests::testSingleChain() {
// //
// A------>B------>C------>D // A------>B------>C------>D
// //
int indexD = 3;
glm::vec3 targetPosition(2.0f, 1.0f, 0.0f); glm::vec3 targetPosition(2.0f, 1.0f, 0.0f);
glm::quat targetRotation = glm::angleAxis(PI / 2.0f, zAxis); glm::quat targetRotation = glm::angleAxis(PI / 2.0f, zAxis);
ikDoll.updateTarget(indexD, targetPosition, targetRotation); AnimVariantMap varMap;
varMap.set("positionD", targetPosition);
varMap.set("rotationD", targetRotation);
ikDoll.setTargetVars("D", "positionD", "rotationD");
AnimNode::Triggers triggers;
// the IK solution should be: // the IK solution should be:
// //
@ -143,7 +145,7 @@ void AnimInverseKinematicsTests::testSingleChain() {
// A------>B------>C // A------>B------>C
// //
float dt = 1.0f; float dt = 1.0f;
ikDoll.evaluate(dt); ikDoll.evaluate(varMap, dt, triggers);
// verify absolute results // verify absolute results
// NOTE: since we expect this solution to converge very quickly (one loop) // NOTE: since we expect this solution to converge very quickly (one loop)
@ -204,17 +206,20 @@ void AnimInverseKinematicsTests::testSingleChain() {
// | // |
// A------>B t // A------>B t
// //
int indexD = 3;
glm::vec3 targetPosition(3.0f, 0.0f, 0.0f); glm::vec3 targetPosition(3.0f, 0.0f, 0.0f);
glm::quat targetRotation = identity; glm::quat targetRotation = identity;
ikDoll.updateTarget(indexD, targetPosition, targetRotation); AnimVariantMap varMap;
varMap.set("positionD", targetPosition);
varMap.set("rotationD", targetRotation);
ikDoll.setTargetVars("D", "positionD", "rotationD");
AnimNode::Triggers triggers;
// the IK solution should be: // the IK solution should be:
// //
// A------>B------>C------>D // A------>B------>C------>D
// //
float dt = 1.0f; float dt = 1.0f;
ikDoll.evaluate(dt); ikDoll.evaluate(varMap, dt, triggers);
// verify absolute results // verify absolute results
// NOTE: the IK algorithm doesn't converge very fast for full-reach targets, // NOTE: the IK algorithm doesn't converge very fast for full-reach targets,

View file

@ -193,6 +193,7 @@ void RotationConstraintTests::testSwingTwistConstraint() {
glm::quat inputRotation = swingRotation * twistRotation * referenceRotation; glm::quat inputRotation = swingRotation * twistRotation * referenceRotation;
glm::quat outputRotation = inputRotation; glm::quat outputRotation = inputRotation;
shoulder.clearHistory();
bool updated = shoulder.apply(outputRotation); bool updated = shoulder.apply(outputRotation);
QVERIFY(updated == false); QVERIFY(updated == false);
QCOMPARE_WITH_ABS_ERROR(inputRotation, outputRotation, EPSILON); QCOMPARE_WITH_ABS_ERROR(inputRotation, outputRotation, EPSILON);
@ -223,6 +224,7 @@ void RotationConstraintTests::testSwingTwistConstraint() {
glm::quat inputRotation = swingRotation * twistRotation * referenceRotation; glm::quat inputRotation = swingRotation * twistRotation * referenceRotation;
glm::quat outputRotation = inputRotation; glm::quat outputRotation = inputRotation;
shoulder.clearHistory();
bool updated = shoulder.apply(outputRotation); bool updated = shoulder.apply(outputRotation);
QVERIFY(updated == true); QVERIFY(updated == true);
@ -257,6 +259,7 @@ void RotationConstraintTests::testSwingTwistConstraint() {
glm::quat inputRotation = swingRotation * twistRotation * referenceRotation; glm::quat inputRotation = swingRotation * twistRotation * referenceRotation;
glm::quat outputRotation = inputRotation; glm::quat outputRotation = inputRotation;
shoulder.clearHistory();
bool updated = shoulder.apply(outputRotation); bool updated = shoulder.apply(outputRotation);
QVERIFY(updated == true); QVERIFY(updated == true);
@ -291,6 +294,7 @@ void RotationConstraintTests::testSwingTwistConstraint() {
glm::quat inputRotation = swingRotation * twistRotation * referenceRotation; glm::quat inputRotation = swingRotation * twistRotation * referenceRotation;
glm::quat outputRotation = inputRotation; glm::quat outputRotation = inputRotation;
shoulder.clearHistory();
bool updated = shoulder.apply(outputRotation); bool updated = shoulder.apply(outputRotation);
QVERIFY(updated == true); QVERIFY(updated == true);