diff --git a/src/behaviours/joystick-dpad4.js b/src/behaviours/joystick-dpad4.js deleted file mode 100644 index 0eae7e1d194dfb6f207da53a7499caaf8e483c02..0000000000000000000000000000000000000000 --- a/src/behaviours/joystick-dpad4.js +++ /dev/null @@ -1,34 +0,0 @@ -import { angleTo4Direction } from "../utils/dpad"; - -// @TODO specify 4 or 8 direction -function joystick_dpad4(el, outputPrefix) { - this.angleToDirection = angleTo4Direction; - this.outputPrefix = outputPrefix; - this.centerRadius = 0.6; - this.previous = "none"; - this.hapticIntensity = "low"; - this.emitDPad4 = this.emitDPad4.bind(this); - this.el = el; -} - -joystick_dpad4.prototype = { - addEventListeners: function() { - this.el.addEventListener("axismove", this.emitDPad4); - }, - removeEventListeners: function() { - this.el.removeEventListener("axismove", this.emitDPad4); - }, - emitDPad4: function(event) { - const x = event.detail.axis[0]; - const y = event.detail.axis[1]; - const inCenter = Math.abs(x) < this.centerRadius && Math.abs(y) < this.centerRadius; - const current = inCenter ? "center" : this.angleToDirection(Math.atan2(x, -y)); - if (current !== this.previous) { - this.previous = current; - event.target.emit(`${this.outputPrefix}_dpad4_${current}`); - event.target.emit("haptic_pulse", { intensity: this.hapticIntensity }); - } - } -}; - -export default joystick_dpad4; diff --git a/src/behaviours/msft-mr-axis-with-deadzone.js b/src/behaviours/msft-mr-axis-with-deadzone.js deleted file mode 100644 index c2b86fe8b5a0b645572a6bf27a2dfceb0449187b..0000000000000000000000000000000000000000 --- a/src/behaviours/msft-mr-axis-with-deadzone.js +++ /dev/null @@ -1,26 +0,0 @@ -function msft_mr_axis_with_deadzone(el, outputPrefix) { - this.el = el; - this.outputPrefix = outputPrefix; - this.deadzone = 0.1; - 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/behaviours/trackpad-dpad4.js b/src/behaviours/trackpad-dpad4.js deleted file mode 100644 index f15908d34d5854d60ae158af7026007745293dfb..0000000000000000000000000000000000000000 --- a/src/behaviours/trackpad-dpad4.js +++ /dev/null @@ -1,62 +0,0 @@ -import { angleTo4Direction } from "../utils/dpad"; - -function trackpad_dpad4(el, outputPrefix) { - this.outputPrefix = outputPrefix; - this.lastDirection = ""; - this.previous = ""; - this.pressed = false; - this.emitDPad4 = this.emitDPad4.bind(this); - this.press = this.press.bind(this); - this.unpress = this.unpress.bind(this); - this.hapticIntensity = "low"; - this.centerRadius = 0.6; - this.el = el; -} - -trackpad_dpad4.prototype = { - addEventListeners: function() { - this.el.addEventListener("axismove", this.emitDPad4); - this.el.addEventListener("trackpaddown", this.press); - this.el.addEventListener("trackpadup", this.unpress); - }, - removeEventListeners: function() { - this.el.removeEventListener("axismove", this.emitDPad4); - this.el.removeEventListener("trackpaddown", this.press); - this.el.removeEventListener("trackpadup", this.unpress); - }, - press: function() { - this.pressed = true; - }, - unpress: function() { - this.pressed = false; - }, - emitDPad4: function(event) { - const x = event.detail.axis[0]; - const y = event.detail.axis[1]; - const inCenter = Math.abs(x) < this.centerRadius && Math.abs(y) < this.centerRadius; - const direction = inCenter ? "center" : angleTo4Direction(Math.atan2(x, -y)); - const pressed = this.pressed ? "pressed_" : ""; - const current = `${pressed + direction}`; // e.g. "pressed_north" - - // Real axismove events are not perfectly [0,0]... - // This is a touchend event. - if (x === 0 && y === 0) { - event.target.emit(`${this.outputPrefix}_dpad4_${this.previous}_up`); - this.previous = ""; // Clear this because the user has lifted their finger. - return; - } - - if (current === this.previous) { - return; - } - - if (this.previous !== "") { - event.target.emit(`${this.outputPrefix}_dpad4_${this.previous}_up`); - } - - event.target.emit(`${this.outputPrefix}_dpad4_${current}_down`); - this.previous = current; - } -}; - -export default trackpad_dpad4; diff --git a/src/behaviours/trackpad-scrolling.js b/src/behaviours/trackpad-scrolling.js deleted file mode 100644 index 8cb5baf9502b697141b434499525b5c40e63e555..0000000000000000000000000000000000000000 --- a/src/behaviours/trackpad-scrolling.js +++ /dev/null @@ -1,56 +0,0 @@ -function trackpad_scrolling(el) { - this.el = el; - this.start = "trackpadtouchstart"; - this.move = "axismove"; - this.end = "trackpadtouchend"; - this.isScrolling = false; - this.x = -10; - this.y = -10; - this.axis = [0, 0]; - this.emittedEventDetail = { detail: { axis: this.axis } }; - - this.onStart = this.onStart.bind(this); - this.onMove = this.onMove.bind(this); - this.onEnd = this.onEnd.bind(this); -} - -trackpad_scrolling.prototype = { - addEventListeners: function() { - this.el.addEventListener(this.start, this.onStart); - this.el.addEventListener(this.move, this.onMove); - this.el.addEventListener(this.end, this.onEnd); - }, - removeEventListeners: function() { - this.el.removeEventListener(this.start, this.onStart); - this.el.removeEventListener(this.move, this.onMove); - this.el.removeEventListener(this.end, this.onEnd); - }, - onStart: function() { - this.isScrolling = true; - }, - onMove: function(e) { - if (!this.isScrolling) return; - const x = e.detail.axis[0]; - const y = e.detail.axis[1]; - if (this.x === -10) { - this.x = x; - this.y = y; - return; - } - - const scrollSpeed = 8; - this.axis[0] = (x - this.x) * scrollSpeed; - this.axis[1] = (y - this.y) * scrollSpeed; - this.emittedEventDetail.axis = this.axis; - e.target.emit("scroll", this.emittedEventDetail); - this.x = x; - this.y = y; - }, - onEnd: function() { - this.isScrolling = false; - this.x = -10; - this.y = -10; - } -}; - -export default trackpad_scrolling;