diff --git a/interface/src/avatar/SkeletonModel.cpp b/interface/src/avatar/SkeletonModel.cpp index 7da4cf14b8..e7772e5cce 100644 --- a/interface/src/avatar/SkeletonModel.cpp +++ b/interface/src/avatar/SkeletonModel.cpp @@ -148,14 +148,26 @@ void SkeletonModel::applyPalmData(int jointIndex, const QVector& fingerJoin return; } - // sort the finger indices by raw x + // sort the finger indices by raw x, get the average direction QVector fingerIndices; + glm::vec3 direction; for (int i = 0; i < palm.getNumFingers(); i++) { + glm::vec3 fingerVector = palm.getFingers()[i].getTipPosition() - palm.getFingers()[i].getRootPosition(); + float length = glm::length(fingerVector); + if (length > EPSILON) { + direction += fingerVector / length; + } IndexValue indexValue = { i, palm.getFingers()[i].getTipRawPosition().x }; fingerIndices.append(indexValue); } qSort(fingerIndices.begin(), fingerIndices.end()); + // rotate palm according to average finger direction + float directionLength = glm::length(direction); + if (directionLength > EPSILON) { + palmRotation = rotationBetween(palmRotation * glm::vec3(sign, 0.0f, 0.0f), direction) * palmRotation; + } + // match them up as best we can float proportion = fingerIndices.size() / (float)fingerJointIndices.size(); for (int i = 0; i < fingerJointIndices.size(); i++) {