Fix IK for hydra hands.

This commit is contained in:
Andrew Meadows 2014-06-09 15:40:29 -07:00
parent adac661e9f
commit e8b6338de9
2 changed files with 17 additions and 32 deletions

View file

@ -144,9 +144,9 @@ void SkeletonModel::getBodyShapes(QVector<const Shape*>& shapes) const {
void SkeletonModel::renderIKConstraints() { void SkeletonModel::renderIKConstraints() {
renderJointConstraints(getRightHandJointIndex()); renderJointConstraints(getRightHandJointIndex());
renderJointConstraints(getLeftHandJointIndex()); renderJointConstraints(getLeftHandJointIndex());
if (isActive() && _owningAvatar->isMyAvatar()) { //if (isActive() && _owningAvatar->isMyAvatar()) {
renderRagDoll(); // renderRagDoll();
} //}
} }
class IndexValue { class IndexValue {
@ -195,35 +195,20 @@ void SkeletonModel::applyPalmData(int jointIndex, PalmData& palm) {
} }
// rotate palm to align with its normal (normal points out of hand's palm) // rotate palm to align with its normal (normal points out of hand's palm)
glm::quat palmRotation;
glm::quat r0, r1;
if (!Menu::getInstance()->isOptionChecked(MenuOption::AlternateIK) &&
Menu::getInstance()->isOptionChecked(MenuOption::AlignForearmsWithWrists)) {
JointState parentState = _jointStates[parentJointIndex];
palmRotation = parentState.getRotationFromBindToModelFrame();
r0 = palmRotation;
} else {
JointState state = _jointStates[jointIndex];
palmRotation = state.getRotationFromBindToModelFrame();
}
glm::quat inverseRotation = glm::inverse(_rotation); glm::quat inverseRotation = glm::inverse(_rotation);
glm::vec3 palmNormal = inverseRotation * palm.getNormal();
palmRotation = rotationBetween(palmRotation * geometry.palmDirection, palmNormal) * palmRotation;
r1 = palmRotation;
// rotate palm to align with finger direction
glm::vec3 direction = inverseRotation * palm.getFingerDirection();
palmRotation = rotationBetween(palmRotation * glm::vec3(-sign, 0.0f, 0.0f), direction) * palmRotation;
// set hand position, rotation
glm::vec3 palmPosition = inverseRotation * (palm.getPosition() - _translation); glm::vec3 palmPosition = inverseRotation * (palm.getPosition() - _translation);
glm::vec3 palmNormal = inverseRotation * palm.getNormal();
glm::vec3 fingerDirection = inverseRotation * palm.getFingerDirection();
glm::quat palmRotation = rotationBetween(glm::vec3(0.0f, -1.0f, 0.0f), palmNormal);
palmRotation = rotationBetween(palmRotation * glm::vec3(-sign, 0.0f, 0.0f), fingerDirection) * palmRotation;
if (Menu::getInstance()->isOptionChecked(MenuOption::AlternateIK)) { if (Menu::getInstance()->isOptionChecked(MenuOption::AlternateIK)) {
setHandPosition(jointIndex, palmPosition, palmRotation); setHandPosition(jointIndex, palmPosition, palmRotation);
} else if (Menu::getInstance()->isOptionChecked(MenuOption::AlignForearmsWithWrists)) { } else if (Menu::getInstance()->isOptionChecked(MenuOption::AlignForearmsWithWrists)) {
glm::vec3 forearmVector = palmRotation * glm::vec3(sign, 0.0f, 0.0f); float forearmLength = geometry.joints.at(jointIndex).distanceToParent * extractUniformScale(_scale);
setJointPosition(parentJointIndex, palmPosition + forearmVector * glm::vec3 forearm = palmRotation * glm::vec3(sign * forearmLength, 0.0f, 0.0f);
geometry.joints.at(jointIndex).distanceToParent * extractUniformScale(_scale), setJointPosition(parentJointIndex, palmPosition + forearm,
glm::quat(), false, -1, false, glm::vec3(0.0f, -1.0f, 0.0f), PALM_PRIORITY); glm::quat(), false, -1, false, glm::vec3(0.0f, -1.0f, 0.0f), PALM_PRIORITY);
JointState& parentState = _jointStates[parentJointIndex]; JointState& parentState = _jointStates[parentJointIndex];
parentState.setRotationFromBindFrame(palmRotation, PALM_PRIORITY); parentState.setRotationFromBindFrame(palmRotation, PALM_PRIORITY);

View file

@ -1275,8 +1275,8 @@ bool Model::setJointPosition(int jointIndex, const glm::vec3& position, const gl
if (useRotation) { if (useRotation) {
JointState& state = _jointStates[jointIndex]; JointState& state = _jointStates[jointIndex];
state.setRotation(rotation, true, priority); state.setRotationFromBindFrame(rotation, priority);
endRotation = state.getRotation(); endRotation = state.getRotationFromBindToModelFrame();
} }
// then, we go from the joint upwards, rotating the end as close as possible to the target // then, we go from the joint upwards, rotating the end as close as possible to the target