Skip to content

Commit

Permalink
Merge branch 'master' into gh-pages
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandrevicenzi committed Jul 1, 2015
2 parents 6a1e9f1 + f15f5df commit 6af9bda
Show file tree
Hide file tree
Showing 9 changed files with 249 additions and 328 deletions.
1 change: 0 additions & 1 deletion bower.json
Expand Up @@ -23,7 +23,6 @@
"tests"
],
"dependencies": {
"underscore-min": "http://underscorejs.org/underscore-min.js",
"jquery-2.1.4.min": "http://code.jquery.com/jquery-2.1.4.min.js",
"leap-0.6.4.min": "http://js.leapmotion.com/leap-0.6.4.min.js",
"leap-plugins-0.1.10.min": "http://js.leapmotion.com/leap-plugins-0.1.10.min.js",
Expand Down
15 changes: 5 additions & 10 deletions gulpfile.js
Expand Up @@ -17,7 +17,6 @@ gulp.task('vendor', function() {
gulp.task('main', function() {
gulp.src([
'js/leap-extras.js',
'js/threejs-position.js',
'js/marionette-drawer.js',
'js/app.js'
])
Expand All @@ -27,14 +26,10 @@ gulp.task('main', function() {
.pipe(gulp.dest('dist/js'));
});

gulp.task('model', function() {
gulp.src(['models/*.json'])
.pipe(gulp.dest('dist/models'));
});

gulp.task('img', function() {
gulp.src(['images/*.png'])
.pipe(gulp.dest('dist/images'));
gulp.task('cp', function() {
gulp.src(['models/*.json']).pipe(gulp.dest('dist/models'));
gulp.src(['images/*.png']).pipe(gulp.dest('dist/images'));
gulp.src(['sounds/*.mp3']).pipe(gulp.dest('dist/sounds'));
});

gulp.task('css', function() {
Expand All @@ -56,4 +51,4 @@ gulp.task('replace', function() {

gulp.task('js', ['vendor', 'main']);

gulp.task('default', ['js', 'css', 'replace', 'model', 'img']);
gulp.task('default', ['js', 'css', 'replace', 'cp']);
3 changes: 1 addition & 2 deletions index.html
Expand Up @@ -6,7 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">

<!--<meta http-equiv="refresh" content="0;URL=/setup.html">-->
<title>Marionette Wireless</title>

<!-- build:css -->
Expand All @@ -24,7 +24,6 @@
<script type="text/javascript" src="bower_components/three.min/index.js"></script>
<script type="text/javascript" src="bower_components/threejs-stats/Stats.js"></script>

<script type="text/javascript" src="js/threejs-position.js"></script>
<script type="text/javascript" src="js/leap-extras.js"></script>
<script type="text/javascript" src="js/marionette-drawer.js"></script>
<script type="text/javascript" src="js/app.js"></script>
Expand Down
48 changes: 33 additions & 15 deletions js/app.js
@@ -1,45 +1,63 @@
var drawer;

function rotateRadian(radian){
if (radian < 0) {
return radian - Math.PI;
} else {
return radian + Math.PI;
}
}

function moveObject(hand) {
if (hand && (hand.timeVisible > .25) && (hand.confidence > .7)) {
var pitch = hand.pitchDegree(),
roll = hand.rollDegree(),
yaw = hand.yawDegree(),
p = hand.get3JsScreenPosition();
if (hand && (hand.timeVisible > 0.25) && (hand.confidence > 0.7)) {
var pitch = hand.pitch(),
roll = hand.roll() * -1,
yaw = hand.yaw() * -1,
p = {
x: hand.stabilizedPalmPosition[0],
y: hand.stabilizedPalmPosition[1],
z: hand.stabilizedPalmPosition[2]
};

drawer.moveObject(hand.type, p.x, p.y, p.z);
drawer.rotateObject(hand.type, pitch * -1, yaw, roll);
drawer.rotateObject(hand.type, pitch, rotateRadian(yaw), roll);
}
}

$(document).ready(function () {
drawer = new MarionetteDrawer();
drawer.init(document.getElementById('container'));
drawer.addScenario();
drawer.setup();
drawer.setupStats();
drawer.setBackground();
drawer.animate();

var controller = new Leap.Controller();

controller.use('screenPosition')
controller.use('screenPosition', {
scale: 0.25
})
.use('handEntry')
.use('threejsPosition')
.use('leapExtras');
.use('leapExtras')
.use('boneHand', {
scene: drawer.scene,
targetEl: document.body,
arm: false
});

controller.on('frame', function (frame) {
moveObject(frame.getLeftHand());
moveObject(frame.getRightHand());
});

controller.on('handFound', function (hand) {
var p = hand.screenPosition();
if (hand.type === 'left') {
drawer.addHorse(hand.type);
drawer.addHorse(hand.type, p.x, p.y, p.z);
} else if (hand.type == 'right') {
drawer.addFlamingo(hand.type);
drawer.addFlamingo(hand.type, p.x, p.y, p.z);
} else {
drawer.addCube(hand.type);
}

drawer.moveObject(hand.type);
});

controller.on('handLost', function (hand) {
Expand Down
42 changes: 2 additions & 40 deletions js/leap-extras.js
@@ -1,52 +1,14 @@
Leap.Controller.plugin('leapExtras', function() {

function radians2degrees(radians) {
return radians * (180 / Math.PI);
}

return {
frame: {
getHandsCount: function () {
return this.hands.length;
},

getFingersCount: function () {
return _.reduce(this.hands, function (memo, hand) {
return memo + hand.fingers.length;
}, 0);
},

getExtendedFingersCount: function () {
return _.reduce(this.hands, function (memo, hand) {
return memo + _.filter(hand.fingers, function (finger) { return finger.extended }).length;
}, 0);
},

getLeftHand: function () {
return _.findWhere(this.hands, { type: 'left' });
return $.grep(this.hands, function (hand){ return hand.type === 'left'; })[0];
},

getRightHand: function () {
return _.findWhere(this.hands, { type: 'right' });
return $.grep(this.hands, function (hand){ return hand.type === 'right' })[0];
},

getFrameRate: function () {
return this.currentFrameRate;
}
},

hand: {
pitchDegree: function () {
return radians2degrees(this.pitch());
},

rollDegree: function () {
return radians2degrees(this.roll());
},

yawDegree: function () {
return radians2degrees(this.yaw());
}
}
};
});

0 comments on commit 6af9bda

Please sign in to comment.