From ac1df7b8150fe0fbe0b044ea681f53026134c351 Mon Sep 17 00:00:00 2001 From: Menithal Date: Sun, 5 Nov 2017 00:18:48 +0200 Subject: [PATCH] 21539: Allow HMD to turned off in Desktop Mode --- .../qml/hifi/tablet/OpenVrConfiguration.qml | 37 ++++++++++++++++++- plugins/openvr/src/ViveControllerManager.cpp | 32 ++++++++++++++-- plugins/openvr/src/ViveControllerManager.h | 6 ++- 3 files changed, 69 insertions(+), 6 deletions(-) diff --git a/interface/resources/qml/hifi/tablet/OpenVrConfiguration.qml b/interface/resources/qml/hifi/tablet/OpenVrConfiguration.qml index 78c10e2ffa..5e9bf40d41 100644 --- a/interface/resources/qml/hifi/tablet/OpenVrConfiguration.qml +++ b/interface/resources/qml/hifi/tablet/OpenVrConfiguration.qml @@ -36,7 +36,9 @@ Rectangle { readonly property bool hmdHead: headBox.checked readonly property bool headPuck: headPuckBox.checked readonly property bool handController: handBox.checked + readonly property bool handPuck: handPuckBox.checked + readonly property bool hmdDesktop: hmdInDesktop.checked property int state: buttonState.disabled property var lastConfiguration: null @@ -789,6 +791,7 @@ Rectangle { verticalCenter: viveInDesktop.verticalCenter } } + NumberAnimation { id: numberAnimation @@ -797,6 +800,35 @@ Rectangle { to: 0 } + HifiControls.CheckBox { + id: hmdInDesktop + width: 15 + height: 15 + boxRadius: 7 + + anchors.top: viveInDesktop.bottom + anchors.topMargin: 5 + anchors.left: openVrConfiguration.left + anchors.leftMargin: leftMargin + 10 + + onClicked: { + sendConfigurationSettings(); + } + } + + RalewayBold { + id: hmdDesktopText + size: 10 + text: "Use HMD in desktop mode" + color: hifi.colors.white + + anchors { + left: hmdInDesktop.right + leftMargin: 5 + verticalCenter: hmdInDesktop.verticalCenter + } + } + function logAction(action, status) { console.log("calibrated from ui"); var data = { @@ -877,6 +909,7 @@ Rectangle { var HmdHead = settings["HMDHead"]; var viveController = settings["handController"]; var desktopMode = settings["desktopMode"]; + var hmdDesktopPosition = settings["hmdDesktopTracking"]; armCircumference.value = settings.armCircumference; shoulderWidth.value = settings.shoulderWidth; @@ -898,6 +931,7 @@ Rectangle { } viveInDesktop.checked = desktopMode; + hmdInDesktop.checked = hmdDesktopPosition; initializeButtonState(); updateCalibrationText(); @@ -1058,7 +1092,8 @@ Rectangle { "handConfiguration": handObject, "armCircumference": armCircumference.value, "shoulderWidth": shoulderWidth.value, - "desktopMode": viveInDesktop.checked + "desktopMode": viveInDesktop.checked, + "hmdDesktopTracking": hmdInDesktop.checked } return settingsObject; diff --git a/plugins/openvr/src/ViveControllerManager.cpp b/plugins/openvr/src/ViveControllerManager.cpp index 430dc193a3..6b24aa0b5b 100644 --- a/plugins/openvr/src/ViveControllerManager.cpp +++ b/plugins/openvr/src/ViveControllerManager.cpp @@ -166,6 +166,12 @@ void ViveControllerManager::setConfigurationSettings(const QJsonObject configura _resetMatCalculated = false; } } + + if (configurationSettings.contains("hmdDesktopTracking")) { + + _hmdDesktopTracking = configurationSettings["hmdDesktopTracking"].toBool(); + } + _inputDevice->configureCalibrationSettings(configurationSettings); saveSettings(); } @@ -175,6 +181,7 @@ QJsonObject ViveControllerManager::configurationSettings() { if (isSupported()) { QJsonObject configurationSettings = _inputDevice->configurationSettings(); configurationSettings["desktopMode"] = _desktopMode; + configurationSettings["hmdDesktopTracking"] = _hmdDesktopTracking; return configurationSettings; } @@ -414,6 +421,8 @@ void ViveControllerManager::InputDevice::configureCalibrationSettings(const QJso if (!configurationSettings.empty()) { auto iter = configurationSettings.begin(); auto end = configurationSettings.end(); + bool hmdDesktopTracking = true; + bool hmdDesktopMode = false; while (iter != end) { if (iter.key() == "bodyConfiguration") { setConfigFromString(iter.value().toString()); @@ -441,9 +450,17 @@ void ViveControllerManager::InputDevice::configureCalibrationSettings(const QJso _armCircumference = (float)iter.value().toDouble() * CM_TO_M; } else if (iter.key() == "shoulderWidth") { _shoulderWidth = (float)iter.value().toDouble() * CM_TO_M; + } else if (iter.key() == "hmdDesktopTracking") { + hmdDesktopTracking = iter.value().toBool(); + } else if (iter.key() == "desktopMode") { + hmdDesktopMode = iter.value().toBool(); } iter++; } + + _hmdTrackingEnabled = !(hmdDesktopMode && !hmdDesktopTracking); + + qDebug() << "HMD desktop tracking Enabled" << _hmdTrackingEnabled << "-" << hmdDesktopMode << "-" << hmdDesktopTracking << !(hmdDesktopMode && !hmdDesktopTracking); } } @@ -735,11 +752,18 @@ void ViveControllerManager::InputDevice::handleHmd(uint32_t deviceIndex, const c _system->GetTrackedDeviceClass(deviceIndex) == vr::TrackedDeviceClass_HMD && _nextSimPoseData.vrPoses[deviceIndex].bPoseIsValid) { - const mat4& mat = _nextSimPoseData.poses[deviceIndex]; - const vec3 linearVelocity = _nextSimPoseData.linearVelocities[deviceIndex]; - const vec3 angularVelocity = _nextSimPoseData.angularVelocities[deviceIndex]; + if (_hmdTrackingEnabled){ + const mat4& mat = _nextSimPoseData.poses[deviceIndex]; + const vec3 linearVelocity = _nextSimPoseData.linearVelocities[deviceIndex]; + const vec3 angularVelocity = _nextSimPoseData.angularVelocities[deviceIndex]; - handleHeadPoseEvent(inputCalibrationData, mat, linearVelocity, angularVelocity); + handleHeadPoseEvent(inputCalibrationData, mat, linearVelocity, angularVelocity); + } else { + const mat4& mat = mat4(); + const vec3 zero = vec3(); + + handleHeadPoseEvent(inputCalibrationData, mat, zero, zero); + } } } diff --git a/plugins/openvr/src/ViveControllerManager.h b/plugins/openvr/src/ViveControllerManager.h index 4a7fcaf85e..cbe331feb3 100644 --- a/plugins/openvr/src/ViveControllerManager.h +++ b/plugins/openvr/src/ViveControllerManager.h @@ -113,7 +113,6 @@ private: void emitCalibrationStatus(); void calibrateNextFrame(); - class FilteredStick { public: glm::vec2 process(float deltaTime, const glm::vec2& stick) { @@ -195,6 +194,8 @@ private: bool _overrideHands { false }; mutable std::recursive_mutex _lock; + bool _hmdTrackingEnabled{ false }; + QString configToString(Config config); friend class ViveControllerManager; }; @@ -204,7 +205,10 @@ private: bool _registeredWithInputMapper { false }; bool _modelLoaded { false }; bool _resetMatCalculated { false }; + bool _desktopMode { false }; + bool _hmdDesktopTracking{ false }; + glm::mat4 _resetMat { glm::mat4() }; model::Geometry _modelGeometry; gpu::TexturePointer _texture;