From 3eefb6a93ee73d45c1f0ed4cfa1dd2078fd54b9b Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Thu, 15 May 2014 15:32:32 -0700 Subject: [PATCH] Rotation bits for alternate IK. --- interface/src/avatar/SkeletonModel.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/interface/src/avatar/SkeletonModel.cpp b/interface/src/avatar/SkeletonModel.cpp index 1921094a0f..540565f5b8 100644 --- a/interface/src/avatar/SkeletonModel.cpp +++ b/interface/src/avatar/SkeletonModel.cpp @@ -322,8 +322,8 @@ void SkeletonModel::setHandPosition(int jointIndex, const glm::vec3& position, c const float NORMAL_WEIGHT = 0.5f; glm::vec3 finalNormal = glm::mix(relaxedNormal, handNormal, NORMAL_WEIGHT); - if((jointIndex == geometry.rightHandJointIndex && finalNormal.y > 0.0f) || - (jointIndex == geometry.leftHandJointIndex && finalNormal.y < 0)) { + bool rightHand = (jointIndex == geometry.rightHandJointIndex); + if (rightHand ? (finalNormal.y > 0.0f) : (finalNormal.y < 0.0f)) { finalNormal.y = 0.0f; // dont allow elbows to point inward (y is vertical axis) } @@ -331,5 +331,17 @@ void SkeletonModel::setHandPosition(int jointIndex, const glm::vec3& position, c // ik solution glm::vec3 elbowPosition = shoulderPosition + glm::normalize(shoulderToWrist) * mid - tangent * height; + + glm::vec3 forwardVector(rightHand ? -1.0f : 1.0f, 0.0f, 0.0f); + + glm::quat shoulderRotation; + getJointRotation(shoulderJointIndex, shoulderRotation, true); + applyRotationDelta(shoulderJointIndex, rotationBetween(shoulderRotation * forwardVector, elbowPosition - shoulderPosition), false); + + glm::quat elbowRotation; + getJointRotation(elbowJointIndex, elbowRotation, true); + applyRotationDelta(elbowJointIndex, rotationBetween(elbowRotation * forwardVector, wristPosition - elbowPosition), false); + + setJointRotation(jointIndex, rotation, true); }