Skip to content

Instantly share code, notes, and snippets.

@nervetattoo
Last active December 20, 2015 17:09
Show Gist options
  • Save nervetattoo/6166440 to your computer and use it in GitHub Desktop.
Save nervetattoo/6166440 to your computer and use it in GitHub Desktop.
How to handle left/right/up/down swipes for the Leap Motion controller
require.config({
paths: {
leap : '//js.leapmotion.com/0.2.0/leap'
},
shim: {
exports: 'Leap'
}
});
define(['leap'], function(Leap) {
Leap.loop();
});
Leap.loop({enableGestures: true}, function(frame)
{
if (frame.gestures.length > 0) {
var g = frame.gestures[0];
if (g.type === 'swipe' && g.state === 'stop') {
// Get the absolute movement along the x and y axis
var xMov = Math.abs(g.direction[0]);
var yMov = Math.abs(g.direction[1]);
if (xMov > 0.3) {
if (g.direction[0] < 0) {
onLeftSwipe();
}
else {
onRightSwipe();
}
}
else if (yMov > 0.3) {
if (g.direction[1] < 0) {
onDownSwipe();
}
else {
onUpSwipe();
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment