diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index 31e1ee43fb..47ac966a6d 100755 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -660,12 +660,13 @@ void Avatar::updateArmIKAndConstraints(float deltaTime, AvatarJointID fingerTipJ float distance = glm::length(armVector); // don't let right hand get dragged beyond maximum arm length... - if (distance > _maxArmLength) { + float armLength = _maxArmLength * 0.5f; + if (distance > armLength) { // reset right hand to be constrained to maximum arm length fingerJoint.position = shoulderJoint.position; glm::vec3 armNormal = armVector / distance; - armVector = armNormal * _maxArmLength; - distance = _maxArmLength; + armVector = armNormal * armLength; + distance = armLength; glm::vec3 constrainedPosition = shoulderJoint.position; constrainedPosition += armVector; fingerJoint.position = constrainedPosition; diff --git a/interface/src/renderer/Model.cpp b/interface/src/renderer/Model.cpp index b7dd65b0a0..750b1e7676 100644 --- a/interface/src/renderer/Model.cpp +++ b/interface/src/renderer/Model.cpp @@ -616,16 +616,16 @@ bool Model::setJointPosition(int jointIndex, const glm::vec3& position) { // this is a constraint relaxation algorithm: see // http://www.ryanjuckett.com/programming/animation/22-constraint-relaxation-ik-in-2d - // start by optimistically setting the position of the end joint to our target - setJointTranslation(jointIndex, freeLineage.at(1), -1, relativePosition); - // the influence of gravity; lowers the potential energy of our configurations - glm::vec3 gravity = _rotation * IDENTITY_UP * -0.1f; + glm::vec3 gravity = _rotation * IDENTITY_UP * -0.01f; // over one or more iterations, apply the length constraints and update the rotations accordingly float uniformScale = (_scale.x + _scale.y + _scale.z) / 3.0f; - const int ITERATION_COUNT = 1; + const int ITERATION_COUNT = 3; for (int i = 0; i < ITERATION_COUNT; i++) { + // start by optimistically setting the position of the end joint to our target + setJointTranslation(jointIndex, freeLineage.at(1), -1, relativePosition); + for (int j = 1; j < freeLineage.size(); j++) { int sourceIndex = freeLineage.at(j); int destIndex = freeLineage.at(j - 1); @@ -657,11 +657,11 @@ bool Model::setJointPosition(int jointIndex, const glm::vec3& position) { destTranslation + boneVector * extension * 0.5f + gravity); } } - } - - // now update the joint states from the top - for (int i = freeLineage.size() - 1; i >= 0; i--) { - updateJointState(freeLineage.at(i)); + + // now update the joint states from the top + for (int j = freeLineage.size() - 1; j >= 0; j--) { + updateJointState(freeLineage.at(j)); + } } return true;