From 2034162c76986a776671bef38bfb0064cd5883bc Mon Sep 17 00:00:00 2001 From: David Rowe Date: Wed, 15 Aug 2018 21:31:53 +1200 Subject: [PATCH 1/5] Disable Vive teleport button if transitioning from direction button --- .../controllers/controllerModules/teleport.js | 58 ++++++++++++++++++- 1 file changed, 55 insertions(+), 3 deletions(-) diff --git a/scripts/system/controllers/controllerModules/teleport.js b/scripts/system/controllers/controllerModules/teleport.js index 92e3168147..e7040208fb 100644 --- a/scripts/system/controllers/controllerModules/teleport.js +++ b/scripts/system/controllers/controllerModules/teleport.js @@ -116,6 +116,11 @@ Script.include("/~/system/libraries/controllers.js"); function Teleporter(hand) { var _this = this; this.hand = hand; + + this.buttonStateXX = 0; // Left hand / right hand x-axis. + this.buttonStateXY = 0; // Left hand / right hand y-axis. + this.BUTTON_TRANSITION_DELAY = 50; // Allow time for transition from direction buttons to touch-pad. + this.buttonValue = 0; this.disabled = false; // used by the 'Hifi-Teleport-Disabler' message handler this.active = false; @@ -190,8 +195,42 @@ Script.include("/~/system/libraries/controllers.js"); Pointers.removePointer(this.teleportParabolaHeadInvisible); }; - this.buttonPress = function(value) { - _this.buttonValue = value; + + this.buttonStateXX = function (value) { + if (value !== 0) { + // Don't lock right hand's x-axis buttons if snap turn. + if (_this.hand === LEFT_HAND || !Controller.getValue(Controller.Hardware.Application.SnapTurn)) { + _this.buttonStateX = value; + } + } else { + // Delay direction button release until after teleport possibly pressed. + Script.setTimeout(function () { + _this.buttonStateX = value; + }, _this.BUTTON_TRANSITION_DELAY); + } + }; + + this.buttonStateXY = function (value) { + if (value !== 0) { + _this.buttonStateY = value; + } else { + // Delay direction button release until after teleport possibly pressed. + Script.setTimeout(function () { + _this.buttonStateY = value; + }, _this.BUTTON_TRANSITION_DELAY); + } + }; + + this.teleportLocked = function () { + // Lock teleport if in advanced movement mode and have just transitioned from pressing a direction button. + return Controller.getValue(Controller.Hardware.Application.AdvancedMovement) + && (_this.buttonStateX !== 0 || _this.buttonStateY !== 0); + }; + + this.buttonPress = function (value) { + if (value === 0 || !_this.teleportLocked()) { + _this.buttonValue = value; + } }; this.parameters = makeDispatcherModuleParameters( @@ -394,8 +433,21 @@ Script.include("/~/system/libraries/controllers.js"); mappingName = 'Hifi-Teleporter-Dev-' + Math.random(); teleportMapping = Controller.newMapping(mappingName); - teleportMapping.from(Controller.Standard.RightPrimaryThumb).peek().to(rightTeleporter.buttonPress); + // Disable Vive teleport if touch is transitioning across touch-pad after using a direction button. + if (Controller.Hardware.Vive) { + teleportMapping.from(Controller.Hardware.Vive.LX).peek().when(Controller.Hardware.Vive.LSX) + .to(leftTeleporter.buttonStateXX); + teleportMapping.from(Controller.Hardware.Vive.LY).peek().when(Controller.Hardware.Vive.LSY).invert() + .to(leftTeleporter.buttonStateXY); + teleportMapping.from(Controller.Hardware.Vive.RX).peek().when(Controller.Hardware.Vive.RSX) + .to(rightTeleporter.buttonStateXX); + teleportMapping.from(Controller.Hardware.Vive.RY).peek().when(Controller.Hardware.Vive.RSY).invert() + .to(rightTeleporter.buttonStateXY); + } + + // Teleport actions. teleportMapping.from(Controller.Standard.LeftPrimaryThumb).peek().to(leftTeleporter.buttonPress); + teleportMapping.from(Controller.Standard.RightPrimaryThumb).peek().to(rightTeleporter.buttonPress); } var leftTeleporter = new Teleporter(LEFT_HAND); From 8d1b947bbd187f8c0b46cb6fe6de811f9c074990 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Thu, 16 Aug 2018 13:35:36 +1200 Subject: [PATCH 2/5] Fix variable names --- scripts/system/controllers/controllerModules/teleport.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/system/controllers/controllerModules/teleport.js b/scripts/system/controllers/controllerModules/teleport.js index e7040208fb..07f7371aef 100644 --- a/scripts/system/controllers/controllerModules/teleport.js +++ b/scripts/system/controllers/controllerModules/teleport.js @@ -117,8 +117,8 @@ Script.include("/~/system/libraries/controllers.js"); var _this = this; this.hand = hand; - this.buttonStateXX = 0; // Left hand / right hand x-axis. - this.buttonStateXY = 0; // Left hand / right hand y-axis. + this.buttonStateX = 0; // Left hand / right hand x-axis. + this.buttonStateX = 0; // Left hand / right hand y-axis. this.BUTTON_TRANSITION_DELAY = 50; // Allow time for transition from direction buttons to touch-pad. this.buttonValue = 0; From bf733ded0f2b3f827e8eeb0332fe423f71d56aed Mon Sep 17 00:00:00 2001 From: David Rowe Date: Fri, 17 Aug 2018 09:08:28 +1200 Subject: [PATCH 3/5] Handle Vive controller not being available at start-up --- .../controllers/controllerModules/teleport.js | 57 ++++++++++++------- 1 file changed, 36 insertions(+), 21 deletions(-) diff --git a/scripts/system/controllers/controllerModules/teleport.js b/scripts/system/controllers/controllerModules/teleport.js index 07f7371aef..8d0fe2cfbf 100644 --- a/scripts/system/controllers/controllerModules/teleport.js +++ b/scripts/system/controllers/controllerModules/teleport.js @@ -117,10 +117,6 @@ Script.include("/~/system/libraries/controllers.js"); var _this = this; this.hand = hand; - this.buttonStateX = 0; // Left hand / right hand x-axis. - this.buttonStateX = 0; // Left hand / right hand y-axis. - this.BUTTON_TRANSITION_DELAY = 50; // Allow time for transition from direction buttons to touch-pad. - this.buttonValue = 0; this.disabled = false; // used by the 'Hifi-Teleport-Disabler' message handler this.active = false; @@ -195,8 +191,11 @@ Script.include("/~/system/libraries/controllers.js"); Pointers.removePointer(this.teleportParabolaHeadInvisible); }; + this.axisButtonStateX = 0; // Left/right axis button pressed. + this.axisButtonStateY = 0; // Up/down axis button pressed. + this.BUTTON_TRANSITION_DELAY = 100; // Allow time for transition from direction buttons to touch-pad. - this.buttonStateXX = function (value) { + this.axisButtonChangeX = function (value) { if (value !== 0) { // Don't lock right hand's x-axis buttons if snap turn. if (_this.hand === LEFT_HAND || !Controller.getValue(Controller.Hardware.Application.SnapTurn)) { @@ -205,18 +204,18 @@ Script.include("/~/system/libraries/controllers.js"); } else { // Delay direction button release until after teleport possibly pressed. Script.setTimeout(function () { - _this.buttonStateX = value; + _this.axisButtonStateX = value; }, _this.BUTTON_TRANSITION_DELAY); } }; - this.buttonStateXY = function (value) { + this.axisButtonChangeY = function (value) { if (value !== 0) { - _this.buttonStateY = value; + _this.axisButtonStateY = value; } else { // Delay direction button release until after teleport possibly pressed. Script.setTimeout(function () { - _this.buttonStateY = value; + _this.axisButtonStateY = value; }, _this.BUTTON_TRANSITION_DELAY); } }; @@ -224,7 +223,7 @@ Script.include("/~/system/libraries/controllers.js"); this.teleportLocked = function () { // Lock teleport if in advanced movement mode and have just transitioned from pressing a direction button. return Controller.getValue(Controller.Hardware.Application.AdvancedMovement) - && (_this.buttonStateX !== 0 || _this.buttonStateY !== 0); + && (_this.axisButtonStateX !== 0 || _this.axisButtonStateY !== 0); }; this.buttonPress = function (value) { @@ -386,6 +385,7 @@ Script.include("/~/system/libraries/controllers.js"); } var mappingName, teleportMapping; + var isViveMapped = false; function parseJSON(json) { try { @@ -429,21 +429,35 @@ Script.include("/~/system/libraries/controllers.js"); } } + function registerViveTeleportMapping() { + // Disable Vive teleport if touch is transitioning across touch-pad after pressing a direction button. + if (Controller.Hardware.Vive) { + var mappingName = 'Hifi-Teleporter-Dev-Vive-' + Math.random(); + var viveTeleportMapping = Controller.newMapping(mappingName); + viveTeleportMapping.from(Controller.Hardware.Vive.LSX).peek().to(leftTeleporter.axisButtonChangeX); + viveTeleportMapping.from(Controller.Hardware.Vive.LSY).peek().to(leftTeleporter.axisButtonChangeY); + viveTeleportMapping.from(Controller.Hardware.Vive.RSX).peek().to(rightTeleporter.axisButtonChangeX); + viveTeleportMapping.from(Controller.Hardware.Vive.RSY).peek().to(rightTeleporter.axisButtonChangeY); + Controller.enableMapping(mappingName); + isViveMapped = true; + } + } + + function onHardwareChanged() { + // Controller.Hardware.Vive is not immediately available at Interface start-up. + if (!isViveMapped && Controller.Hardware.Vive) { + registerViveTeleportMapping(); + } + } + + Controller.hardwareChanged.connect(onHardwareChanged); + function registerMappings() { mappingName = 'Hifi-Teleporter-Dev-' + Math.random(); teleportMapping = Controller.newMapping(mappingName); - // Disable Vive teleport if touch is transitioning across touch-pad after using a direction button. - if (Controller.Hardware.Vive) { - teleportMapping.from(Controller.Hardware.Vive.LX).peek().when(Controller.Hardware.Vive.LSX) - .to(leftTeleporter.buttonStateXX); - teleportMapping.from(Controller.Hardware.Vive.LY).peek().when(Controller.Hardware.Vive.LSY).invert() - .to(leftTeleporter.buttonStateXY); - teleportMapping.from(Controller.Hardware.Vive.RX).peek().when(Controller.Hardware.Vive.RSX) - .to(rightTeleporter.buttonStateXX); - teleportMapping.from(Controller.Hardware.Vive.RY).peek().when(Controller.Hardware.Vive.RSY).invert() - .to(rightTeleporter.buttonStateXY); - } + // Vive teleport button lock-out. + registerViveTeleportMapping(); // Teleport actions. teleportMapping.from(Controller.Standard.LeftPrimaryThumb).peek().to(leftTeleporter.buttonPress); @@ -459,6 +473,7 @@ Script.include("/~/system/libraries/controllers.js"); Controller.enableMapping(mappingName); function cleanup() { + Controller.hardwareChanged.disconnect(onHardwareChanged); teleportMapping.disable(); leftTeleporter.cleanup(); rightTeleporter.cleanup(); From 5328b48acc97cea77d806406c3cb38e66e032521 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Fri, 17 Aug 2018 09:09:11 +1200 Subject: [PATCH 4/5] Make Vive snap turn buttons lock teleport, also --- scripts/system/controllers/controllerModules/teleport.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/scripts/system/controllers/controllerModules/teleport.js b/scripts/system/controllers/controllerModules/teleport.js index 8d0fe2cfbf..05d90dde72 100644 --- a/scripts/system/controllers/controllerModules/teleport.js +++ b/scripts/system/controllers/controllerModules/teleport.js @@ -197,10 +197,7 @@ Script.include("/~/system/libraries/controllers.js"); this.axisButtonChangeX = function (value) { if (value !== 0) { - // Don't lock right hand's x-axis buttons if snap turn. - if (_this.hand === LEFT_HAND || !Controller.getValue(Controller.Hardware.Application.SnapTurn)) { - _this.buttonStateX = value; - } + _this.buttonStateX = value; } else { // Delay direction button release until after teleport possibly pressed. Script.setTimeout(function () { From 26576fa760bbce30a577e232c7573ba14686115b Mon Sep 17 00:00:00 2001 From: David Rowe Date: Sat, 18 Aug 2018 09:34:16 +1200 Subject: [PATCH 5/5] Fix Vive left/right buttons not disabling teleport --- scripts/system/controllers/controllerModules/teleport.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/system/controllers/controllerModules/teleport.js b/scripts/system/controllers/controllerModules/teleport.js index 05d90dde72..db95f6b09b 100644 --- a/scripts/system/controllers/controllerModules/teleport.js +++ b/scripts/system/controllers/controllerModules/teleport.js @@ -116,7 +116,6 @@ Script.include("/~/system/libraries/controllers.js"); function Teleporter(hand) { var _this = this; this.hand = hand; - this.buttonValue = 0; this.disabled = false; // used by the 'Hifi-Teleport-Disabler' message handler this.active = false; @@ -197,7 +196,7 @@ Script.include("/~/system/libraries/controllers.js"); this.axisButtonChangeX = function (value) { if (value !== 0) { - _this.buttonStateX = value; + _this.axisButtonStateX = value; } else { // Delay direction button release until after teleport possibly pressed. Script.setTimeout(function () {