From 51189cfc503aea5d8646723ad13b971d30fe8728 Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Thu, 4 Feb 2016 17:56:41 -0800 Subject: [PATCH] AnimInverseKinematics: opened up UpLeg and Leg constraints This improves the quality of the jump animations, while IK is enabled. --- .../animation/src/AnimInverseKinematics.cpp | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/libraries/animation/src/AnimInverseKinematics.cpp b/libraries/animation/src/AnimInverseKinematics.cpp index 9f08ce455a..dc589a5f05 100644 --- a/libraries/animation/src/AnimInverseKinematics.cpp +++ b/libraries/animation/src/AnimInverseKinematics.cpp @@ -590,17 +590,24 @@ void AnimInverseKinematics::initConstraints() { stConstraint->setReferenceRotation(_defaultRelativePoses[i].rot); stConstraint->setTwistLimits(-PI / 4.0f, PI / 4.0f); - // these directions are approximate swing limits in root-frame - // NOTE: they don't need to be normalized std::vector swungDirections; - swungDirections.push_back(glm::vec3(mirror * 0.25f, 0.0f, 1.0f)); - swungDirections.push_back(glm::vec3(mirror * -0.5f, 0.0f, 1.0f)); - swungDirections.push_back(glm::vec3(mirror * -1.0f, 0.0f, 1.0f)); - swungDirections.push_back(glm::vec3(mirror * -1.0f, 0.0f, 0.0f)); - swungDirections.push_back(glm::vec3(mirror * -0.5f, -0.5f, -1.0f)); - swungDirections.push_back(glm::vec3(mirror * 0.0f, -0.75f, -1.0f)); - swungDirections.push_back(glm::vec3(mirror * 0.25f, -1.0f, 0.0f)); - swungDirections.push_back(glm::vec3(mirror * 0.25f, -1.0f, 1.0f)); + float deltaTheta = PI / 4.0f; + float theta = 0.0f; + swungDirections.push_back(glm::vec3(mirror * cos(theta), 0.25f, sin(theta))); + theta += deltaTheta; + swungDirections.push_back(glm::vec3(mirror * cos(theta), 0.0f, sin(theta))); + theta += deltaTheta; + swungDirections.push_back(glm::vec3(mirror * cos(theta), -0.25f, sin(theta))); // posterior + theta += deltaTheta; + swungDirections.push_back(glm::vec3(mirror * cos(theta), 0.0f, sin(theta))); + theta += deltaTheta; + swungDirections.push_back(glm::vec3(mirror * cos(theta), 0.25f, sin(theta))); + theta += deltaTheta; + swungDirections.push_back(glm::vec3(mirror * cos(theta), 0.5f, sin(theta))); + theta += deltaTheta; + swungDirections.push_back(glm::vec3(mirror * cos(theta), 0.5f, sin(theta))); // anterior + theta += deltaTheta; + swungDirections.push_back(glm::vec3(mirror * cos(theta), 0.5f, sin(theta))); // rotate directions into joint-frame glm::quat invAbsoluteRotation = glm::inverse(absolutePoses[i].rot); @@ -755,7 +762,7 @@ void AnimInverseKinematics::initConstraints() { // we determine the max/min angles by rotating the swing limit lines from parent- to child-frame // then measure the angles to swing the yAxis into alignment const float MIN_KNEE_ANGLE = 0.0f; - const float MAX_KNEE_ANGLE = 3.0f * PI / 4.0f; + const float MAX_KNEE_ANGLE = 7.0f * PI / 8.0f; glm::quat invReferenceRotation = glm::inverse(referenceRotation); glm::vec3 minSwingAxis = invReferenceRotation * glm::angleAxis(MIN_KNEE_ANGLE, hingeAxis) * Vectors::UNIT_Y; glm::vec3 maxSwingAxis = invReferenceRotation * glm::angleAxis(MAX_KNEE_ANGLE, hingeAxis) * Vectors::UNIT_Y;