remove debug stuff and nerfed constriants

This commit is contained in:
Andrew Meadows 2015-09-08 19:14:31 -07:00
parent 381828dac3
commit e86e760118

View file

@ -11,7 +11,6 @@
#include <NumericalConstants.h> #include <NumericalConstants.h>
#include <SharedUtil.h> #include <SharedUtil.h>
#include <StreamUtils.h> // adebug
#include "ElbowConstraint.h" #include "ElbowConstraint.h"
#include "SwingTwistConstraint.h" #include "SwingTwistConstraint.h"
@ -73,7 +72,6 @@ void AnimInverseKinematics::updateTarget(int index, const glm::vec3& position, c
parentIndex = _skeleton->getParentIndex(parentIndex); parentIndex = _skeleton->getParentIndex(parentIndex);
} }
target.rootIndex = rootIndex; target.rootIndex = rootIndex;
std::cout << "adebug adding target for end-effector " << index << " with rootIndex " << rootIndex << std::endl; // adebug
_absoluteTargets[index] = target; _absoluteTargets[index] = target;
if (index > _maxTargetIndex) { if (index > _maxTargetIndex) {
@ -109,7 +107,6 @@ void AnimInverseKinematics::clearAllTargets() {
//virtual //virtual
const AnimPoseVec& AnimInverseKinematics::evaluate(const AnimVariantMap& animVars, float dt, AnimNode::Triggers& triggersOut) { const AnimPoseVec& AnimInverseKinematics::evaluate(const AnimVariantMap& animVars, float dt, AnimNode::Triggers& triggersOut) {
static int adebug = 0; ++adebug;
// NOTE: we assume that _relativePoses are up to date (e.g. loadPoses() was just called) // NOTE: we assume that _relativePoses are up to date (e.g. loadPoses() was just called)
if (_relativePoses.empty()) { if (_relativePoses.empty()) {
return _relativePoses; return _relativePoses;
@ -123,12 +120,7 @@ const AnimPoseVec& AnimInverseKinematics::evaluate(const AnimVariantMap& animVar
while (constraintItr != _constraints.end()) { while (constraintItr != _constraints.end()) {
int index = constraintItr->first; int index = constraintItr->first;
glm::quat rotation = _relativePoses[index].rot; glm::quat rotation = _relativePoses[index].rot;
// glm::quat oldRotation = rotation; // adebug constraintItr->second->apply(rotation);
// bool appliedConstraint = constraintItr->second->apply(rotation);
// if (0 == (adebug % 100) && appliedConstraint) {
// float angle = glm::angle(rotation * glm::inverse(oldRotation)); // adebug
// std::cout << "adebug 001 applied constraint to index " << index << std::endl; // adebug
// }
_relativePoses[index].rot = rotation; _relativePoses[index].rot = rotation;
++constraintItr; ++constraintItr;
} }
@ -142,7 +134,6 @@ const AnimPoseVec& AnimInverseKinematics::evaluate(const AnimVariantMap& animVar
int numLoops = 0; int numLoops = 0;
const int MAX_IK_LOOPS = 16; const int MAX_IK_LOOPS = 16;
const quint64 MAX_IK_TIME = 10 * USECS_PER_MSEC; const quint64 MAX_IK_TIME = 10 * USECS_PER_MSEC;
// quint64 loopStart = usecTimestampNow();
quint64 expiry = usecTimestampNow() + MAX_IK_TIME; quint64 expiry = usecTimestampNow() + MAX_IK_TIME;
do { do {
largestError = 0.0f; largestError = 0.0f;
@ -171,27 +162,15 @@ const AnimPoseVec& AnimInverseKinematics::evaluate(const AnimVariantMap& animVar
// compute tip's new parent-relative rotation // compute tip's new parent-relative rotation
// Q = Qp * q --> q' = Qp^ * Q // Q = Qp * q --> q' = Qp^ * Q
glm::quat newRelativeRotation = glm::inverse(absolutePoses[parentIndex].rot) * targetPose.rot; glm::quat newRelativeRotation = glm::inverse(absolutePoses[parentIndex].rot) * targetPose.rot;
/*
RotationConstraint* constraint = getConstraint(tipIndex); RotationConstraint* constraint = getConstraint(tipIndex);
if (constraint) { if (constraint) {
// bool appliedConstraint = false; constraint->apply(newRelativeRotation);
if (0 == (adebug % 5)) { // && appliedConstraint) { // TODO: ATM the final rotation target may fails but we need to provide
//std::cout << "adebug 001 applied constraint to index " << tipIndex << std::endl; // adebug
constraint->applyVerbose(newRelativeRotation);
} else {
constraint->apply(newRelativeRotation);
}
// TODO: ATM the final rotation target just fails but we need to provide
// feedback to the IK system so that it can adjust the bones up the skeleton // feedback to the IK system so that it can adjust the bones up the skeleton
// to help this rotation target get met. // to help this rotation target get met.
// TODO: setting the absolutePose.rot is not so simple if the relative rotation had to be constrained
//absolutePoses[tipIndex].rot = targetPose.rot;
} }
*/
_relativePoses[tipIndex].rot = newRelativeRotation; _relativePoses[tipIndex].rot = newRelativeRotation;
} }
break; break;
} }
@ -218,25 +197,15 @@ const AnimPoseVec& AnimInverseKinematics::evaluate(const AnimVariantMap& animVar
int parentIndex = _skeleton->getParentIndex(index); int parentIndex = _skeleton->getParentIndex(index);
if (parentIndex == -1) { if (parentIndex == -1) {
// accumulate any delta at the root's relative
// glm::quat newRot = glm::normalize(deltaRotation * _relativePoses[index].rot);
// _relativePoses[index].rot = newRot;
// absolutePoses[index].rot = newRot;
// TODO? apply constraints to root? // TODO? apply constraints to root?
// TODO: harvest the root's transform as movement of entire skeleton // TODO? harvest the root's transform as movement of entire skeleton?
} else { } else {
// compute joint's new parent-relative rotation // compute joint's new parent-relative rotation
// Q' = dQ * Q and Q = Qp * q --> q' = Qp^ * dQ * Q // Q' = dQ * Q and Q = Qp * q --> q' = Qp^ * dQ * Q
glm::quat newRot = glm::normalize(glm::inverse(absolutePoses[parentIndex].rot) * deltaRotation * absolutePoses[index].rot); glm::quat newRot = glm::normalize(glm::inverse(absolutePoses[parentIndex].rot) * deltaRotation * absolutePoses[index].rot);
RotationConstraint* constraint = getConstraint(index); RotationConstraint* constraint = getConstraint(index);
if (constraint) { if (constraint) {
// glm::quat oldRot = newRot; // adebug
// bool appliedConstraint = // adebug
constraint->apply(newRot); constraint->apply(newRot);
// if (0 == (adebug % 100) && appliedConstraint) {
// float angle = glm::angle(newRot * glm::inverse(oldRot)); // adebug
// std::cout << "adebug 001 applied constraint to index " << index << " angle = " << angle << std::endl; // adebug
// }
} }
_relativePoses[index].rot = newRot; _relativePoses[index].rot = newRot;
} }
@ -272,37 +241,19 @@ const AnimPoseVec& AnimInverseKinematics::evaluate(const AnimVariantMap& animVar
// compute tip's new parent-relative rotation // compute tip's new parent-relative rotation
// Q = Qp * q --> q' = Qp^ * Q // Q = Qp * q --> q' = Qp^ * Q
glm::quat newRelativeRotation = glm::inverse(absolutePoses[parentIndex].rot) * targetPose.rot; glm::quat newRelativeRotation = glm::inverse(absolutePoses[parentIndex].rot) * targetPose.rot;
/*
RotationConstraint* constraint = getConstraint(tipIndex); RotationConstraint* constraint = getConstraint(tipIndex);
if (constraint) { if (constraint) {
// bool appliedConstraint = false; constraint->apply(newRelativeRotation);
if (0 == (adebug % 5)) { // && appliedConstraint) {
//std::cout << "adebug 001 applied constraint to index " << tipIndex << std::endl; // adebug
constraint->applyVerbose(newRelativeRotation);
} else {
constraint->apply(newRelativeRotation);
}
// TODO: ATM the final rotation target just fails but we need to provide // TODO: ATM the final rotation target just fails but we need to provide
// feedback to the IK system so that it can adjust the bones up the skeleton // feedback to the IK system so that it can adjust the bones up the skeleton
// to help this rotation target get met. // to help this rotation target get met.
} }
*/
_relativePoses[tipIndex].rot = newRelativeRotation; _relativePoses[tipIndex].rot = newRelativeRotation;
// TODO: setting the absolutePose.rot is not so simple if the relative rotation had to be constrained
absolutePoses[tipIndex].rot = targetPose.rot; absolutePoses[tipIndex].rot = targetPose.rot;
} }
} }
++numLoops; ++numLoops;
} while (largestError > ACCEPTABLE_RELATIVE_ERROR && numLoops < MAX_IK_LOOPS && usecTimestampNow() < expiry); } while (largestError > ACCEPTABLE_RELATIVE_ERROR && numLoops < MAX_IK_LOOPS && usecTimestampNow() < expiry);
/*
if (0 == (adebug % 20)) {
std::cout << "adebug"
<< " l = " << numLoops
<< " t = " << float(usecTimestampNow() - loopStart)
<< " e = " << largestError
<< std::endl; // adebug
}
*/
} }
return _relativePoses; return _relativePoses;
} }
@ -445,7 +396,6 @@ void AnimInverseKinematics::initConstraints() {
constraint = static_cast<RotationConstraint*>(stConstraint); constraint = static_cast<RotationConstraint*>(stConstraint);
} else if (0 == name.compare("RightHand", Qt::CaseInsensitive)) { } else if (0 == name.compare("RightHand", Qt::CaseInsensitive)) {
std::cout << "adebug creating constraint for RightHand" << std::endl; // adebug
SwingTwistConstraint* stConstraint = new SwingTwistConstraint(); SwingTwistConstraint* stConstraint = new SwingTwistConstraint();
stConstraint->setReferenceRotation(_defaultRelativePoses[i].rot); stConstraint->setReferenceRotation(_defaultRelativePoses[i].rot);
const float MAX_HAND_TWIST = PI / 2.0f; const float MAX_HAND_TWIST = PI / 2.0f;
@ -587,7 +537,6 @@ void AnimInverseKinematics::initConstraints() {
} }
if (constraint) { if (constraint) {
_constraints[i] = constraint; _constraints[i] = constraint;
std::cout << "adebug " << i << " '" << _skeleton->getJointName(i).toStdString() << "' constraint = " << (void*)(constraint) << std::endl; // adebug
} }
} }
} }