fix animation-tests

This commit is contained in:
Andrew Meadows 2015-09-14 16:42:57 -07:00
parent 15b809bd16
commit 75ec142827
4 changed files with 26 additions and 11 deletions

View file

@ -72,7 +72,7 @@ SwingTwistConstraint::SwingTwistConstraint() :
_swingLimitFunction(),
_minTwist(-PI),
_maxTwist(PI),
_lastTwistBoundary(0)
_lastTwistBoundary(LAST_CLAMP_NO_BOUNDARY)
{
}
@ -249,3 +249,6 @@ bool SwingTwistConstraint::apply(glm::quat& rotation) const {
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
const SwingLimitFunction& getSwingLimitFunction() const { return _swingLimitFunction; }
/// \brief exposed for unit testing
void clearHistory();
protected:
SwingLimitFunction _swingLimitFunction;
float _minTwist;

View file

@ -35,7 +35,6 @@ void makeTestFBXJoints(std::vector<FBXJoint>& fbxJoints) {
joint.freeLineage.clear();
joint.parentIndex = -1;
joint.distanceToParent = 1.0f;
joint.boneRadius = 1.0f;
joint.translation = origin; // T
joint.preTransform = glm::mat4(); // Roff * Rp
@ -96,11 +95,11 @@ void makeTestFBXJoints(std::vector<FBXJoint>& fbxJoints) {
void AnimInverseKinematicsTests::testSingleChain() {
std::vector<FBXJoint> fbxJoints;
AnimPose offset;
makeTestFBXJoints(fbxJoints, offset);
makeTestFBXJoints(fbxJoints);
// create a skeleton and doll
AnimSkeleton* skeleton = new AnimSkeleton(fbxJoints);
AnimPose offset;
AnimSkeleton* skeleton = new AnimSkeleton(fbxJoints, offset);
AnimSkeleton::Pointer skeletonPtr(skeleton);
AnimInverseKinematics ikDoll("doll");
ikDoll.setSkeleton(skeletonPtr);
@ -130,10 +129,13 @@ void AnimInverseKinematicsTests::testSingleChain() {
//
// A------>B------>C------>D
//
int indexD = 3;
glm::vec3 targetPosition(2.0f, 1.0f, 0.0f);
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:
//
@ -143,7 +145,7 @@ void AnimInverseKinematicsTests::testSingleChain() {
// A------>B------>C
//
float dt = 1.0f;
ikDoll.evaluate(dt);
ikDoll.evaluate(varMap, dt, triggers);
// verify absolute results
// NOTE: since we expect this solution to converge very quickly (one loop)
@ -204,17 +206,20 @@ void AnimInverseKinematicsTests::testSingleChain() {
// |
// A------>B t
//
int indexD = 3;
glm::vec3 targetPosition(3.0f, 0.0f, 0.0f);
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:
//
// A------>B------>C------>D
//
float dt = 1.0f;
ikDoll.evaluate(dt);
ikDoll.evaluate(varMap, dt, triggers);
// verify absolute results
// 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 outputRotation = inputRotation;
shoulder.clearHistory();
bool updated = shoulder.apply(outputRotation);
QVERIFY(updated == false);
QCOMPARE_WITH_ABS_ERROR(inputRotation, outputRotation, EPSILON);
@ -223,6 +224,7 @@ void RotationConstraintTests::testSwingTwistConstraint() {
glm::quat inputRotation = swingRotation * twistRotation * referenceRotation;
glm::quat outputRotation = inputRotation;
shoulder.clearHistory();
bool updated = shoulder.apply(outputRotation);
QVERIFY(updated == true);
@ -257,6 +259,7 @@ void RotationConstraintTests::testSwingTwistConstraint() {
glm::quat inputRotation = swingRotation * twistRotation * referenceRotation;
glm::quat outputRotation = inputRotation;
shoulder.clearHistory();
bool updated = shoulder.apply(outputRotation);
QVERIFY(updated == true);
@ -291,6 +294,7 @@ void RotationConstraintTests::testSwingTwistConstraint() {
glm::quat inputRotation = swingRotation * twistRotation * referenceRotation;
glm::quat outputRotation = inputRotation;
shoulder.clearHistory();
bool updated = shoulder.apply(outputRotation);
QVERIFY(updated == true);