From 960ffd9c9e41054046d5238a03b2028e5fecb40c Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Fri, 18 Mar 2016 15:16:58 -0700 Subject: [PATCH] DisplayPlugins: updateHeadPose() no longer returns a value. Also, moved updateHeadPose so that the overlay and the main rendering use the same headPose. Which should also be the same place the latencyMarker for the ovr_GetTrackingState is set. --- interface/src/Application.cpp | 13 +++++++------ libraries/plugins/src/plugins/DisplayPlugin.h | 4 +--- plugins/oculus/src/OculusBaseDisplayPlugin.cpp | 9 ++------- plugins/oculus/src/OculusBaseDisplayPlugin.h | 2 +- plugins/openvr/src/OpenVrDisplayPlugin.cpp | 4 +--- plugins/openvr/src/OpenVrDisplayPlugin.h | 2 +- 6 files changed, 13 insertions(+), 21 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 786f29fc90..dc969d4ab4 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1418,6 +1418,12 @@ void Application::paintGL() { // FIXME not needed anymore? _offscreenContext->makeCurrent(); + // Tell the plugin what pose we're using to render. In this case we're just using the + // unmodified head pose because the only plugin that cares (the Oculus plugin) uses it + // for rotational timewarp. If we move to support positonal timewarp, we need to + // ensure this contains the full pose composed with the eye offsets. + displayPlugin->updateHeadPose(_frameCount); + // update the avatar with a fresh HMD pose getMyAvatar()->updateFromHMDSensorMatrix(getHMDSensorPose()); @@ -1598,12 +1604,7 @@ void Application::paintGL() { auto baseProjection = renderArgs._viewFrustum->getProjection(); auto hmdInterface = DependencyManager::get(); float IPDScale = hmdInterface->getIPDScale(); - - // Tell the plugin what pose we're using to render. In this case we're just using the - // unmodified head pose because the only plugin that cares (the Oculus plugin) uses it - // for rotational timewarp. If we move to support positonal timewarp, we need to - // ensure this contains the full pose composed with the eye offsets. - mat4 headPose = displayPlugin->updateHeadPose(_frameCount); + mat4 headPose = displayPlugin->getHeadPose(); // FIXME we probably don't need to set the projection matrix every frame, // only when the display plugin changes (or in non-HMD modes when the user diff --git a/libraries/plugins/src/plugins/DisplayPlugin.h b/libraries/plugins/src/plugins/DisplayPlugin.h index 376cec7b70..e5ac78036e 100644 --- a/libraries/plugins/src/plugins/DisplayPlugin.h +++ b/libraries/plugins/src/plugins/DisplayPlugin.h @@ -122,9 +122,7 @@ public: } // will query the underlying hmd api to compute the most recent head pose - virtual glm::mat4 updateHeadPose(uint32_t frameIndex) { - return glm::mat4(); - } + virtual void updateHeadPose(uint32_t frameIndex) {} // returns a copy of the most recent head pose, computed via updateHeadPose virtual glm::mat4 getHeadPose() const { diff --git a/plugins/oculus/src/OculusBaseDisplayPlugin.cpp b/plugins/oculus/src/OculusBaseDisplayPlugin.cpp index 0f87d526d7..7a4bcc665b 100644 --- a/plugins/oculus/src/OculusBaseDisplayPlugin.cpp +++ b/plugins/oculus/src/OculusBaseDisplayPlugin.cpp @@ -15,16 +15,11 @@ void OculusBaseDisplayPlugin::resetSensors() { ovr_RecenterPose(_session); } -glm::mat4 OculusBaseDisplayPlugin::updateHeadPose(uint32_t frameIndex) { - static uint32_t lastFrameSeen = 0; +void OculusBaseDisplayPlugin::updateHeadPose(uint32_t frameIndex) { auto displayTime = ovr_GetPredictedDisplayTime(_session, frameIndex); - auto trackingState = ovr_GetTrackingState(_session, displayTime, frameIndex > lastFrameSeen); - if (frameIndex > lastFrameSeen) { - lastFrameSeen = frameIndex; - } + auto trackingState = ovr_GetTrackingState(_session, displayTime, true); mat4 headPose = toGlm(trackingState.HeadPose.ThePose); _headPoseCache.set(headPose); - return headPose; } glm::mat4 OculusBaseDisplayPlugin::getHeadPose() const { diff --git a/plugins/oculus/src/OculusBaseDisplayPlugin.h b/plugins/oculus/src/OculusBaseDisplayPlugin.h index cf8f38fe3a..61179a632f 100644 --- a/plugins/oculus/src/OculusBaseDisplayPlugin.h +++ b/plugins/oculus/src/OculusBaseDisplayPlugin.h @@ -21,7 +21,7 @@ public: // Stereo specific methods virtual void resetSensors() override final; - virtual glm::mat4 updateHeadPose(uint32_t frameIndex) override; + virtual void updateHeadPose(uint32_t frameIndex) override; virtual glm::mat4 getHeadPose() const override; protected: diff --git a/plugins/openvr/src/OpenVrDisplayPlugin.cpp b/plugins/openvr/src/OpenVrDisplayPlugin.cpp index f5b80b0918..abc47577d1 100644 --- a/plugins/openvr/src/OpenVrDisplayPlugin.cpp +++ b/plugins/openvr/src/OpenVrDisplayPlugin.cpp @@ -112,7 +112,7 @@ void OpenVrDisplayPlugin::resetSensors() { _sensorResetMat = glm::inverse(cancelOutRollAndPitch(m)); } -glm::mat4 OpenVrDisplayPlugin::updateHeadPose(uint32_t frameIndex) { +void OpenVrDisplayPlugin::updateHeadPose(uint32_t frameIndex) { float displayFrequency = _system->GetFloatTrackedDeviceProperty(vr::k_unTrackedDeviceIndex_Hmd, vr::Prop_DisplayFrequency_Float); float frameDuration = 1.f / displayFrequency; @@ -141,8 +141,6 @@ glm::mat4 OpenVrDisplayPlugin::updateHeadPose(uint32_t frameIndex) { } _headPoseCache.set(_trackedDevicePoseMat4[0]); - - return _trackedDevicePoseMat4[0]; } glm::mat4 OpenVrDisplayPlugin::getHeadPose() const { diff --git a/plugins/openvr/src/OpenVrDisplayPlugin.h b/plugins/openvr/src/OpenVrDisplayPlugin.h index 7405aab82e..4f0320d237 100644 --- a/plugins/openvr/src/OpenVrDisplayPlugin.h +++ b/plugins/openvr/src/OpenVrDisplayPlugin.h @@ -28,7 +28,7 @@ public: // Stereo specific methods virtual void resetSensors() override; - virtual glm::mat4 updateHeadPose(uint32_t frameIndex) override; + virtual void updateHeadPose(uint32_t frameIndex) override; virtual glm::mat4 getHeadPose() const override; protected: