From 942f2c13ab38c3a27be390291f546c0882c28b73 Mon Sep 17 00:00:00 2001 From: Anthony Thibault Date: Fri, 19 Feb 2016 15:58:13 -0800 Subject: [PATCH] Vive: smoother updates for IK driven by vive controllers Before this PR the simulation rate was clamped to never exceed 60htz. This had problems when waving the vive hand controllers in the world, they would jitter. The simulation rate is now clamped to never exceed 120 htz. This has the effect of synchronizing the display and the update rates to 90htz. Also there are improvements to vive support if threaded present is disabled. --- interface/src/Application.cpp | 3 ++- plugins/openvr/src/OpenVrDisplayPlugin.cpp | 9 +++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index c202331041..670df573a7 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -210,7 +210,7 @@ static const QString INFO_EDIT_ENTITIES_PATH = "html/edit-commands.html"; static const unsigned int THROTTLED_SIM_FRAMERATE = 15; static const int THROTTLED_SIM_FRAME_PERIOD_MS = MSECS_PER_SECOND / THROTTLED_SIM_FRAMERATE; -static const unsigned int CAPPED_SIM_FRAMERATE = 60; +static const unsigned int CAPPED_SIM_FRAMERATE = 120; static const int CAPPED_SIM_FRAME_PERIOD_MS = MSECS_PER_SECOND / CAPPED_SIM_FRAMERATE; static const uint32_t INVALID_FRAME = UINT32_MAX; @@ -1733,6 +1733,7 @@ bool Application::event(QEvent* event) { if ((int)event->type() == (int)Paint) { paintGL(); + return true; } if (!_keyboardFocusedItem.isInvalidID()) { diff --git a/plugins/openvr/src/OpenVrDisplayPlugin.cpp b/plugins/openvr/src/OpenVrDisplayPlugin.cpp index 353b248302..efd230bc28 100644 --- a/plugins/openvr/src/OpenVrDisplayPlugin.cpp +++ b/plugins/openvr/src/OpenVrDisplayPlugin.cpp @@ -101,9 +101,16 @@ glm::mat4 OpenVrDisplayPlugin::getHeadPose(uint32_t frameIndex) const { float frameDuration = 1.f / displayFrequency; float vsyncToPhotons = _system->GetFloatTrackedDeviceProperty(vr::k_unTrackedDeviceIndex_Hmd, vr::Prop_SecondsFromVsyncToPhotons_Float); +#if THREADED_PRESENT // TODO: this seems awfuly long, 44ms total, but it produced the best results. const float NUM_PREDICTION_FRAMES = 3.0f; float predictedSecondsFromNow = NUM_PREDICTION_FRAMES * frameDuration + vsyncToPhotons; +#else + uint64_t frameCounter; + float timeSinceLastVsync; + _system->GetTimeSinceLastVsync(&timeSinceLastVsync, &frameCounter); + float predictedSecondsFromNow = 3.0f * frameDuration - timeSinceLastVsync + vsyncToPhotons; +#endif vr::TrackedDevicePose_t predictedTrackedDevicePose[vr::k_unMaxTrackedDeviceCount]; _system->GetDeviceToAbsoluteTrackingPose(vr::TrackingUniverseSeated, predictedSecondsFromNow, predictedTrackedDevicePose, vr::k_unMaxTrackedDeviceCount); @@ -126,8 +133,6 @@ void OpenVrDisplayPlugin::internalPresent() { _compositor->Submit(vr::Eye_Left, &texture, &leftBounds); _compositor->Submit(vr::Eye_Right, &texture, &rightBounds); - glFinish(); - vr::TrackedDevicePose_t currentTrackedDevicePose[vr::k_unMaxTrackedDeviceCount]; _compositor->WaitGetPoses(currentTrackedDevicePose, vr::k_unMaxTrackedDeviceCount, nullptr, 0);