diff --git a/src/behaviours/msft-mr-axis-with-deadzone.js b/src/behaviours/msft-mr-axis-with-deadzone.js new file mode 100644 index 0000000000000000000000000000000000000000..6a1bb9d1e0c8837544cac7f92b70e0ece3bfc1eb --- /dev/null +++ b/src/behaviours/msft-mr-axis-with-deadzone.js @@ -0,0 +1,26 @@ +function msft_mr_axis_with_deadzone(el, outputPrefix) { + this.el = el; + this.outputPrefix = outputPrefix; + this.deadzone = 0.01; + this.emitAxisMoveWithDeadzone = this.emitAxisMoveWithDeadzone.bind(this); +} + +msft_mr_axis_with_deadzone.prototype = { + addEventListeners: function() { + this.el.addEventListener("axismove", this.emitAxisMoveWithDeadzone); + }, + removeEventListeners: function() { + this.el.removeEventListener("axismove", this.emitAxisMoveWithDeadzone); + }, + emitAxisMoveWithDeadzone: function(event) { + const axis = event.detail.axis; + if (Math.abs(axis[0]) < this.deadzone && Math.abs(axis[1]) < this.deadzone) { + return; + } + // Reverse y + axis[1] = -axis[1]; + this.el.emit("axisMoveWithDeadzone", event.detail); + } +}; + +export default msft_mr_axis_with_deadzone; diff --git a/src/hub.js b/src/hub.js index 80741c2e11939461503bb57cd99a1cee97a0ee75..67aa647307f5d2fd3838cc3d9166e97e186aca34 100644 --- a/src/hub.js +++ b/src/hub.js @@ -23,6 +23,7 @@ import "./utils/audio-context-fix"; import trackpad_dpad4 from "./behaviours/trackpad-dpad4"; import joystick_dpad4 from "./behaviours/joystick-dpad4"; +import msft_mr_axis_with_deadzone from "./behaviours/msft-mr-axis-with-deadzone"; import { PressedMove } from "./activators/pressedmove"; import { ReverseY } from "./activators/reversey"; import "./activators/shortpress"; @@ -126,6 +127,7 @@ registerTelemetry(); AFRAME.registerInputBehaviour("trackpad_dpad4", trackpad_dpad4); AFRAME.registerInputBehaviour("joystick_dpad4", joystick_dpad4); +AFRAME.registerInputBehaviour("msft_mr_axis_with_deadzone", msft_mr_axis_with_deadzone); AFRAME.registerInputActivator("pressedmove", PressedMove); AFRAME.registerInputActivator("reverseY", ReverseY); AFRAME.registerInputMappings(inputConfig, true); diff --git a/src/input-mappings.js b/src/input-mappings.js index 5413bbac75868938b92986d40c2e2aa21f0effb2..a1c4c06a2d7cf1f8442b81fee5cfa25821af90b5 100644 --- a/src/input-mappings.js +++ b/src/input-mappings.js @@ -27,7 +27,8 @@ const config = { trackpad: "trackpad_dpad4" }, "windows-motion-controls": { - joystick: "joystick_dpad4" + joystick: "joystick_dpad4", + axisMoveWithDeadzone: "msft_mr_axis_with_deadzone" }, "daydream-controls": { trackpad: "trackpad_dpad4" @@ -106,7 +107,7 @@ const config = { trackpadtouchend: "thumb_up", triggerdown: ["action_grab", "index_down"], triggerup: ["action_release", "index_up"], - "axismove.reverseY": { left: "move" } + axisMoveWithDeadzone: { left: "move" } }, "daydream-controls": { trackpad_dpad4_pressed_west_down: "snap_rotate_left",