mirror of
https://github.com/overte-org/overte.git
synced 2025-04-23 23:33:26 +02:00
simpler logic for tracking hips offset
This commit is contained in:
parent
03eaa95258
commit
56f038d5a7
2 changed files with 9 additions and 10 deletions
|
@ -356,12 +356,12 @@ const AnimPoseVec& AnimInverseKinematics::overlay(const AnimVariantMap& animVars
|
|||
}
|
||||
} else {
|
||||
// shift the hips according to the offset from the previous frame
|
||||
float offsetLength = glm::length(_actualHipsOffset);
|
||||
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);
|
||||
_relativePoses[0].trans = underPoses[0].trans + scaleFactor * _actualHipsOffset;
|
||||
_relativePoses[0].trans = underPoses[0].trans + scaleFactor * _hipsOffset;
|
||||
}
|
||||
|
||||
solveWithCyclicCoordinateDescent(targets);
|
||||
|
@ -369,7 +369,7 @@ const AnimPoseVec& AnimInverseKinematics::overlay(const AnimVariantMap& animVars
|
|||
// 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)
|
||||
_targetHipsOffset = Vectors::ZERO;
|
||||
glm::vec3 newOffset = Vectors::ZERO;
|
||||
for (auto& target: targets) {
|
||||
if (target.index == _headIndex && _headIndex != -1) {
|
||||
// special handling for headTarget
|
||||
|
@ -382,18 +382,18 @@ const AnimPoseVec& AnimInverseKinematics::overlay(const AnimVariantMap& animVars
|
|||
}
|
||||
glm::vec3 headOffset = headOverPose.trans - headUnderPose.trans;
|
||||
const float HEAD_OFFSET_SLAVE_FACTOR = 0.65f;
|
||||
_targetHipsOffset += HEAD_OFFSET_SLAVE_FACTOR * headOffset;
|
||||
newOffset += HEAD_OFFSET_SLAVE_FACTOR * headOffset;
|
||||
} else if (target.type == IKTarget::Type::RotationAndPosition) {
|
||||
glm::vec3 actualPosition = _skeleton->getAbsolutePose(target.index, _relativePoses).trans;
|
||||
glm::vec3 targetPosition = target.pose.trans;
|
||||
_targetHipsOffset += targetPosition - actualPosition;
|
||||
newOffset += targetPosition - actualPosition;
|
||||
}
|
||||
}
|
||||
|
||||
// smooth transitions by relaxing targetHipsOffset onto actualHipsOffset over some timescale
|
||||
// smooth transitions by relaxing _hipsOffset toward the new value
|
||||
const float HIPS_OFFSET_SLAVE_TIMESCALE = 0.15f;
|
||||
glm::vec3 deltaOffset = (_targetHipsOffset - _actualHipsOffset) * (dt / HIPS_OFFSET_SLAVE_TIMESCALE);
|
||||
_actualHipsOffset += deltaOffset;
|
||||
glm::vec3 deltaOffset = (newOffset - _hipsOffset) * (dt / HIPS_OFFSET_SLAVE_TIMESCALE);
|
||||
_hipsOffset += deltaOffset;
|
||||
}
|
||||
}
|
||||
return _relativePoses;
|
||||
|
|
|
@ -91,8 +91,7 @@ protected:
|
|||
|
||||
// experimental data for moving hips during IK
|
||||
int _headIndex = -1;
|
||||
glm::vec3 _targetHipsOffset = Vectors::ZERO; // offset we want
|
||||
glm::vec3 _actualHipsOffset = Vectors::ZERO; // offset we have
|
||||
glm::vec3 _hipsOffset = Vectors::ZERO;
|
||||
|
||||
// _maxTargetIndex is tracked to help optimize the recalculation of absolute poses
|
||||
// during the the cyclic coordinate descent algorithm
|
||||
|
|
Loading…
Reference in a new issue