Add support for newer Gamepad API. Fix left stick handling.
This commit is contained in:
@@ -26,11 +26,16 @@ class GamepadController
|
||||
return false if not gamepads?[0]
|
||||
gp = gamepads[0]
|
||||
return if not gp.buttons? or not gp.axes?
|
||||
@acceleration = gp.buttons[0]
|
||||
@lstickx = gp.axes[0]
|
||||
@ltrigger = gp.buttons[6]
|
||||
@rtrigger = gp.buttons[7]
|
||||
@select = gp.buttons[8]
|
||||
accel = gp.buttons[0]
|
||||
lt = gp.buttons[6]
|
||||
rt = gp.buttons[7]
|
||||
sel = gp.buttons[8]
|
||||
# API fallback
|
||||
@acceleration = accel.pressed ? accel
|
||||
@ltrigger = lt.pressed ? lt
|
||||
@rtrigger = rt.pressed ? rt
|
||||
@select = sel.pressed ? sel
|
||||
@buttonPressCallback this
|
||||
true
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
|
||||
|
||||
GamepadController.prototype.updateAvailable = function() {
|
||||
var gamepads, gp;
|
||||
var accel, gamepads, gp, lt, rt, sel, _ref, _ref1, _ref2, _ref3;
|
||||
if (!this.active) {
|
||||
return false;
|
||||
}
|
||||
@@ -45,11 +45,15 @@
|
||||
if ((gp.buttons == null) || (gp.axes == null)) {
|
||||
return;
|
||||
}
|
||||
this.acceleration = gp.buttons[0];
|
||||
this.lstickx = gp.axes[0];
|
||||
this.ltrigger = gp.buttons[6];
|
||||
this.rtrigger = gp.buttons[7];
|
||||
this.select = gp.buttons[8];
|
||||
accel = gp.buttons[0];
|
||||
lt = gp.buttons[6];
|
||||
rt = gp.buttons[7];
|
||||
sel = gp.buttons[8];
|
||||
this.acceleration = (_ref = accel.pressed) != null ? _ref : accel;
|
||||
this.ltrigger = (_ref1 = lt.pressed) != null ? _ref1 : lt;
|
||||
this.rtrigger = (_ref2 = rt.pressed) != null ? _ref2 : rt;
|
||||
this.select = (_ref3 = sel.pressed) != null ? _ref3 : sel;
|
||||
this.buttonPressCallback(this);
|
||||
return true;
|
||||
};
|
||||
|
||||
@@ -386,17 +386,17 @@ bkcore.hexgl.ShipControls.prototype.update = function(dt)
|
||||
angularAmount -= this.touchController.stickVector.x/100 * this.angularSpeed * dt;
|
||||
rollAmount += this.touchController.stickVector.x/100 * this.rollAngle;
|
||||
}
|
||||
if(this.orientationController != null)
|
||||
else if(this.orientationController != null)
|
||||
{
|
||||
angularAmount += this.orientationController.beta/45 * this.angularSpeed * dt;
|
||||
rollAmount -= this.orientationController.beta/45 * this.rollAngle;
|
||||
}
|
||||
if(this.gamepadController != null && this.gamepadController.updateAvailable())
|
||||
else if(this.gamepadController != null && this.gamepadController.updateAvailable())
|
||||
{
|
||||
angularAmount -= this.gamepadController.lstickx * 0.2 * this.angularSpeed * dt;
|
||||
angularAmount -= this.gamepadController.lstickx * this.angularSpeed * dt;
|
||||
rollAmount += this.gamepadController.lstickx * this.rollAngle;
|
||||
}
|
||||
if(this.leapBridge != null && this.leapBridge.hasHands)
|
||||
else if(this.leapBridge != null && this.leapBridge.hasHands)
|
||||
{
|
||||
angularAmount += this.leapBridge.palmNormal[0] * 2 * this.angularSpeed * dt;
|
||||
this.speed += Math.max(0.0, (0.5 + this.leapBridge.palmNormal[2])) * 3 * this.thrust * dt;
|
||||
|
||||
Reference in New Issue
Block a user