Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wip] Add Hand Splay #13

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Gruntfile.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ module.exports = (grunt) ->
grunt.initConfig
pkg: grunt.file.readJSON("package.json")

watch:
options:
livereload: true
js:
files: ['main/**/*.coffee', 'main/**/*.html'],
tasks: ['default'],
options:
spawn: false

coffee:
main:
files: [{
Expand Down
2 changes: 1 addition & 1 deletion extras/leap-plugins-0.1.4-extras.min.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* LeapJS-Plugins Extra - v0.1.4 - 2014-04-08
* LeapJS-Plugins Extra - v0.1.4 - 2014-04-27
* http://github.com/leapmotion/leapjs-plugins/
*
* Copyright 2014 LeapMotion, Inc
Expand Down
47 changes: 47 additions & 0 deletions main/hand-splay/leap.hand-splay.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# measures how spread out and flat a hand is
# fires 'handSplay' and 'handUnsplay' events from the controller
#
# Two items are made accessible through hand.data
# hand.data('handSplay.splay') returns the fractional splay amount, 0 to 1
# hand.data('handSplay.splayed') returns a boolean: whether the hand is considered splayed or not

Leap.Controller.plugin 'handSplay', (scope = {})->
scope.splayThreshold ||= 0.65
scope.requiredFingers ||= 4

@use('handHold')

{
hand: (hand)->
palmDot = null
avgPalmDot = 0
straightenedFingerCount = 0

# set base data, find minimum
for finger in hand.fingers
palmDot = Leap.vec3.dot( hand.direction, finger.direction )
avgPalmDot += palmDot

if palmDot > scope.splayThreshold
straightenedFingerCount++

# v1 tracking backwards compatibility
# missing fingers treated as mid-curl
avgPalmDot += 0.5 * (5 - hand.fingers.length)

avgPalmDot /= 5

hand.data('handSplay.splay', avgPalmDot)
hand.data('handSplay.splayedFingers', straightenedFingerCount)

if avgPalmDot > scope.splayThreshold || straightenedFingerCount >= scope.requiredFingers
unless hand.data('handSplay.splayed')
hand.data('handSplay.splayed': true)
@emit('handSplay', hand)

else
if hand.data('handSplay.splayed')
@emit('handUnsplay', hand)
hand.data('handSplay.splayed': false)

}
48 changes: 48 additions & 0 deletions main/hand-splay/leap.hand-splay.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//CoffeeScript generated from main/hand-splay/leap.hand-splay.coffee
(function() {
Leap.Controller.plugin('handSplay', function(scope) {
if (scope == null) {
scope = {};
}
scope.splayThreshold || (scope.splayThreshold = 0.65);
scope.requiredFingers || (scope.requiredFingers = 4);
this.use('handHold');
return {
hand: function(hand) {
var avgPalmDot, finger, palmDot, straightenedFingerCount, _i, _len, _ref;
palmDot = null;
avgPalmDot = 0;
straightenedFingerCount = 0;
_ref = hand.fingers;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
finger = _ref[_i];
palmDot = Leap.vec3.dot(hand.direction, finger.direction);
avgPalmDot += palmDot;
if (palmDot > scope.splayThreshold) {
straightenedFingerCount++;
}
}
avgPalmDot += 0.5 * (5 - hand.fingers.length);
avgPalmDot /= 5;
hand.data('handSplay.splay', avgPalmDot);
hand.data('handSplay.splayedFingers', straightenedFingerCount);
if (avgPalmDot > scope.splayThreshold || straightenedFingerCount >= scope.requiredFingers) {
if (!hand.data('handSplay.splayed')) {
hand.data({
'handSplay.splayed': true
});
return this.emit('handSplay', hand);
}
} else {
if (hand.data('handSplay.splayed')) {
this.emit('handUnsplay', hand);
return hand.data({
'handSplay.splayed': false
});
}
}
}
};
});

}).call(this);
40 changes: 40 additions & 0 deletions main/hand-splay/test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<html>
<head>
<title>Hand Splay</title>
<script src="//js.leapmotion.com/leap-0.6.0-beta2.min.js"></script>
<script src="../hand-hold/leap.hand-hold.js"></script>
<script src="leap.hand-splay.js"></script>

<script type="text/javascript">
Leap.loop({
hand: function(hand){
document.getElementById('out').innerHTML = hand.data('handSplay.splay').toPrecision(2);
}
})
.use('handSplay')
.on('handSplay', function(hand){

console.log('splay',
hand.data('handSplay.splay') > Leap.loopController.plugins.handSplay.splayThreshold,
hand.data('handSplay.splayedFingers') >= Leap.loopController.plugins.handSplay.requiredFingers
);

// use timer to log quickly-flipping-back-and-forth
console.time('splay')
})
.on('handUnsplay', function(hand){

console.log('unsplay',
hand.data('handSplay.splay') > Leap.loopController.plugins.handSplay.splayThreshold,
hand.data('handSplay.splayedFingers') >= Leap.loopController.plugins.handSplay.requiredFingers
);

console.timeEnd('splay')
});
</script>
</head>

<body>
<div id="out"></div>
</body>
</html>
52 changes: 48 additions & 4 deletions main/leap-plugins-0.1.4.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* LeapJS-Plugins - v0.1.4 - 2014-04-08
* LeapJS-Plugins - v0.1.4 - 2014-04-27
* http://github.com/leapmotion/leapjs-plugins/
*
* Copyright 2014 LeapMotion, Inc
Expand Down Expand Up @@ -157,10 +157,54 @@ Each event also includes the hand object, which will be invalid for the handLost

}).call(this);

//CoffeeScript generated from main/hand-splay/leap.hand-splay.coffee
(function() {
Leap.Controller.plugin('handSplay', function(scope) {
if (scope == null) {
scope = {};
}
scope.splayThreshold || (scope.splayThreshold = 0.65);
scope.requiredFingers || (scope.requiredFingers = 4);
this.use('handHold');
return {
hand: function(hand) {
var avgPalmDot, finger, palmDot, straightenedFingerCount, _i, _len, _ref;
palmDot = null;
avgPalmDot = 0;
straightenedFingerCount = 0;
_ref = hand.fingers;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
finger = _ref[_i];
palmDot = Leap.vec3.dot(hand.direction, finger.direction);
avgPalmDot += palmDot;
if (palmDot > scope.splayThreshold) {
straightenedFingerCount++;
}
}
avgPalmDot += 0.5 * (5 - hand.fingers.length);
avgPalmDot /= 5;
hand.data('handSplay.splay', avgPalmDot);
hand.data('handSplay.splayedFingers', straightenedFingerCount);
if (avgPalmDot > scope.splayThreshold || straightenedFingerCount >= scope.requiredFingers) {
if (!hand.data('handSplay.splayed')) {
hand.data({
'handSplay.splayed': true
});
return this.emit('handSplay', hand);
}
} else {
if (hand.data('handSplay.splayed')) {
this.emit('handUnsplay', hand);
return hand.data({
'handSplay.splayed': false
});
}
}
}
};
});




}).call(this);


(function () {
Expand Down
6 changes: 3 additions & 3 deletions main/leap-plugins-0.1.4.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions main/playback/leap-playback-0.1.js

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
"dependencies": {},
"devDependencies": {
"coffee-script": ">=1.7.1",
"grunt-contrib-concat": "~0.3.0",
"grunt-contrib-uglify": "~0.3.2",
"grunt-contrib-coffee": "~0.8.2",
"grunt-banner": "git://github.com/pehrlich/grunt-banner.git",
"grunt-contrib-clean": "~0.5.0",
"grunt": "~0.4.2",
"grunt-banner": "git://github.com/pehrlich/grunt-banner.git",
"grunt-bump": "0.0.13",
"grunt-contrib-clean": "~0.5.0",
"grunt-contrib-coffee": "~0.8.2",
"grunt-contrib-concat": "~0.3.0",
"grunt-contrib-uglify": "~0.3.2",
"grunt-contrib-watch": "^0.6.1",
"load-grunt-tasks": "~0.4.0"
},
"repository": {
Expand Down