Compute spine length on skeleton load

This commit is contained in:
Atlante45 2017-02-26 10:18:37 -08:00
parent e9316d30d0
commit 36dc2dc49d
2 changed files with 13 additions and 0 deletions

View file

@ -938,10 +938,22 @@ void AnimInverseKinematics::setSkeletonInternal(AnimSkeleton::ConstPointer skele
} else {
_hipsParentIndex = -1;
}
auto currentJointIndex = _headIndex;
auto parentJointIndex = _skeleton->getParentIndex(currentJointIndex);
_spineLength = 0.0f;
while (currentJointIndex != _hipsIndex && parentJointIndex != -1) {
_spineLength += glm::distance(_skeleton->getAbsoluteDefaultPose(currentJointIndex).trans(),
_skeleton->getAbsoluteDefaultPose(parentJointIndex).trans());
currentJointIndex = parentJointIndex;
parentJointIndex = _skeleton->getParentIndex(currentJointIndex);
}
} else {
clearConstraints();
_headIndex = -1;
_hipsIndex = -1;
_hipsParentIndex = -1;
_spineLength = 0.0f;
}
}

View file

@ -91,6 +91,7 @@ protected:
int _headIndex { -1 };
int _hipsIndex { -1 };
int _hipsParentIndex { -1 };
float _spineLength { 0.0f };
// _maxTargetIndex is tracked to help optimize the recalculation of absolute poses
// during the the cyclic coordinate descent algorithm