From 4af37668047ab36ae95ff2f563293e7e97a8719a Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Wed, 9 Mar 2016 14:28:26 -0800 Subject: [PATCH 1/6] Don't reset sensors when initializing or changing display plugins. This should fix the issue with the Oculus starting up with the UI aligned to the HMD on your desk, rather then the configured default sitting pose. --- interface/src/Application.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 660e597752..654e58c170 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -69,6 +69,7 @@ #include #include #include +#include #include #include #include @@ -3287,6 +3288,14 @@ void Application::update(float deltaTime) { // update sensorToWorldMatrix for rendering camera. myAvatar->updateSensorToWorldMatrix(); + + // AJT: TODO: make this a menu item. + const bool DRAW_SENSOR_TO_WORLD_MATRIX = true; + if (DRAW_SENSOR_TO_WORLD_MATRIX) { + // draw the origin of the room in world space. + glm::mat4 m = myAvatar->getSensorToWorldMatrix(); + DebugDraw::getInstance().addMarker("room", glmExtractRotation(m), extractTranslation(m), glm::vec4(1)); + } } @@ -4811,7 +4820,7 @@ void Application::updateDisplayMode() { } } emit activeDisplayPluginChanged(); - resetSensors(); + Q_ASSERT_X(_displayPlugin, "Application::updateDisplayMode", "could not find an activated display plugin"); } From 5df616be37406f5385ec5f58965501c55438dcd2 Mon Sep 17 00:00:00 2001 From: Anthony Thibault Date: Wed, 9 Mar 2016 16:24:08 -0800 Subject: [PATCH 2/6] OpenVR: More usable UI Sphere overlay location Also, added a debug option to display SensorToWorld matrix in Developer > Avatar menu. --- interface/src/Application.cpp | 8 -------- interface/src/Menu.cpp | 2 ++ interface/src/Menu.h | 1 + interface/src/avatar/MyAvatar.cpp | 12 ++++++++++++ interface/src/avatar/MyAvatar.h | 2 ++ plugins/openvr/src/OpenVrDisplayPlugin.cpp | 17 ++++++++++++++++- 6 files changed, 33 insertions(+), 9 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 654e58c170..d575160f99 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -3288,14 +3288,6 @@ void Application::update(float deltaTime) { // update sensorToWorldMatrix for rendering camera. myAvatar->updateSensorToWorldMatrix(); - - // AJT: TODO: make this a menu item. - const bool DRAW_SENSOR_TO_WORLD_MATRIX = true; - if (DRAW_SENSOR_TO_WORLD_MATRIX) { - // draw the origin of the room in world space. - glm::mat4 m = myAvatar->getSensorToWorldMatrix(); - DebugDraw::getInstance().addMarker("room", glmExtractRotation(m), extractTranslation(m), glm::vec4(1)); - } } diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index d605516380..919ee0f3c3 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -471,6 +471,8 @@ Menu::Menu() { avatar, SLOT(setUseAnimPreAndPostRotations(bool))); addCheckableActionToQMenuAndActionHash(avatarDebugMenu, MenuOption::EnableInverseKinematics, 0, true, avatar, SLOT(setEnableInverseKinematics(bool))); + addCheckableActionToQMenuAndActionHash(avatarDebugMenu, MenuOption::RenderSensorToWorldMatrix, 0, false, + avatar, SLOT(setEnableDebugDrawSensorToWorldMatrix(bool))); addCheckableActionToQMenuAndActionHash(avatarDebugMenu, MenuOption::KeyboardMotorControl, Qt::CTRL | Qt::SHIFT | Qt::Key_K, true, avatar, SLOT(updateMotionBehaviorFromMenu()), diff --git a/interface/src/Menu.h b/interface/src/Menu.h index fb00416af0..8ffd7efb36 100644 --- a/interface/src/Menu.h +++ b/interface/src/Menu.h @@ -144,6 +144,7 @@ namespace MenuOption { const QString RenderResolutionHalf = "1/2"; const QString RenderResolutionThird = "1/3"; const QString RenderResolutionQuarter = "1/4"; + const QString RenderSensorToWorldMatrix = "Show SensorToWorld Matrix"; const QString ResetAvatarSize = "Reset Avatar Size"; const QString ResetSensors = "Reset Sensors"; const QString RunningScripts = "Running Scripts..."; diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 397627434f..a5b69f2be6 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -442,6 +442,10 @@ void MyAvatar::updateSensorToWorldMatrix() { _sensorToWorldMatrix = desiredMat * glm::inverse(_bodySensorMatrix); lateUpdatePalms(); + + if (_enableDebugDrawSensorToWorldMatrix) { + DebugDraw::getInstance().addMarker("sensorToWorldMatrix", glmExtractRotation(_sensorToWorldMatrix), extractTranslation(_sensorToWorldMatrix), glm::vec4(1)); + } } // Update avatar head rotation with sensor data @@ -695,6 +699,14 @@ void MyAvatar::setEnableDebugDrawPosition(bool isEnabled) { } } +void MyAvatar::setEnableDebugDrawSensorToWorldMatrix(bool isEnabled) { + _enableDebugDrawSensorToWorldMatrix = isEnabled; + + if (!isEnabled) { + DebugDraw::getInstance().removeMarker("sensorToWorldMatrix"); + } +} + void MyAvatar::setEnableMeshVisible(bool isEnabled) { render::ScenePointer scene = qApp->getMain3DScene(); _skeletonModel.setVisibleInScene(isEnabled, scene); diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index 731cba8153..8e5c1796b1 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -267,6 +267,7 @@ public slots: void setEnableDebugDrawDefaultPose(bool isEnabled); void setEnableDebugDrawAnimPose(bool isEnabled); void setEnableDebugDrawPosition(bool isEnabled); + void setEnableDebugDrawSensorToWorldMatrix(bool isEnabled); bool getEnableMeshVisible() const { return _skeletonModel.isVisible(); } void setEnableMeshVisible(bool isEnabled); void setUseAnimPreAndPostRotations(bool isEnabled); @@ -429,6 +430,7 @@ private: bool _enableDebugDrawDefaultPose { false }; bool _enableDebugDrawAnimPose { false }; + bool _enableDebugDrawSensorToWorldMatrix { false }; AudioListenerMode _audioListenerMode; glm::vec3 _customListenPosition; diff --git a/plugins/openvr/src/OpenVrDisplayPlugin.cpp b/plugins/openvr/src/OpenVrDisplayPlugin.cpp index e5708572f6..57a896dd4d 100644 --- a/plugins/openvr/src/OpenVrDisplayPlugin.cpp +++ b/plugins/openvr/src/OpenVrDisplayPlugin.cpp @@ -68,6 +68,21 @@ void OpenVrDisplayPlugin::activate() { _compositor = vr::VRCompositor(); Q_ASSERT(_compositor); HmdDisplayPlugin::activate(); + + // set up default sensor space such that the UI overlay will align with the front of the room. + auto chaperone = vr::VRChaperone(); + if (chaperone) { + float const UI_RADIUS = 1.0f; + float const UI_HEIGHT = 1.6f; + float const UI_Z_OFFSET = 0.5; + + float xSize, zSize; + chaperone->GetPlayAreaSize(&xSize, &zSize); + glm::vec3 uiPos(0.0f, UI_HEIGHT, 0.5f * zSize - UI_RADIUS + UI_Z_OFFSET); + _sensorResetMat = glm::inverse(createMatFromQuatAndPos(Quaternions::Y_180, uiPos)); + } else { + qDebug() << "OpenVR: error could not get chaperone pointer"; + } } void OpenVrDisplayPlugin::deactivate() { @@ -115,7 +130,7 @@ glm::mat4 OpenVrDisplayPlugin::getHeadPose(uint32_t frameIndex) const { #endif vr::TrackedDevicePose_t predictedTrackedDevicePose[vr::k_unMaxTrackedDeviceCount]; - _system->GetDeviceToAbsoluteTrackingPose(vr::TrackingUniverseSeated, predictedSecondsFromNow, predictedTrackedDevicePose, vr::k_unMaxTrackedDeviceCount); + _system->GetDeviceToAbsoluteTrackingPose(vr::TrackingUniverseStanding, predictedSecondsFromNow, predictedTrackedDevicePose, vr::k_unMaxTrackedDeviceCount); // copy and process predictedTrackedDevicePoses for (int i = 0; i < vr::k_unMaxTrackedDeviceCount; i++) { From 5f1b8805cf76d9b7ef96341ac58a8a49e9a4c3df Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Wed, 9 Mar 2016 17:37:51 -0800 Subject: [PATCH 3/6] Removed unnecessary include --- interface/src/Application.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 426efbd914..66662a7500 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -69,7 +69,6 @@ #include #include #include -#include #include #include #include From 42d27557a11ed30db5c1869c87c72fabce0cae1b Mon Sep 17 00:00:00 2001 From: Anthony Thibault Date: Wed, 9 Mar 2016 18:42:03 -0800 Subject: [PATCH 4/6] OpenVR: remove 180 y rotation for UI bounds. Turns out the room I was using was misconfigured. --- plugins/openvr/src/OpenVrDisplayPlugin.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/openvr/src/OpenVrDisplayPlugin.cpp b/plugins/openvr/src/OpenVrDisplayPlugin.cpp index 57a896dd4d..83c834161b 100644 --- a/plugins/openvr/src/OpenVrDisplayPlugin.cpp +++ b/plugins/openvr/src/OpenVrDisplayPlugin.cpp @@ -79,7 +79,7 @@ void OpenVrDisplayPlugin::activate() { float xSize, zSize; chaperone->GetPlayAreaSize(&xSize, &zSize); glm::vec3 uiPos(0.0f, UI_HEIGHT, 0.5f * zSize - UI_RADIUS + UI_Z_OFFSET); - _sensorResetMat = glm::inverse(createMatFromQuatAndPos(Quaternions::Y_180, uiPos)); + _sensorResetMat = glm::inverse(createMatFromQuatAndPos(glm::quat(), uiPos)); } else { qDebug() << "OpenVR: error could not get chaperone pointer"; } From 153f7fc3aa9088fffdcc22b3524a0877da9aa996 Mon Sep 17 00:00:00 2001 From: Anthony Thibault Date: Thu, 10 Mar 2016 09:45:47 -0800 Subject: [PATCH 5/6] OpenVR: adjusted translation of UI sphere overlay --- plugins/openvr/src/OpenVrDisplayPlugin.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/openvr/src/OpenVrDisplayPlugin.cpp b/plugins/openvr/src/OpenVrDisplayPlugin.cpp index 83c834161b..b86a7f9ebc 100644 --- a/plugins/openvr/src/OpenVrDisplayPlugin.cpp +++ b/plugins/openvr/src/OpenVrDisplayPlugin.cpp @@ -78,7 +78,7 @@ void OpenVrDisplayPlugin::activate() { float xSize, zSize; chaperone->GetPlayAreaSize(&xSize, &zSize); - glm::vec3 uiPos(0.0f, UI_HEIGHT, 0.5f * zSize - UI_RADIUS + UI_Z_OFFSET); + glm::vec3 uiPos(0.0f, UI_HEIGHT, UI_RADIUS - (0.5f * zSize) - UI_Z_OFFSET); _sensorResetMat = glm::inverse(createMatFromQuatAndPos(glm::quat(), uiPos)); } else { qDebug() << "OpenVR: error could not get chaperone pointer"; From 6d11dd465ca50b2a7fffaf00b3da4dee5c0753a2 Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Thu, 10 Mar 2016 13:12:09 -0800 Subject: [PATCH 6/6] Application: reset avatar on displayMode change but not HMD sensor. --- interface/src/Application.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 66662a7500..795145ca5c 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -4857,6 +4857,9 @@ void Application::updateDisplayMode() { } emit activeDisplayPluginChanged(); + // reset the avatar, to set head and hand palms back to a resonable default pose. + getMyAvatar()->reset(false); + Q_ASSERT_X(_displayPlugin, "Application::updateDisplayMode", "could not find an activated display plugin"); }