diff --git a/interface/resources/controllers/oculus_touch.json b/interface/resources/controllers/oculus_touch.json index 8cb512a526..b59bf54e5b 100644 --- a/interface/resources/controllers/oculus_touch.json +++ b/interface/resources/controllers/oculus_touch.json @@ -10,16 +10,14 @@ { "from": "OculusTouch.LX", "to": "Standard.LX" }, { "from": "OculusTouch.LT", "to": "Standard.LT" }, { "from": "OculusTouch.LS", "to": "Standard.LS" }, - { "from": "OculusTouch.LG", "to": "Standard.LG" }, - { "from": "OculusTouch.LeftGrip", "to": "Standard.LB" }, + { "from": "OculusTouch.LeftGrip", "to": "Standard.LeftGrip" }, { "from": "OculusTouch.LeftHand", "to": "Standard.LeftHand" }, { "from": "OculusTouch.RY", "filters": "invert", "to": "Standard.RY" }, { "from": "OculusTouch.RX", "to": "Standard.RX" }, { "from": "OculusTouch.RT", "to": "Standard.RT" }, { "from": "OculusTouch.RS", "to": "Standard.RS" }, - { "from": "OculusTouch.RG", "to": "Standard.RG" }, - { "from": "OculusTouch.RightGrip", "to": "Standard.RB" }, + { "from": "OculusTouch.RightGrip", "to": "Standard.RightGrip" }, { "from": "OculusTouch.RightHand", "to": "Standard.RightHand" }, { "from": "OculusTouch.LeftApplicationMenu", "to": "Standard.Back" }, diff --git a/interface/resources/controllers/vive.json b/interface/resources/controllers/vive.json index 60a46ba3ce..dc3ca3755e 100644 --- a/interface/resources/controllers/vive.json +++ b/interface/resources/controllers/vive.json @@ -5,7 +5,7 @@ { "from": "Vive.LX", "when": "Vive.LSOuter", "to": "Standard.LX" }, { "from": "Vive.LT", "to": "Standard.LT" }, - { "from": "Vive.LeftGrip", "to": "Standard.LB" }, + { "from": "Vive.LeftGrip", "to": "Standard.LeftGrip" }, { "from": "Vive.LS", "to": "Standard.LS" }, { "from": "Vive.LSTouch", "to": "Standard.LSTouch" }, @@ -13,7 +13,7 @@ { "from": "Vive.RX", "when": "Vive.RSOuter", "to": "Standard.RX" }, { "from": "Vive.RT", "to": "Standard.RT" }, - { "from": "Vive.RightGrip", "to": "Standard.RB" }, + { "from": "Vive.RightGrip", "to": "Standard.RightGrip" }, { "from": "Vive.RS", "to": "Standard.RS" }, { "from": "Vive.RSTouch", "to": "Standard.RSTouch" }, diff --git a/libraries/controllers/src/controllers/StandardControls.h b/libraries/controllers/src/controllers/StandardControls.h index 79c23bc6ee..d7eb3de2c2 100644 --- a/libraries/controllers/src/controllers/StandardControls.h +++ b/libraries/controllers/src/controllers/StandardControls.h @@ -66,9 +66,7 @@ namespace controller { RIGHT_SECONDARY_INDEX_TOUCH, RIGHT_INDEX_POINT, - LEFT_GRIP, LEFT_GRIP_TOUCH, - RIGHT_GRIP, RIGHT_GRIP_TOUCH, NUM_STANDARD_BUTTONS @@ -85,9 +83,9 @@ namespace controller { // Triggers LT, RT, - // Grips (Oculus touch squeeze) - LG, - RG, + // Grips + LEFT_GRIP, + RIGHT_GRIP, NUM_STANDARD_AXES, LZ = LT, RZ = RT diff --git a/plugins/oculus/src/OculusControllerManager.cpp b/plugins/oculus/src/OculusControllerManager.cpp index e84fdcbfc7..9eadb83ea7 100644 --- a/plugins/oculus/src/OculusControllerManager.cpp +++ b/plugins/oculus/src/OculusControllerManager.cpp @@ -173,11 +173,6 @@ void OculusControllerManager::RemoteDevice::focusOutEvent() { } void OculusControllerManager::TouchDevice::update(float deltaTime, const controller::InputCalibrationData& inputCalibrationData) { - // Check past values of button map for hysteresis before clearing map - const float HYSTERESIS_OFFSET = -0.1f; - float LEFT_HYSTERESIS_OFFSET = _buttonPressedMap.find(LEFT_GRIP) != _buttonPressedMap.end() ? HYSTERESIS_OFFSET : 0.0f; - float RIGHT_HYSTERESIS_OFFSET = _buttonPressedMap.find(RIGHT_GRIP) != _buttonPressedMap.end() ? HYSTERESIS_OFFSET : 0.0f; - _poseStateMap.clear(); _buttonPressedMap.clear(); @@ -198,12 +193,12 @@ void OculusControllerManager::TouchDevice::update(float deltaTime, const control _axisStateMap[LX] = inputState.Thumbstick[ovrHand_Left].x; _axisStateMap[LY] = inputState.Thumbstick[ovrHand_Left].y; _axisStateMap[LT] = inputState.IndexTrigger[ovrHand_Left]; - _axisStateMap[LG] = inputState.HandTrigger[ovrHand_Left]; + _axisStateMap[LEFT_GRIP] = inputState.HandTrigger[ovrHand_Left]; _axisStateMap[RX] = inputState.Thumbstick[ovrHand_Right].x; _axisStateMap[RY] = inputState.Thumbstick[ovrHand_Right].y; _axisStateMap[RT] = inputState.IndexTrigger[ovrHand_Right]; - _axisStateMap[RG] = inputState.HandTrigger[ovrHand_Right]; + _axisStateMap[RIGHT_GRIP] = inputState.HandTrigger[ovrHand_Right]; // Buttons for (const auto& pair : BUTTON_MAP) { @@ -211,16 +206,6 @@ void OculusControllerManager::TouchDevice::update(float deltaTime, const control _buttonPressedMap.insert(pair.second); } } - // Map pressed hand triggers to grip buttons - // This is temporary in order to support the grab/equip scripts - const float handTriggerThreshold = 0.9f; - if (inputState.HandTrigger[ovrHand_Left] >= handTriggerThreshold + LEFT_HYSTERESIS_OFFSET) { - _buttonPressedMap.insert(LEFT_GRIP); - } - if (inputState.HandTrigger[ovrHand_Right] >= handTriggerThreshold + RIGHT_HYSTERESIS_OFFSET) { - _buttonPressedMap.insert(RIGHT_GRIP); - } - // Touches for (const auto& pair : TOUCH_MAP) { if (inputState.Touches & pair.first) { @@ -348,8 +333,6 @@ controller::Input::NamedVector OculusControllerManager::TouchDevice::getAvailabl //makePair(RB, "RB"), // side grip triggers - makePair(LG, "LG"), - makePair(RG, "RG"), makePair(LEFT_GRIP, "LeftGrip"), makePair(RIGHT_GRIP, "RightGrip"), diff --git a/plugins/openvr/src/ViveControllerManager.cpp b/plugins/openvr/src/ViveControllerManager.cpp index 6e75454b5f..bddbb91316 100644 --- a/plugins/openvr/src/ViveControllerManager.cpp +++ b/plugins/openvr/src/ViveControllerManager.cpp @@ -342,7 +342,7 @@ void ViveControllerManager::InputDevice::handleButtonEvent(float deltaTime, uint if (button == vr::k_EButton_ApplicationMenu) { _buttonPressedMap.insert(isLeftHand ? LEFT_APP_MENU : RIGHT_APP_MENU); } else if (button == vr::k_EButton_Grip) { - _buttonPressedMap.insert(isLeftHand ? LEFT_GRIP : RIGHT_GRIP); + _axisStateMap[isLeftHand ? LEFT_GRIP : RIGHT_GRIP] = 1.0f; } else if (button == vr::k_EButton_SteamVR_Trigger) { _buttonPressedMap.insert(isLeftHand ? LT : RT); } else if (button == vr::k_EButton_SteamVR_Touchpad) { diff --git a/scripts/system/controllers/handControllerGrab.js b/scripts/system/controllers/handControllerGrab.js index 06549a38b5..4f4b7e32ad 100644 --- a/scripts/system/controllers/handControllerGrab.js +++ b/scripts/system/controllers/handControllerGrab.js @@ -33,6 +33,9 @@ var TRIGGER_OFF_VALUE = 0.15; var BUMPER_ON_VALUE = 0.5; +var GRIP_ON_VALUE = 0.9; +var GRIP_OFF_VALUE = 0.8; + var THUMB_ON_VALUE = 0.5; var HAND_HEAD_MIX_RATIO = 0.0; // 0 = only use hands for search/move. 1 = only use head for search/move. @@ -271,6 +274,7 @@ function MyController(hand) { this.triggerValue = 0; // rolling average of trigger value this.rawTriggerValue = 0; + this.rawGripValue = 0; this.rawBumperValue = 0; this.rawThumbValue = 0; @@ -509,10 +513,10 @@ function MyController(hand) { var searchSphereLocation = Vec3.sum(distantPickRay.origin, Vec3.multiply(distantPickRay.direction, this.searchSphereDistance)); this.searchSphereOn(searchSphereLocation, SEARCH_SPHERE_SIZE * this.searchSphereDistance, - (this.triggerSmoothedGrab() || this.bumperSqueezed()) ? INTERSECT_COLOR : NO_INTERSECT_COLOR); + (this.triggerSmoothedGrab() || (this.bumperSqueezed() || this.gripSqueezed())) ? INTERSECT_COLOR : NO_INTERSECT_COLOR); if ((USE_OVERLAY_LINES_FOR_SEARCHING === true) && PICK_WITH_HAND_RAY) { this.overlayLineOn(handPosition, searchSphereLocation, - (this.triggerSmoothedGrab() || this.bumperSqueezed()) ? INTERSECT_COLOR : NO_INTERSECT_COLOR); + (this.triggerSmoothedGrab() || (this.bumperSqueezed() || this.gripSqueezed())) ? INTERSECT_COLOR : NO_INTERSECT_COLOR); } } @@ -772,6 +776,10 @@ function MyController(hand) { _this.rawBumperValue = value; }; + this.gripPress = function(value) { + _this.rawGripValue = value; + }; + this.updateSmoothedTrigger = function() { var triggerValue = this.rawTriggerValue; // smooth out trigger value @@ -799,6 +807,14 @@ function MyController(hand) { return _this.rawBumperValue < BUMPER_ON_VALUE; }; + this.gripSqueezed = function() { + return _this.rawGripValue > GRIP_ON_VALUE; + }; + + this.gripReleased = function() { + return _this.rawGripValue < GRIP_OFF_VALUE; + }; + // this.triggerOrBumperSqueezed = function() { // return triggerSmoothedSqueezed() || bumperSqueezed(); // } @@ -820,13 +836,13 @@ function MyController(hand) { }; this.off = function() { - if (this.triggerSmoothedSqueezed() || this.bumperSqueezed()) { + if (this.triggerSmoothedSqueezed() || (this.bumperSqueezed() || this.gripSqueezed())) { this.lastPickTime = 0; var controllerHandInput = (this.hand === RIGHT_HAND) ? Controller.Standard.RightHand : Controller.Standard.LeftHand; this.startingHandRotation = Controller.getPoseValue(controllerHandInput).rotation; if (this.triggerSmoothedSqueezed()) { this.setState(STATE_SEARCHING); - } else if (this.bumperSqueezed()) { + } else if (this.bumperSqueezed() || this.gripSqueezed()) { this.setState(STATE_HOLD_SEARCHING); } } @@ -839,11 +855,13 @@ function MyController(hand) { this.checkForStrayChildren(); + print("bumper: " + this.bumperReleased() + " grip: " + this.gripReleased()); + if (this.state == STATE_SEARCHING && this.triggerSmoothedReleased()) { this.setState(STATE_RELEASE); return; } - if (this.state == STATE_HOLD_SEARCHING && this.bumperReleased()) { + if (this.state == STATE_HOLD_SEARCHING && (this.bumperReleased() || this.gripReleased())) { this.setState(STATE_RELEASE); return; } @@ -1000,7 +1018,7 @@ function MyController(hand) { grabbableData = grabbableDataForCandidate; } } - if ((this.grabbedEntity !== null) && (this.triggerSmoothedGrab() || this.bumperSqueezed())) { + if ((this.grabbedEntity !== null) && (this.triggerSmoothedGrab() || (this.bumperSqueezed() || this.gripSqueezed()))) { // We are squeezing enough to grab, and we've found an entity that we'll try to do something with. var near = (nearPickedCandidateEntities.indexOf(this.grabbedEntity) >= 0) || minDistance <= NEAR_PICK_MAX_DISTANCE; var isPhysical = this.propsArePhysical(props); @@ -1166,7 +1184,7 @@ function MyController(hand) { }; this.continueDistanceHolding = function() { - if (this.triggerSmoothedReleased() && this.bumperReleased()) { + if (this.triggerSmoothedReleased() && (this.bumperReleased() || this.gripReleased())) { this.setState(STATE_RELEASE); this.callEntityMethodOnGrabbed("releaseGrab"); return; @@ -1390,7 +1408,7 @@ function MyController(hand) { this.callEntityMethodOnGrabbed("releaseGrab"); return; } - if (this.state == STATE_HOLD && this.bumperReleased()) { + if (this.state == STATE_HOLD && (this.bumperReleased() || this.gripReleased())) { this.setState(STATE_RELEASE); this.callEntityMethodOnGrabbed("releaseGrab"); return; @@ -1504,7 +1522,7 @@ function MyController(hand) { this.callEntityMethodOnGrabbed("releaseGrab"); return; } - if (this.state == STATE_CONTINUE_HOLD && this.bumperReleased()) { + if (this.state == STATE_CONTINUE_HOLD && (this.bumperReleased() || this.gripReleased())) { this.setState(STATE_RELEASE); this.callEntityMethodOnGrabbed("releaseEquip"); return; @@ -1633,7 +1651,7 @@ function MyController(hand) { }; this.nearTrigger = function() { - if (this.triggerSmoothedReleased() && this.bumperReleased()) { + if (this.triggerSmoothedReleased() && (this.bumperReleased() || this.gripReleased())) { this.setState(STATE_RELEASE); this.callEntityMethodOnGrabbed("stopNearTrigger"); return; @@ -1643,7 +1661,7 @@ function MyController(hand) { }; this.farTrigger = function() { - if (this.triggerSmoothedReleased() && this.bumperReleased()) { + if (this.triggerSmoothedReleased() && (this.bumperReleased() || this.gripReleased())) { this.setState(STATE_RELEASE); this.callEntityMethodOnGrabbed("stopFarTrigger"); return; @@ -1653,7 +1671,7 @@ function MyController(hand) { }; this.continueNearTrigger = function() { - if (this.triggerSmoothedReleased() && this.bumperReleased()) { + if (this.triggerSmoothedReleased() && (this.bumperReleased() || this.gripReleased())) { this.setState(STATE_RELEASE); this.callEntityMethodOnGrabbed("stopNearTrigger"); return; @@ -1662,7 +1680,7 @@ function MyController(hand) { }; this.continueFarTrigger = function() { - if (this.triggerSmoothedReleased() && this.bumperReleased()) { + if (this.triggerSmoothedReleased() && (this.bumperReleased() || this.gripReleased())) { this.setState(STATE_RELEASE); this.callEntityMethodOnGrabbed("stopFarTrigger"); return; @@ -1945,6 +1963,9 @@ mapping.from([Controller.Standard.LT]).peek().to(leftController.triggerPress); mapping.from([Controller.Standard.RB]).peek().to(rightController.bumperPress); mapping.from([Controller.Standard.LB]).peek().to(leftController.bumperPress); +mapping.from([Controller.Standard.RightGrip]).peek().to(rightController.gripPress); +mapping.from([Controller.Standard.LeftGrip]).peek().to(leftController.gripPress); + mapping.from([Controller.Standard.LeftPrimaryThumb]).peek().to(leftController.thumbPress); mapping.from([Controller.Standard.RightPrimaryThumb]).peek().to(rightController.thumbPress);