Remove weighted offset, special case downward pressure

This commit is contained in:
Atlante45 2017-03-06 19:35:00 -08:00 committed by Chris Collins
parent 74323cb1f0
commit c52c43e23d

View file

@ -488,13 +488,7 @@ const AnimPoseVec& AnimInverseKinematics::overlay(const AnimVariantMap& animVars
// measure new _hipsOffset for next frame // measure new _hipsOffset for next frame
// by looking for discrepancies between where a targeted endEffector is // by looking for discrepancies between where a targeted endEffector is
// and where it wants to be (after IK solutions are done) // and where it wants to be (after IK solutions are done)
glm::vec3 newHipsOffset = Vectors::ZERO;
// use weighted average between HMD and other targets
float HMD_WEIGHT = 10.0f;
float OTHER_WEIGHT = 1.0f;
float totalWeight = 0.0f;
glm::vec3 additionalHipsOffset = Vectors::ZERO;
for (auto& target: targets) { for (auto& target: targets) {
int targetIndex = target.getIndex(); int targetIndex = target.getIndex();
if (targetIndex == _headIndex && _headIndex != -1) { if (targetIndex == _headIndex && _headIndex != -1) {
@ -505,42 +499,34 @@ const AnimPoseVec& AnimInverseKinematics::overlay(const AnimVariantMap& animVars
glm::vec3 under = _skeleton->getAbsolutePose(_headIndex, underPoses).trans(); glm::vec3 under = _skeleton->getAbsolutePose(_headIndex, underPoses).trans();
glm::vec3 actual = _skeleton->getAbsolutePose(_headIndex, _relativePoses).trans(); glm::vec3 actual = _skeleton->getAbsolutePose(_headIndex, _relativePoses).trans();
const float HEAD_OFFSET_SLAVE_FACTOR = 0.65f; const float HEAD_OFFSET_SLAVE_FACTOR = 0.65f;
additionalHipsOffset += (OTHER_WEIGHT * HEAD_OFFSET_SLAVE_FACTOR) * (under- actual); newHipsOffset += HEAD_OFFSET_SLAVE_FACTOR * (actual - under);
totalWeight += OTHER_WEIGHT;
} else if (target.getType() == IKTarget::Type::HmdHead) { } 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(); glm::vec3 actual = _skeleton->getAbsolutePose(_headIndex, _relativePoses).trans();
glm::vec3 thisOffset = target.getTranslation() - actual; _hipsOffset += target.getTranslation() - actual;
glm::vec3 futureHipsOffset = _hipsOffset + thisOffset; // and ignore all other targets
if (glm::length(glm::vec2(futureHipsOffset.x, futureHipsOffset.z)) < _maxHipsOffsetLength) { newHipsOffset = _hipsOffset;
// it is imperative to shift the hips and bring the head to its designated position break;
// so we slam newHipsOffset here and ignore all other targets } else if (target.getType() == IKTarget::Type::RotationAndPosition) {
additionalHipsOffset = futureHipsOffset - _hipsOffset; glm::vec3 actualPosition = _skeleton->getAbsolutePose(targetIndex, _relativePoses).trans();
totalWeight = 0.0f; glm::vec3 targetPosition = target.getTranslation();
break; newHipsOffset += targetPosition - actualPosition;
} else {
additionalHipsOffset += HMD_WEIGHT * (target.getTranslation() - actual); // Add downward pressure on the hips
totalWeight += HMD_WEIGHT; newHipsOffset *= 0.95f;
} newHipsOffset -= 1.0f;
} }
} else if (target.getType() == IKTarget::Type::RotationAndPosition) { } else if (target.getType() == IKTarget::Type::RotationAndPosition) {
glm::vec3 actualPosition = _skeleton->getAbsolutePose(targetIndex, _relativePoses).trans(); glm::vec3 actualPosition = _skeleton->getAbsolutePose(targetIndex, _relativePoses).trans();
glm::vec3 targetPosition = target.getTranslation(); glm::vec3 targetPosition = target.getTranslation();
additionalHipsOffset += OTHER_WEIGHT * (targetPosition - actualPosition); newHipsOffset += targetPosition - actualPosition;
totalWeight += OTHER_WEIGHT;
} }
} }
if (totalWeight > 1.0f) {
additionalHipsOffset /= totalWeight;
}
// Add downward pressure on the hips
additionalHipsOffset *= 0.95f;
additionalHipsOffset -= 1.0f;
// smooth transitions by relaxing _hipsOffset toward the new value // smooth transitions by relaxing _hipsOffset toward the new value
const float HIPS_OFFSET_SLAVE_TIMESCALE = 0.10f; const float HIPS_OFFSET_SLAVE_TIMESCALE = 0.10f;
float tau = dt < HIPS_OFFSET_SLAVE_TIMESCALE ? dt / HIPS_OFFSET_SLAVE_TIMESCALE : 1.0f; float tau = dt < HIPS_OFFSET_SLAVE_TIMESCALE ? dt / HIPS_OFFSET_SLAVE_TIMESCALE : 1.0f;
_hipsOffset += additionalHipsOffset * tau; _hipsOffset += (newHipsOffset - _hipsOffset) * tau;
// clamp the hips offset // clamp the hips offset
float hipsOffsetLength = glm::length(_hipsOffset); float hipsOffsetLength = glm::length(_hipsOffset);