From 8b76af531bf326a0e707ce4760f4600218611784 Mon Sep 17 00:00:00 2001 From: SamGondelman Date: Thu, 2 Jun 2016 16:52:17 -0700 Subject: [PATCH] made touch hand orientation more comfortable, fixed all the touch key mappings, exposed capacitive touch keys for use later --- .../resources/controllers/oculus_touch.json | 36 ++++++-- .../oculus/src/OculusControllerManager.cpp | 86 +++++++++++++++---- 2 files changed, 98 insertions(+), 24 deletions(-) diff --git a/interface/resources/controllers/oculus_touch.json b/interface/resources/controllers/oculus_touch.json index cc8c2f8bdc..8cb512a526 100644 --- a/interface/resources/controllers/oculus_touch.json +++ b/interface/resources/controllers/oculus_touch.json @@ -1,22 +1,42 @@ { "name": "Oculus Touch to Standard", "channels": [ - { "from": "OculusTouch.LY", "filters": "invert", "to": "Standard.LY" }, - { "from": "OculusTouch.LX", "to": "Standard.LX" }, + { "from": "OculusTouch.A", "to": "Standard.A" }, + { "from": "OculusTouch.B", "to": "Standard.B" }, + { "from": "OculusTouch.X", "to": "Standard.X" }, + { "from": "OculusTouch.Y", "to": "Standard.Y" }, + + { "from": "OculusTouch.LY", "filters": "invert", "to": "Standard.LY" }, + { "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.LeftHand", "to": "Standard.LeftHand" }, - { "from": "OculusTouch.RY", "filters": "invert", "to": "Standard.RY" }, - { "from": "OculusTouch.RX", "to": "Standard.RX" }, - + { "from": "OculusTouch.RY", "filters": "invert", "to": "Standard.RY" }, + { "from": "OculusTouch.RX", "to": "Standard.RX" }, { "from": "OculusTouch.RT", "to": "Standard.RT" }, - { "from": "OculusTouch.RB", "to": "Standard.RB" }, { "from": "OculusTouch.RS", "to": "Standard.RS" }, + { "from": "OculusTouch.RG", "to": "Standard.RG" }, + { "from": "OculusTouch.RightGrip", "to": "Standard.RB" }, + { "from": "OculusTouch.RightHand", "to": "Standard.RightHand" }, { "from": "OculusTouch.LeftApplicationMenu", "to": "Standard.Back" }, { "from": "OculusTouch.RightApplicationMenu", "to": "Standard.Start" }, - { "from": "OculusTouch.LeftHand", "to": "Standard.LeftHand" }, - { "from": "OculusTouch.RightHand", "to": "Standard.RightHand" } + { "from": "OculusTouch.LeftPrimaryThumbTouch", "to": "Standard.LeftPrimaryThumbTouch" }, + { "from": "OculusTouch.LeftSecondaryThumbTouch", "to": "Standard.LeftSecondaryThumbTouch" }, + { "from": "OculusTouch.RightPrimaryThumbTouch", "to": "Standard.RightPrimaryThumbTouch" }, + { "from": "OculusTouch.RightSecondaryThumbTouch", "to": "Standard.RightSecondaryThumbTouch" }, + { "from": "OculusTouch.LeftPrimaryIndexTouch", "to": "Standard.LeftPrimaryIndexTouch" }, + { "from": "OculusTouch.RightPrimaryIndexTouch", "to": "Standard.RightPrimaryIndexTouch" }, + { "from": "OculusTouch.LSTouch", "to": "Standard.LSTouch" }, + { "from": "OculusTouch.RSTouch", "to": "Standard.RSTouch" }, + { "from": "OculusTouch.LeftThumbUp", "to": "Standard.LeftThumbUp" }, + { "from": "OculusTouch.RightThumbUp", "to": "Standard.RightThumbUp" }, + { "from": "OculusTouch.LeftIndexPoint", "to": "Standard.LeftIndexPoint" }, + { "from": "OculusTouch.RightIndexPoint", "to": "Standard.RightIndexPoint" } ] } diff --git a/plugins/oculus/src/OculusControllerManager.cpp b/plugins/oculus/src/OculusControllerManager.cpp index 2fd48bb611..e84fdcbfc7 100644 --- a/plugins/oculus/src/OculusControllerManager.cpp +++ b/plugins/oculus/src/OculusControllerManager.cpp @@ -120,14 +120,14 @@ static const std::vector> BUTTON_MAP { ovrButton_B, B }, { ovrButton_LThumb, LS }, { ovrButton_RThumb, RS }, - { ovrButton_LShoulder, LB }, - { ovrButton_RShoulder, RB }, + //{ ovrButton_LShoulder, LB }, + //{ ovrButton_RShoulder, RB }, } }; static const std::vector> TOUCH_MAP { { - { ovrTouch_X, LEFT_SECONDARY_THUMB_TOUCH }, + { ovrTouch_X, LEFT_PRIMARY_THUMB_TOUCH }, { ovrTouch_Y, LEFT_SECONDARY_THUMB_TOUCH }, - { ovrTouch_A, RIGHT_SECONDARY_THUMB_TOUCH }, + { ovrTouch_A, RIGHT_PRIMARY_THUMB_TOUCH }, { ovrTouch_B, RIGHT_SECONDARY_THUMB_TOUCH }, { ovrTouch_LIndexTrigger, LEFT_PRIMARY_INDEX_TOUCH }, { ovrTouch_RIndexTrigger, RIGHT_PRIMARY_INDEX_TOUCH }, @@ -173,6 +173,11 @@ 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(); @@ -206,6 +211,16 @@ 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) { @@ -261,7 +276,7 @@ void OculusControllerManager::TouchDevice::handlePose(float deltaTime, // // An approximate offset for the Touch can be obtained by inspection: // - // Qoffset = glm::inverse(glm::angleAxis(sign * PI/2.0f, zAxis) + // Qoffset = glm::inverse(glm::angleAxis(sign * PI/2.0f, zAxis) * glm::angleAxis(PI/4.0f, xAxis)) // // So the full equation is: // @@ -280,14 +295,26 @@ void OculusControllerManager::TouchDevice::handlePose(float deltaTime, static const glm::quat leftQuarterZ = glm::angleAxis(-PI_OVER_TWO, Vectors::UNIT_Z); static const glm::quat rightQuarterZ = glm::angleAxis(PI_OVER_TWO, Vectors::UNIT_Z); + static const glm::quat eighthX = glm::angleAxis(PI / 4.0f, Vectors::UNIT_X); - static const glm::quat leftRotationOffset = glm::inverse(leftQuarterZ) * touchToHand; - static const glm::quat rightRotationOffset = glm::inverse(rightQuarterZ) * touchToHand; + static const glm::quat leftRotationOffset = glm::inverse(leftQuarterZ * eighthX) * touchToHand; + static const glm::quat rightRotationOffset = glm::inverse(rightQuarterZ * eighthX) * touchToHand; + static const float CONTROLLER_LENGTH_OFFSET = 0.0762f; // three inches + static const glm::vec3 CONTROLLER_OFFSET = glm::vec3(CONTROLLER_LENGTH_OFFSET / 2.0f, + CONTROLLER_LENGTH_OFFSET / 2.0f, + CONTROLLER_LENGTH_OFFSET * 2.0f); + static const glm::vec3 leftTranslationOffset = glm::vec3(-1.0f, 1.0f, 1.0f) * CONTROLLER_OFFSET; + static const glm::vec3 rightTranslationOffset = CONTROLLER_OFFSET; + + auto translationOffset = (hand == ovrHand_Left ? leftTranslationOffset : rightTranslationOffset); auto rotationOffset = (hand == ovrHand_Left ? leftRotationOffset : rightRotationOffset); + glm::quat rotation = toGlm(handPose.ThePose.Orientation); + pose.translation = toGlm(handPose.ThePose.Position); - pose.rotation = toGlm(handPose.ThePose.Orientation)*rotationOffset; + pose.translation += rotation * translationOffset; + pose.rotation = rotation * rotationOffset; pose.angularVelocity = toGlm(handPose.AngularVelocity); pose.velocity = toGlm(handPose.LinearVelocity); pose.valid = true; @@ -300,27 +327,54 @@ void OculusControllerManager::TouchDevice::handlePose(float deltaTime, controller::Input::NamedVector OculusControllerManager::TouchDevice::getAvailableInputs() const { using namespace controller; QVector availableInputs{ - // Trackpad analogs + // buttons + makePair(A, "A"), + makePair(B, "B"), + makePair(X, "X"), + makePair(Y, "Y"), + + // trackpad analogs makePair(LX, "LX"), makePair(LY, "LY"), makePair(RX, "RX"), makePair(RY, "RY"), - // trigger analogs + + // triggers makePair(LT, "LT"), makePair(RT, "RT"), - makePair(LB, "LB"), - makePair(RB, "RB"), + // trigger buttons + //makePair(LB, "LB"), + //makePair(RB, "RB"), + // side grip triggers + makePair(LG, "LG"), + makePair(RG, "RG"), + makePair(LEFT_GRIP, "LeftGrip"), + makePair(RIGHT_GRIP, "RightGrip"), + + // joystick buttons makePair(LS, "LS"), makePair(RS, "RS"), + makePair(LEFT_HAND, "LeftHand"), makePair(RIGHT_HAND, "RightHand"), - makePair(LEFT_PRIMARY_THUMB, "LeftPrimaryThumb"), - makePair(LEFT_SECONDARY_THUMB, "LeftSecondaryThumb"), - makePair(RIGHT_PRIMARY_THUMB, "RightPrimaryThumb"), - makePair(RIGHT_SECONDARY_THUMB, "RightSecondaryThumb"), + makePair(LEFT_PRIMARY_THUMB_TOUCH, "LeftPrimaryThumbTouch"), + makePair(LEFT_SECONDARY_THUMB_TOUCH, "LeftSecondaryThumbTouch"), + makePair(RIGHT_PRIMARY_THUMB_TOUCH, "RightPrimaryThumbTouch"), + makePair(RIGHT_SECONDARY_THUMB_TOUCH, "RightSecondaryThumbTouch"), + makePair(LEFT_PRIMARY_INDEX_TOUCH, "LeftPrimaryIndexTouch"), + makePair(RIGHT_PRIMARY_INDEX_TOUCH, "RightPrimaryIndexTouch"), + makePair(LS_TOUCH, "LSTouch"), + makePair(RS_TOUCH, "RSTouch"), + makePair(LEFT_THUMB_UP, "LeftThumbUp"), + makePair(RIGHT_THUMB_UP, "RightThumbUp"), + makePair(LEFT_INDEX_POINT, "LeftIndexPoint"), + makePair(RIGHT_INDEX_POINT, "RightIndexPoint"), + + makePair(BACK, "LeftApplicationMenu"), + makePair(START, "RightApplicationMenu"), }; return availableInputs; }