diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 53e40b5bd3..d33f752cfe 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1055,6 +1055,9 @@ void Application::paintGL() { displayPlugin->preRender(); _offscreenContext->makeCurrent(); + // update the avatar with a fresh HMD pose + _myAvatar->updateFromHMDSensorMatrix(getHMDSensorPose()); + auto lodManager = DependencyManager::get(); @@ -2895,9 +2898,6 @@ void Application::update(float deltaTime) { userInputMapper->getActionState(UserInputMapper::SHIFT), RIGHT_HAND_INDEX); } - // update the avatar with a fresh HMD pose - _myAvatar->updateFromHMDSensorMatrix(getHMDSensorPose(), deltaTime); - updateThreads(deltaTime); // If running non-threaded, then give the threads some time to process... updateCamera(deltaTime); // handle various camera tweaks like off axis projection diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 4cf1b69ce4..4fe9140b76 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -272,7 +272,15 @@ glm::mat4 MyAvatar::getSensorToWorldMatrix() const { // best called at start of main loop just after we have a fresh hmd pose. // update internal body position from new hmd pose. -void MyAvatar::updateFromHMDSensorMatrix(const glm::mat4& hmdSensorMatrix, float deltaTime) { +void MyAvatar::updateFromHMDSensorMatrix(const glm::mat4& hmdSensorMatrix) { + + auto now = usecTimestampNow(); + auto deltaUsecs = now - _lastUpdateFromHMDTime; + _lastUpdateFromHMDTime = now; + double actualDeltaTime = (double)deltaUsecs / (double)USECS_PER_SECOND; + const float BIGGEST_DELTA_TIME_SECS = 0.25f; + float deltaTime = glm::clamp((float)actualDeltaTime, 0.0f, BIGGEST_DELTA_TIME_SECS); + // update the sensorMatrices based on the new hmd pose _hmdSensorMatrix = hmdSensorMatrix; _hmdSensorPosition = extractTranslation(hmdSensorMatrix); diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index c1a6ada751..daa4424928 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -68,7 +68,7 @@ public: // best called at start of main loop just after we have a fresh hmd pose. // update internal body position from new hmd pose. - void updateFromHMDSensorMatrix(const glm::mat4& hmdSensorMatrix, float deltaTime); + void updateFromHMDSensorMatrix(const glm::mat4& hmdSensorMatrix); // best called at end of main loop, just before rendering. // update sensor to world matrix from current body position and hmd sensor. @@ -361,6 +361,8 @@ private: bool _straightingLean = false; float _straightingLeanAlpha = 0.0f; + + quint64 _lastUpdateFromHMDTime = usecTimestampNow(); }; QScriptValue audioListenModeToScriptValue(QScriptEngine* engine, const AudioListenerMode& audioListenerMode);