Merge pull request #3566 from ctrlaltdavid/leap-finger-fixes

Leap finger fixes
This commit is contained in:
AndrewMeadows 2014-10-09 08:11:30 -07:00
commit acaff7ea13

View file

@ -23,7 +23,7 @@ var leapHands = (function () {
fingers, fingers,
NUM_FINGERS = 5, // 0 = thumb; ...; 4 = pinky NUM_FINGERS = 5, // 0 = thumb; ...; 4 = pinky
THUMB = 0, THUMB = 0,
NUM_FINGER_JOINTS = 3, // 0 = metacarpal(hand)-proximal(finger) joint; ...; 2 = intermediate-distal(tip) joint NUM_FINGER_JOINTS = 3, // 0 = metacarpal(hand)-proximal(finger) joint; ...; 2 = intermediate-distal joint
MAX_HAND_INACTIVE_COUNT = 20, MAX_HAND_INACTIVE_COUNT = 20,
calibrationStatus, calibrationStatus,
UNCALIBRATED = 0, UNCALIBRATED = 0,
@ -226,8 +226,6 @@ var leapHands = (function () {
function setUp() { function setUp() {
// TODO: Leap Motion controller joint naming doesn't match up with skeleton joint naming; numbers are out by 1.
hands = [ hands = [
{ {
jointName: "LeftHand", jointName: "LeftHand",
@ -246,6 +244,9 @@ var leapHands = (function () {
{ controller: Controller.createInputController("Spatial", "joint_R_wrist") } { controller: Controller.createInputController("Spatial", "joint_R_wrist") }
]; ];
// The Leap controller's first joint is the hand-metacarpal joint but this joint's data is not used because it's too
// dependent on the model skeleton exactly matching the Leap skeleton; using just the second and subsequent joints
// seems to work better over all.
fingers = [{}, {}]; fingers = [{}, {}];
fingers[0] = [ fingers[0] = [
[ [
@ -407,19 +408,26 @@ var leapHands = (function () {
MyAvatar.setJointModelPositionAndOrientation(hands[h].jointName, handOffset, handRotation, true); MyAvatar.setJointModelPositionAndOrientation(hands[h].jointName, handOffset, handRotation, true);
// Finger joints ... // Finger joints ...
// TODO: 2.0 * scale factors should not be necessary; Leap Motion controller code needs investigating.
for (i = 0; i < NUM_FINGERS; i += 1) { for (i = 0; i < NUM_FINGERS; i += 1) {
for (j = 0; j < NUM_FINGER_JOINTS; j += 1) { for (j = 0; j < NUM_FINGER_JOINTS; j += 1) {
if (fingers[h][i][j].controller !== null) { if (fingers[h][i][j].controller !== null) {
locRotation = fingers[h][i][j].controller.getLocRotation(); locRotation = fingers[h][i][j].controller.getLocRotation();
if (i === THUMB) { if (i === THUMB) {
MyAvatar.setJointData(fingers[h][i][j].jointName, locRotation = {
Quat.fromPitchYawRollRadians(2.0 * side * locRotation.y, 2.0 * -locRotation.z, x: side * locRotation.y,
2.0 * side * -locRotation.x)); y: side * -locRotation.z,
z: side * -locRotation.x,
w: locRotation.w
};
} else { } else {
MyAvatar.setJointData(fingers[h][i][j].jointName, locRotation = {
Quat.fromPitchYawRollRadians(2.0 * -locRotation.x, 0.0, 2.0 * -locRotation.y)); x: -locRotation.x,
y: -locRotation.z,
z: -locRotation.y,
w: locRotation.w
};
} }
MyAvatar.setJointData(fingers[h][i][j].jointName, locRotation);
} }
} }
} }