mirror of
https://github.com/lubosz/overte.git
synced 2025-04-14 04:26:18 +02:00
put all the hand update code in one function that works for two bone IK
and legacy animInverseKinematics Ik
This commit is contained in:
parent
bc635306ea
commit
71df614989
2 changed files with 43 additions and 15 deletions
|
@ -189,7 +189,7 @@ const AnimPoseVec& AnimSplineIK::evaluate(const AnimVariantMap& animVars, const
|
|||
AnimPose beforeSolveChestNeck;
|
||||
if (_poses.size() > 0) {
|
||||
|
||||
|
||||
// fix this to deal with no neck AA
|
||||
beforeSolveChestNeck = _skeleton->getAbsolutePose(_skeleton->nameToJointIndex("Neck"), _poses);
|
||||
|
||||
secondaryJointChain.buildFromRelativePoses(_skeleton, _poses, secondaryTarget.getIndex());
|
||||
|
@ -205,12 +205,13 @@ const AnimPoseVec& AnimSplineIK::evaluate(const AnimVariantMap& animVars, const
|
|||
AnimPose secondaryTargetPose(target2.getRotation(), target2.getTranslation());
|
||||
AnimPose secondaryTargetRelativePose = _skeleton->getAbsolutePose(secondaryTargetParent, _poses).inverse() * secondaryTargetPose;
|
||||
_poses[_secondaryTargetIndex] = secondaryTargetRelativePose;
|
||||
|
||||
|
||||
AnimPose neckAbsolute = _skeleton->getAbsolutePose(tipParent, _poses);
|
||||
AnimPose finalNeckAbsolute = AnimPose(safeLerp(target2.getRotation(), target.getRotation(), 1.0f),neckAbsolute.trans());
|
||||
_poses[headParent] = spine2Target.inverse() * beforeSolveChestNeck;
|
||||
*/
|
||||
|
||||
AnimPose secondaryTargetPose(secondaryTarget.getRotation(), secondaryTarget.getTranslation());
|
||||
AnimPose neckAbsolute = _skeleton->getAbsolutePose(tipParent, _poses);
|
||||
//AnimPose finalNeckAbsolute = AnimPose(safeLerp(target2.getRotation(), target.getRotation(), 1.0f),neckAbsolute.trans());
|
||||
_poses[tipParent] = secondaryTargetPose.inverse() * beforeSolveChestNeck;
|
||||
|
||||
AnimPose tipTarget(target.getRotation(),target.getTranslation());
|
||||
AnimPose tipRelativePose = _skeleton->getAbsolutePose(tipParent,_poses).inverse() * tipTarget;
|
||||
_poses[_tipJointIndex] = tipRelativePose;
|
||||
|
|
|
@ -1271,6 +1271,7 @@ void Rig::computeHeadFromHMD(const AnimPose& hmdPose, glm::vec3& headPositionOut
|
|||
void Rig::updateHead(bool headEnabled, bool hipsEnabled, const AnimPose& headPose) {
|
||||
if (_animSkeleton) {
|
||||
if (headEnabled) {
|
||||
_animVars.set("splineIKEnabled", true);
|
||||
_animVars.set("headPosition", headPose.trans());
|
||||
_animVars.set("headRotation", headPose.rot());
|
||||
if (hipsEnabled) {
|
||||
|
@ -1285,6 +1286,7 @@ void Rig::updateHead(bool headEnabled, bool hipsEnabled, const AnimPose& headPos
|
|||
_animVars.set("headWeight", 8.0f);
|
||||
}
|
||||
} else {
|
||||
_animVars.set("splineIKEnabled", false);
|
||||
_animVars.unset("headPosition");
|
||||
_animVars.set("headRotation", headPose.rot());
|
||||
_animVars.set("headType", (int)IKTarget::Type::RotationOnly);
|
||||
|
@ -1416,8 +1418,22 @@ void Rig::updateHands(bool leftHandEnabled, bool rightHandEnabled, bool hipsEnab
|
|||
|
||||
const bool ENABLE_POLE_VECTORS = true;
|
||||
|
||||
if (headEnabled) {
|
||||
// always do IK if head is enabled
|
||||
_animVars.set("leftHandIKEnabled", true);
|
||||
_animVars.set("rightHandIKEnabled", true);
|
||||
} else {
|
||||
// only do IK if we have a valid foot.
|
||||
_animVars.set("leftHandIKEnabled", leftHandEnabled);
|
||||
_animVars.set("rightHandIKEnabled", rightHandEnabled);
|
||||
}
|
||||
|
||||
if (leftHandEnabled) {
|
||||
|
||||
// we need this for twoBoneIK version of hands.
|
||||
_animVars.set(LEFT_HAND_IK_POSITION_VAR, LEFT_HAND_POSITION);
|
||||
_animVars.set(LEFT_HAND_IK_ROTATION_VAR, LEFT_HAND_ROTATION);
|
||||
|
||||
glm::vec3 handPosition = leftHandPose.trans();
|
||||
glm::quat handRotation = leftHandPose.rot();
|
||||
|
||||
|
@ -1450,8 +1466,11 @@ void Rig::updateHands(bool leftHandEnabled, bool rightHandEnabled, bool hipsEnab
|
|||
_animVars.set("leftHandPoleVectorEnabled", false);
|
||||
}
|
||||
} else {
|
||||
// need this for two bone ik
|
||||
_animVars.set(LEFT_HAND_IK_POSITION_VAR, MAIN_STATE_MACHINE_LEFT_HAND_POSITION);
|
||||
_animVars.set(LEFT_HAND_IK_ROTATION_VAR, MAIN_STATE_MACHINE_LEFT_HAND_ROTATION);
|
||||
|
||||
_animVars.set("leftHandPoleVectorEnabled", false);
|
||||
|
||||
_animVars.unset("leftHandPosition");
|
||||
_animVars.unset("leftHandRotation");
|
||||
|
||||
|
@ -1465,6 +1484,10 @@ void Rig::updateHands(bool leftHandEnabled, bool rightHandEnabled, bool hipsEnab
|
|||
|
||||
if (rightHandEnabled) {
|
||||
|
||||
// need this for two bone IK
|
||||
_animVars.set(RIGHT_HAND_IK_POSITION_VAR, RIGHT_HAND_POSITION);
|
||||
_animVars.set(RIGHT_HAND_IK_ROTATION_VAR, RIGHT_HAND_ROTATION);
|
||||
|
||||
glm::vec3 handPosition = rightHandPose.trans();
|
||||
glm::quat handRotation = rightHandPose.rot();
|
||||
|
||||
|
@ -1498,8 +1521,12 @@ void Rig::updateHands(bool leftHandEnabled, bool rightHandEnabled, bool hipsEnab
|
|||
_animVars.set("rightHandPoleVectorEnabled", false);
|
||||
}
|
||||
} else {
|
||||
_animVars.set("rightHandPoleVectorEnabled", false);
|
||||
|
||||
// need this for two bone IK
|
||||
_animVars.set(RIGHT_HAND_IK_POSITION_VAR, MAIN_STATE_MACHINE_RIGHT_HAND_POSITION);
|
||||
_animVars.set(RIGHT_HAND_IK_ROTATION_VAR, MAIN_STATE_MACHINE_RIGHT_HAND_ROTATION);
|
||||
|
||||
_animVars.set("rightHandPoleVectorEnabled", false);
|
||||
_animVars.unset("rightHandPosition");
|
||||
_animVars.unset("rightHandRotation");
|
||||
|
||||
|
@ -1857,14 +1884,14 @@ void Rig::updateFromControllerParameters(const ControllerParameters& params, flo
|
|||
|
||||
updateHead(_headEnabled, hipsEnabled, params.primaryControllerPoses[PrimaryControllerType_Head]);
|
||||
|
||||
//updateHands(leftHandEnabled, rightHandEnabled, hipsEnabled, hipsEstimated, leftArmEnabled, rightArmEnabled, _headEnabled, dt,
|
||||
// params.primaryControllerPoses[PrimaryControllerType_LeftHand], params.primaryControllerPoses[PrimaryControllerType_RightHand],
|
||||
// params.hipsShapeInfo, params.spineShapeInfo, params.spine1ShapeInfo, params.spine2ShapeInfo,
|
||||
// params.rigToSensorMatrix, sensorToRigMatrix);
|
||||
updateHands(leftHandEnabled, rightHandEnabled, hipsEnabled, hipsEstimated, leftArmEnabled, rightArmEnabled, _headEnabled, dt,
|
||||
params.primaryControllerPoses[PrimaryControllerType_LeftHand], params.primaryControllerPoses[PrimaryControllerType_RightHand],
|
||||
params.hipsShapeInfo, params.spineShapeInfo, params.spine1ShapeInfo, params.spine2ShapeInfo,
|
||||
params.rigToSensorMatrix, sensorToRigMatrix);
|
||||
|
||||
updateHands2(leftHandEnabled, rightHandEnabled, _headEnabled,
|
||||
params.primaryControllerPoses[PrimaryControllerType_LeftHand], params.primaryControllerPoses[PrimaryControllerType_RightHand],
|
||||
params.rigToSensorMatrix, sensorToRigMatrix);
|
||||
//updateHands2(leftHandEnabled, rightHandEnabled, _headEnabled,
|
||||
// params.primaryControllerPoses[PrimaryControllerType_LeftHand], params.primaryControllerPoses[PrimaryControllerType_RightHand],
|
||||
// params.rigToSensorMatrix, sensorToRigMatrix);
|
||||
|
||||
updateFeet(leftFootEnabled, rightFootEnabled, _headEnabled,
|
||||
params.primaryControllerPoses[PrimaryControllerType_LeftFoot], params.primaryControllerPoses[PrimaryControllerType_RightFoot],
|
||||
|
|
Loading…
Reference in a new issue