use dynamic constraints for IK

This commit is contained in:
Andrew Meadows 2016-03-11 14:44:43 -08:00
parent 71a81331d1
commit 48efbba335
3 changed files with 16 additions and 1 deletions

View file

@ -396,6 +396,17 @@ const AnimPoseVec& AnimInverseKinematics::overlay(const AnimVariantMap& animVars
} }
_relativePoses[i].trans = underPoses[i].trans; _relativePoses[i].trans = underPoses[i].trans;
} }
if (!_relativePoses.empty()) {
// Sometimes the underpose itself can violate the constraints. Rather than
// clamp the animation we dynamically expand each constraint to accomodate it.
std::map<int, RotationConstraint*>::iterator constraintItr = _constraints.begin();
while (constraintItr != _constraints.end()) {
int index = constraintItr->first;
constraintItr->second->dynamicallyAdjustLimits(_relativePoses[index].rot);
++constraintItr;
}
}
} }
if (!_relativePoses.empty()) { if (!_relativePoses.empty()) {

View file

@ -31,6 +31,10 @@ public:
/// \return true if this constraint is part of lower spine /// \return true if this constraint is part of lower spine
virtual bool isLowerSpine() const { return false; } virtual bool isLowerSpine() const { return false; }
/// \param rotation rotation to allow
/// \brief clear previous adjustment and adjust constraint limits to allow rotation
virtual void dynamicallyAdjustLimits(const glm::quat& rotation) {}
protected: protected:
glm::quat _referenceRotation = glm::quat(); glm::quat _referenceRotation = glm::quat();
}; };

View file

@ -55,7 +55,7 @@ public:
/// \param rotation rotation to allow /// \param rotation rotation to allow
/// \brief clear previous adjustment and adjust constraint limits to allow rotation /// \brief clear previous adjustment and adjust constraint limits to allow rotation
void dynamicallyAdjustLimits(const glm::quat& rotation); virtual void dynamicallyAdjustLimits(const glm::quat& rotation) override;
// for testing purposes // for testing purposes
const std::vector<float>& getMinDots() { return _swingLimitFunction.getMinDots(); } const std::vector<float>& getMinDots() { return _swingLimitFunction.getMinDots(); }