Skip to content

Commit

Permalink
Merging, adding gamepad
Browse files Browse the repository at this point in the history
  • Loading branch information
deanputney committed Nov 14, 2013
1 parent c8e7d1c commit 13a5d9b
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
59 changes: 59 additions & 0 deletions hotkeys.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,62 @@ resetCameraRot = function()
camera.rotation.y = 0;
camera.rotation.z = 0;
}




/* Gamepad binding */

var gamepad = new Gamepad();

console.log('binding down');
gamepad.bind(Gamepad.Event.BUTTON_DOWN, function(e) {
switch(e.control){
case 'Y':
game.BARS.toggleWireframe();
break;
case 'X':
game.BARS.toggleWireframe();
break;
case 'B':
console.log('color shift');
game.BARS.colorset.push(game.BARS.colorset.shift());
for(var xpos = 0; xpos < 12; xpos++ ){
game.BARS.objects[xpos].material = new THREE.MeshBasicMaterial( { color: game.BARS.colorset[xpos], wireframe: false, wireframeLinewidth: 3, overdraw: true } );
}
break;
case 'BACK':
window.location = window.location;
break;
}
});

gamepad.bind(Gamepad.Event.BUTTON_UP, function(e) {
switch(e.control){
case 'X':
game.BARS.toggleWireframe();
break;
case 'RB':
for(b in game.BARS.objects) {
game.BARS.objects[b].rotation.x += b/game.BARS.objects.length;
}
break;
case 'LB':
for(b in game.BARS.objects) {
game.BARS.objects[b].rotation.x -= b/game.BARS.objects.length;
}
break;
case 'DPAD_UP':
game.BARS.rotation.speed += 0.01;
break;
case 'DPAD_DOWN':
game.BARS.rotation.speed -= 0.01;
break;
case 'DPAD_RIGHT':
camera.orbit.speed += 10;
break;
case 'DPAD_LEFT':
camera.orbit.speed -= 10;
break;
}
});
7 changes: 6 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

<script src="js/jquery.min.js"></script>
<script src="js/jquery.hotkeys.js"></script>
<script src="js/gamepad.js"></script>

<script src="js/three.min.js"></script>

Expand Down Expand Up @@ -53,9 +54,13 @@
blackAndWhite: false,
colorSetNumber: 0
}
$(document).ready(function()
{
if (!gamepad.init()) {
alert('Your browser does not support gamepads, get the latest Google Chrome or Firefox.');
}

init();
animate();
})
Expand Down

0 comments on commit 13a5d9b

Please sign in to comment.