From 151a907e7702a498c91a83b284681273b3e65915 Mon Sep 17 00:00:00 2001 From: joni <johnfshaughnessy@gmail.com> Date: Thu, 10 May 2018 17:33:19 -0700 Subject: [PATCH] Add deadzone as a behaviour for filtering axismove events on the msft mr controllers. --- src/behaviours/msft-mr-axis-with-deadzone.js | 26 ++++++++++++++++++++ src/hub.js | 2 ++ src/input-mappings.js | 5 ++-- 3 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 src/behaviours/msft-mr-axis-with-deadzone.js 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 000000000..6a1bb9d1e --- /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 80741c2e1..67aa64730 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 5413bbac7..a1c4c06a2 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", -- GitLab