Fix for bad hand rotations

This commit is contained in:
Andrew Meadows 2014-05-14 09:06:46 -07:00
parent 366e9c7d34
commit 498f2843b0
2 changed files with 9 additions and 16 deletions

View file

@ -52,15 +52,12 @@ void SkeletonModel::simulate(float deltaTime, bool fullUpdate) {
} else if (leftPalmIndex == rightPalmIndex) { } else if (leftPalmIndex == rightPalmIndex) {
// right hand only // right hand only
applyPalmData(geometry.rightHandJointIndex, geometry.rightFingerJointIndices, geometry.rightFingertipJointIndices, applyPalmData(geometry.rightHandJointIndex, hand->getPalms()[leftPalmIndex]);
hand->getPalms()[leftPalmIndex]);
restoreLeftHandPosition(HAND_RESTORATION_RATE); restoreLeftHandPosition(HAND_RESTORATION_RATE);
} else { } else {
applyPalmData(geometry.leftHandJointIndex, geometry.leftFingerJointIndices, geometry.leftFingertipJointIndices, applyPalmData(geometry.leftHandJointIndex, hand->getPalms()[leftPalmIndex]);
hand->getPalms()[leftPalmIndex]); applyPalmData(geometry.rightHandJointIndex, hand->getPalms()[rightPalmIndex]);
applyPalmData(geometry.rightHandJointIndex, geometry.rightFingerJointIndices, geometry.rightFingertipJointIndices,
hand->getPalms()[rightPalmIndex]);
} }
} }
@ -140,8 +137,7 @@ void SkeletonModel::applyHandPosition(int jointIndex, const glm::vec3& position)
applyRotationDelta(jointIndex, rotationBetween(handRotation * glm::vec3(-sign, 0.0f, 0.0f), forearmVector)); applyRotationDelta(jointIndex, rotationBetween(handRotation * glm::vec3(-sign, 0.0f, 0.0f), forearmVector));
} }
void SkeletonModel::applyPalmData(int jointIndex, const QVector<int>& fingerJointIndices, void SkeletonModel::applyPalmData(int jointIndex, PalmData& palm) {
const QVector<int>& fingertipJointIndices, PalmData& palm) {
if (jointIndex == -1) { if (jointIndex == -1) {
return; return;
} }
@ -152,19 +148,17 @@ void SkeletonModel::applyPalmData(int jointIndex, const QVector<int>& fingerJoin
return; return;
} }
// rotate palm to align with palm direction // rotate palm to align with its normal (normal points out of hand's palm)
glm::quat palmRotation; glm::quat palmRotation;
if (Menu::getInstance()->isOptionChecked(MenuOption::AlignForearmsWithWrists)) { if (Menu::getInstance()->isOptionChecked(MenuOption::AlignForearmsWithWrists)) {
getJointRotation(parentJointIndex, palmRotation, true); getJointRotation(parentJointIndex, palmRotation, true);
} else { } else {
getJointRotation(jointIndex, palmRotation, true); getJointRotation(jointIndex, palmRotation, true);
} }
palmRotation = rotationBetween(palmRotation * geometry.palmDirection, palm.getPalmDirection()) * palmRotation; palmRotation = rotationBetween(palmRotation * geometry.palmDirection, palm.getNormal()) * palmRotation;
// rotate forearm according to average finger direction // rotate palm to align with finger direction
// NOTE: we're doing this in the avatar local frame, so we DON'T want to use Palm::getHandDirection() glm::vec3 direction = palm.getFingerDirection();
// which returns the world-frame.
glm::vec3 direction = palm.getRawRotation() * glm::vec3(0.0f, 0.0f, 1.0f);
palmRotation = rotationBetween(palmRotation * glm::vec3(-sign, 0.0f, 0.0f), direction) * palmRotation; palmRotation = rotationBetween(palmRotation * glm::vec3(-sign, 0.0f, 0.0f), direction) * palmRotation;
// set hand position, rotation // set hand position, rotation

View file

@ -39,8 +39,7 @@ protected:
void applyHandPosition(int jointIndex, const glm::vec3& position); void applyHandPosition(int jointIndex, const glm::vec3& position);
void applyPalmData(int jointIndex, const QVector<int>& fingerJointIndices, void applyPalmData(int jointIndex, PalmData& palm);
const QVector<int>& fingertipJointIndices, PalmData& palm);
/// Updates the state of the joint at the specified index. /// Updates the state of the joint at the specified index.
virtual void updateJointState(int index); virtual void updateJointState(int index);