This commit is contained in:
Andrew Meadows 2015-10-12 13:35:26 -07:00
parent e1a5afcff3
commit 22786dea7d
2 changed files with 14 additions and 18 deletions

View file

@ -27,15 +27,15 @@
},
{
"jointName": "RightFoot",
"positionVar": "rightToePosition",
"rotationVar": "rightToeRotation",
"typeVar": "rightToeType"
"positionVar": "rightFootPosition",
"rotationVar": "rightFootRotation",
"typeVar": "rightFootType"
},
{
"jointName": "LeftFoot",
"positionVar": "leftToePosition",
"rotationVar": "leftToeRotation",
"typeVar": "leftToeType"
"positionVar": "leftFootPosition",
"rotationVar": "leftFootRotation",
"typeVar": "leftFootType"
},
{
"jointName": "Neck",

View file

@ -102,8 +102,6 @@ void AnimInverseKinematics::computeTargets(const AnimVariantMap& animVars, std::
glm::vec3 translation = animVars.lookup(targetVar.positionVar, defaultPose.trans);
if (target.getType() == IKTarget::Type::HipsRelativeRotationAndPosition) {
translation += _hipsOffset;
// HACK to test whether lifting idle hands will release the shoulders
translation.y += 0.10f;
}
target.setPose(rotation, translation);
target.setIndex(targetVar.jointIndex);
@ -363,20 +361,18 @@ const AnimPoseVec& AnimInverseKinematics::overlay(const AnimVariantMap& animVars
} else {
// shift the hips according to the offset from the previous frame
float offsetLength = glm::length(_hipsOffset);
const float MIN_OFFSET_LENGTH = 0.03f;
if (offsetLength > MIN_OFFSET_LENGTH) {
// but only if actual offset is long enough
float scaleFactor = ((offsetLength - MIN_OFFSET_LENGTH) / offsetLength);
const float MIN_HIPS_OFFSET_LENGTH = 0.03f;
if (offsetLength > MIN_HIPS_OFFSET_LENGTH) {
// but only if offset is long enough
float scaleFactor = ((offsetLength - MIN_HIPS_OFFSET_LENGTH) / offsetLength);
_relativePoses[0].trans = underPoses[0].trans + scaleFactor * _hipsOffset;
}
solveWithCyclicCoordinateDescent(targets);
// compute the new target hips offset (for next frame)
// by looking for discrepancies between where a targeted endEffector is
// and where it wants to be (after IK solutions are done)
glm::vec3 hmdHipsOffset(100.0f);
glm::vec3 newHipsOffset = Vectors::ZERO;
for (auto& target: targets) {
int targetIndex = target.getIndex();
@ -392,7 +388,10 @@ const AnimPoseVec& AnimInverseKinematics::overlay(const AnimVariantMap& animVars
} else if (target.getType() == IKTarget::Type::HmdHead) {
// we want to shift the hips to bring the head to its designated position
glm::vec3 actual = _skeleton->getAbsolutePose(_headIndex, _relativePoses).trans;
hmdHipsOffset = _hipsOffset + target.getTranslation() - actual;
_hipsOffset += target.getTranslation() - actual;
// and ignore all other targets
newHipsOffset = _hipsOffset;
break;
}
} else if (target.getType() == IKTarget::Type::RotationAndPosition) {
glm::vec3 actualPosition = _skeleton->getAbsolutePose(targetIndex, _relativePoses).trans;
@ -404,9 +403,6 @@ const AnimPoseVec& AnimInverseKinematics::overlay(const AnimVariantMap& animVars
// smooth transitions by relaxing _hipsOffset toward the new value
const float HIPS_OFFSET_SLAVE_TIMESCALE = 0.15f;
_hipsOffset += (newHipsOffset - _hipsOffset) * (dt / HIPS_OFFSET_SLAVE_TIMESCALE);
if (glm::length2(hmdHipsOffset) < 100.0f) {
_hipsOffset = hmdHipsOffset;
}
}
}
return _relativePoses;