Created
October 30, 2017 12:23
-
-
Save petecleary/cf4af55fa47a6134db9d1a1f7fa3b61c to your computer and use it in GitHub Desktop.
Leap Motion JavaScript hand position. Simple method to collect the palm position of the first hand on every leap motion frame loop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var handPos = { handId: '', normX: 0, normY: 0, normZ: 0, posX: 0, posY: 0, posZ: 0, rotX: 0, rotY: 0, rotZ: 0, set: false }; | |
Leap.loop(function (frame) { | |
var handIds = {}; | |
if (frame.hands === undefined) { | |
var handsLength = 0 | |
} else { | |
var handsLength = frame.hands.length; | |
} | |
var firstHand = true; | |
for (var handId = 0, handCount = handsLength; handId != handCount; handId++) { | |
var hand = frame.hands[handId]; | |
if (firstHand) { | |
var interactionBox = frame.interactionBox; | |
var normalizedPosition = interactionBox.normalizePoint(hand.palmPosition, true); | |
// Convert the normalized coordinates to span the canvas | |
handPos.normX = normalizedPosition[0]; | |
handPos.normY = normalizedPosition[2]; | |
handPos.normZ = normalizedPosition[1]; | |
handPos.handId = handId; | |
handPos.posX = (hand.palmPosition[0] * 3); | |
handPos.posY = (hand.palmPosition[2] * 3) - 200; | |
handPos.posZ = (hand.palmPosition[1] * 3) - 400; | |
handPos.rotX = (hand._rotation[2] * 90); | |
handPos.rotY = (hand._rotation[1] * 90); | |
handPos.rotZ = (hand._rotation[0] * 90); | |
handPos.set = true; | |
firstHand = false; | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment