More palm fixes.

This commit is contained in:
Andrzej Kapolka 2013-11-07 13:29:17 -08:00
parent 4360621daf
commit 797645a209
2 changed files with 20 additions and 23 deletions

View file

@ -28,17 +28,22 @@ void SkeletonModel::simulate(float deltaTime) {
Model::simulate(deltaTime); Model::simulate(deltaTime);
// find the active Leap palms, if any // find the left and rightmost active Leap palms
HandData& hand = _owningAvatar->getHand(); HandData& hand = _owningAvatar->getHand();
int firstActivePalmIndex = -1; int leftPalmIndex = -1;
int secondActivePalmIndex = -1; float leftPalmX = FLT_MAX;
int rightPalmIndex = -1;
float rightPalmX = -FLT_MAX;
for (int i = 0; i < hand.getNumPalms(); i++) { for (int i = 0; i < hand.getNumPalms(); i++) {
if (hand.getPalms()[i].isActive()) { if (hand.getPalms()[i].isActive()) {
if (firstActivePalmIndex == -1) { float x = hand.getPalms()[i].getRawPosition().x;
firstActivePalmIndex = i; if (x < leftPalmX) {
} else { leftPalmIndex = i;
secondActivePalmIndex = i; leftPalmX = x;
break; }
if (x > rightPalmX) {
rightPalmIndex = i;
rightPalmX = x;
} }
} }
} }
@ -46,7 +51,7 @@ void SkeletonModel::simulate(float deltaTime) {
const float HAND_RESTORATION_RATE = 0.25f; const float HAND_RESTORATION_RATE = 0.25f;
const FBXGeometry& geometry = _geometry->getFBXGeometry(); const FBXGeometry& geometry = _geometry->getFBXGeometry();
if (firstActivePalmIndex == -1) { if (leftPalmIndex == -1) {
// no Leap data; set hands from mouse // no Leap data; set hands from mouse
if (_owningAvatar->getHandState() == HAND_STATE_NULL) { if (_owningAvatar->getHandState() == HAND_STATE_NULL) {
restoreRightHandPosition(HAND_RESTORATION_RATE); restoreRightHandPosition(HAND_RESTORATION_RATE);
@ -55,22 +60,14 @@ void SkeletonModel::simulate(float deltaTime) {
} }
restoreLeftHandPosition(HAND_RESTORATION_RATE); restoreLeftHandPosition(HAND_RESTORATION_RATE);
} else if (secondActivePalmIndex == -1) { } else if (leftPalmIndex == rightPalmIndex) {
// right hand only // right hand only
applyPalmData(geometry.rightHandJointIndex, geometry.rightFingertipJointIndices, applyPalmData(geometry.rightHandJointIndex, geometry.rightFingertipJointIndices, hand.getPalms()[leftPalmIndex]);
hand.getPalms()[firstActivePalmIndex]);
restoreLeftHandPosition(HAND_RESTORATION_RATE); restoreLeftHandPosition(HAND_RESTORATION_RATE);
} else { } else {
// both hands; make sure left is first applyPalmData(geometry.leftHandJointIndex, geometry.leftFingertipJointIndices, hand.getPalms()[leftPalmIndex]);
if (hand.getPalms()[firstActivePalmIndex].getRawPosition().x > applyPalmData(geometry.rightHandJointIndex, geometry.rightFingertipJointIndices, hand.getPalms()[rightPalmIndex]);
hand.getPalms()[secondActivePalmIndex].getRawPosition().x) {
qSwap(firstActivePalmIndex, secondActivePalmIndex);
}
applyPalmData(geometry.leftHandJointIndex, geometry.leftFingertipJointIndices,
hand.getPalms()[firstActivePalmIndex]);
applyPalmData(geometry.rightHandJointIndex, geometry.rightFingertipJointIndices,
hand.getPalms()[secondActivePalmIndex]);
} }
} }
@ -136,7 +133,7 @@ bool operator<(const IndexValue& firstIndex, const IndexValue& secondIndex) {
void SkeletonModel::applyPalmData(int jointIndex, const QVector<int>& fingertipJointIndices, PalmData& palm) { void SkeletonModel::applyPalmData(int jointIndex, const QVector<int>& fingertipJointIndices, PalmData& palm) {
setJointPosition(jointIndex, palm.getPosition()); setJointPosition(jointIndex, palm.getPosition());
setJointRotation(jointIndex, rotationBetween(_rotation * IDENTITY_UP, palm.getNormal()) * _rotation * setJointRotation(jointIndex, rotationBetween(_rotation * IDENTITY_UP, -palm.getNormal()) * _rotation *
glm::angleAxis(90.0f, 0.0f, jointIndex == _geometry->getFBXGeometry().rightHandJointIndex ? 1.0f : -1.0f, 0.0f), true); glm::angleAxis(90.0f, 0.0f, jointIndex == _geometry->getFBXGeometry().rightHandJointIndex ? 1.0f : -1.0f, 0.0f), true);
// no point in continuing if there are no fingers // no point in continuing if there are no fingers

View file

@ -218,7 +218,7 @@ void LeapManager::nextFrame(Avatar& avatar) {
// Simulated data // Simulated data
palm.setRawPosition(glm::vec3( 0.0f, 0.0f, 0.0f) + fakeHandOffsets[i]); palm.setRawPosition(glm::vec3( 0.0f, 0.0f, 0.0f) + fakeHandOffsets[i]);
palm.setRawNormal(glm::vec3(0.0f, 1.0f, 0.0f)); palm.setRawNormal(glm::vec3(0.0f, -1.0f, 0.0f));
for (size_t f = 0; f < palm.getNumFingers(); ++f) { for (size_t f = 0; f < palm.getNumFingers(); ++f) {
FingerData& finger = palm.getFingers()[f]; FingerData& finger = palm.getFingers()[f];