From 1eaac8605fdfc032c34e8663a321d1b0d4035f52 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Thu, 18 Aug 2016 10:43:37 -0700 Subject: [PATCH] invert the structure and make it work with oculus --- interface/resources/controllers/standard.json | 2 +- interface/resources/controllers/vive.json | 13 +-- .../system/controllers/advancedMovement.js | 85 +++++++++++++------ 3 files changed, 70 insertions(+), 30 deletions(-) diff --git a/interface/resources/controllers/standard.json b/interface/resources/controllers/standard.json index 222357ac9d..c9e91c8666 100644 --- a/interface/resources/controllers/standard.json +++ b/interface/resources/controllers/standard.json @@ -11,7 +11,7 @@ [ { "type": "deadZone", "min": 0.15 }, "constrainToInteger", - { "type": "pulse", "interval": 0.5 }, + { "type": "pulse", "interval": 0.25 }, { "type": "scale", "scale": 22.5 } ] }, diff --git a/interface/resources/controllers/vive.json b/interface/resources/controllers/vive.json index 9cf641d2b0..dce3e9660c 100644 --- a/interface/resources/controllers/vive.json +++ b/interface/resources/controllers/vive.json @@ -1,9 +1,11 @@ { "name": "Vive to Standard", "channels": [ + { "from": "Vive.LY", "when": "Vive.LSY", "filters": ["invert"], "to": "Standard.LY" }, + { "from": "Vive.LX", "when": "Vive.LSX", "to": "Standard.LX" }, { - "from": "Vive.LT", "to": "Standard.LT", - "filters": [ + "from": "Vive.LT", "to": "Standard.LT", + "filters": [ { "type": "deadZone", "min": 0.05 } ] }, @@ -13,10 +15,11 @@ { "from": "Vive.LS", "to": "Standard.LS" }, { "from": "Vive.LSTouch", "to": "Standard.LSTouch" }, + { "from": "Vive.RY", "when": "Vive.RSY", "filters": ["invert"], "to": "Standard.RY" }, { "from": "Vive.RX", "when": "Vive.RSX", "to": "Standard.RX" }, { - "from": "Vive.RT", "to": "Standard.RT", - "filters": [ + "from": "Vive.RT", "to": "Standard.RT", + "filters": [ { "type": "deadZone", "min": 0.05 } ] }, @@ -34,4 +37,4 @@ { "from": "Vive.LeftHand", "to": "Standard.LeftHand" }, { "from": "Vive.RightHand", "to": "Standard.RightHand" } ] -} +} \ No newline at end of file diff --git a/scripts/system/controllers/advancedMovement.js b/scripts/system/controllers/advancedMovement.js index 3c804e1e6d..0eb50434b2 100644 --- a/scripts/system/controllers/advancedMovement.js +++ b/scripts/system/controllers/advancedMovement.js @@ -1,54 +1,78 @@ -var mappingName, advancedMapping; +//advanced movements settings are in individual controller json files +//what we do is check the status of the 'advance movement' checkbox when you enter HMD mode +//if 'advanced movement' is checked...we give you the defaults that are in the json. +//if 'advanced movement' is not checked... we override the advanced controls with basic ones. +//when the script stops, + +//todo: store in prefs +// + + +var mappingName, basicMapping; function addAdvancedMovementItemToSettingsMenu() { Menu.addMenuItem({ menuName: "Settings", - menuItemName: "Advanced Movement (Vive)", + menuItemName: "Advanced Movement For Hand Controllers", isCheckable: true, isChecked: false }); } -function addTranslationToLeftStick() { - Controller.enableMapping(mappingName); +function rotate180() { + MyAvatar.orientation = Quat.inverse(MyAvatar.orientation); } -function registerMappings() { +function registerBasicMapping() { mappingName = 'Hifi-AdvancedMovement-Dev-' + Math.random(); - advancedMapping = Controller.newMapping(mappingName); - advancedMapping.from(Controller.Hardware.Vive.LY).when(Controller.getValue(Controller.Hardware.Vive.LSY) === 1).invert().to(function(val) { - testPrint('ly:' + val) - }); - advancedMapping.from(Controller.Hardware.Vive.LX).when(Controller.getValue(Controller.Hardware.Vive.LSX) === 1).to(function(val) { - testPrint('lx:' + val) - }); - advancedMapping.from(Controller.Hardware.Vive.RY).when(Controller.getValue(Controller.Hardware.Vive.RSY) === 1).invert().to(function(val) { - testPrint('ry:' + val) + basicMapping = Controller.newMapping(mappingName); + basicMapping.from(Controller.Standard.LY).to(function(value) { + var stick = Controller.getValue(Controller.Standard.LS); + if (value === 1) { + rotate180(); + } + print('should do LY stuff' + value + ":stick:" + stick); + return; }); + basicMapping.from(Controller.Standard.LX).to(Controller.Standard.RX); + basicMapping.from(Controller.Standard.RY).to(function(value) { + var stick = Controller.getValue(Controller.Standard.RS); + if (value === 1) { + rotate180(); + } + print('should do RY stuff' + value + ":stick:" + stick); + return; + }) } function testPrint(what) { print('it was controller: ' + what) } -function removeTranslationFromLeftStick() { +function enableMappings() { + Controller.enableMapping(mappingName); +} + +function disableMappings() { Controller.disableMapping(mappingName); } function scriptEnding() { - Menu.removeMenuItem("Settings", "Advanced Movement (Vive)"); - removeTranslationFromLeftStick(); + Menu.removeMenuItem("Settings", "Advanced Movement For Hand Controllers"); + disableMappings(); } +var isChecked = false; + function menuItemEvent(menuItem) { - if (menuItem == "Advanced Movement (Vive)") { - print(" checked=" + Menu.isOptionChecked("Advanced Movement (Vive)")); - var isChecked = Menu.isOptionChecked("Advanced Movement (Vive)"); + if (menuItem == "Advanced Movement For Hand Controllers") { + print(" checked=" + Menu.isOptionChecked("Advanced Movement For Hand Controllers")); + isChecked = Menu.isOptionChecked("Advanced Movement For Hand Controllers"); if (isChecked === true) { - addTranslationToLeftStick(); + disableMappings(); } else if (isChecked === false) { - removeTranslationFromLeftStick(); + enableMappings(); } } @@ -56,9 +80,22 @@ function menuItemEvent(menuItem) { addAdvancedMovementItemToSettingsMenu(); -// register our scriptEnding callback Script.scriptEnding.connect(scriptEnding); Menu.menuItemEvent.connect(menuItemEvent); -registerMappings(); \ No newline at end of file +registerBasicMapping(); +enableMappings(); + +HMD.displayModeChanged.connect(function(isHMDMode) { + if (isHMDMode) { + if (Controller.Hardware.Vive !== undefined || Controller.Hardware.OculusTouch !== undefined) { + if (isChecked === true) { + disableMappings(); + } else if (isChecked === false) { + enableMappings(); + } + + } + } +}); \ No newline at end of file