From 287f710ea138a6fc6ce4e8630d3de7e3e9dc35fd Mon Sep 17 00:00:00 2001 From: Phil Palmer Date: Tue, 22 Dec 2020 19:32:43 -0500 Subject: [PATCH] Fix MyAvatar::centerBody breaking existing scripts (eg. away.js) by having a new parameter: Moved the body of the function to a private internal method (centerBodyInternal), which takes the parameter instead. Previously, when leaving 'away' state, the 'Away' overlay would stay on screen because of the bug. The bug started in "VR fixes for: couldn't sit on the floor, wrong walk directions." (2179c153de8bd8d1b455894e9ccd3699df133c3f). --- interface/src/avatar/MyAvatar.cpp | 16 ++++++++++------ interface/src/avatar/MyAvatar.h | 3 ++- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index e5413105f8..be5fa39e1b 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -497,14 +497,18 @@ void MyAvatar::resetSensorsAndBody() { reset(true, false, true); } -// forceFollowYPos: true to force the body matrix to be affected by the HMD's -// vertical position, even if crouch recentering is disabled. -void MyAvatar::centerBody(const bool forceFollowYPos) { +void MyAvatar::centerBody() { if (QThread::currentThread() != thread()) { QMetaObject::invokeMethod(this, "centerBody"); return; } + centerBodyInternal(false); +} + +// forceFollowYPos (default false): true to force the body matrix to be affected by the HMD's +// vertical position, even if crouch recentering is disabled. +void MyAvatar::centerBodyInternal(const bool forceFollowYPos) { // derive the desired body orientation from the current hmd orientation, before the sensor reset. auto newBodySensorMatrix = deriveBodyFromHMDSensor(forceFollowYPos); // Based on current cached HMD position/rotation.. @@ -5323,7 +5327,7 @@ void MyAvatar::setAllowAvatarStandingPreference(const MyAvatar::AllowAvatarStand // Set the correct vertical position for the avatar body relative to the HMD, // according to the newly-selected avatar standing preference. - centerBody(false); + centerBodyInternal(false); } // Set the user preference of when the avatar may lean. @@ -6693,7 +6697,7 @@ void MyAvatar::beginSit(const glm::vec3& position, const glm::quat& rotation) { setHMDLeanRecenterEnabled(false); // Disable movement setSitDriveKeysStatus(false); - centerBody(true); + centerBodyInternal(true); int hipIndex = getJointIndex("Hips"); clearPinOnJoint(hipIndex); pinJoint(hipIndex, position, rotation); @@ -6711,7 +6715,7 @@ void MyAvatar::endSit(const glm::vec3& position, const glm::quat& rotation) { _characterController.setSeated(false); setCollisionsEnabled(true); setHMDLeanRecenterEnabled(true); - centerBody(false); + centerBodyInternal(false); slamPosition(position); setWorldOrientation(rotation); diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index 9e817b5167..c06a1a88ab 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -594,7 +594,7 @@ public: * the HMD. * @function MyAvatar.centerBody */ - Q_INVOKABLE void centerBody(const bool forceFollowYPos); // thread-safe + Q_INVOKABLE void centerBody(); // thread-safe /**jsdoc @@ -2812,6 +2812,7 @@ private: void resetLookAtRotation(const glm::vec3& avatarPosition, const glm::quat& avatarOrientation); void resetPointAt(); static glm::vec3 aimToBlendValues(const glm::vec3& aimVector, const glm::quat& frameOrientation); + void centerBodyInternal(const bool forceFollowYPos = false); // Avatar Preferences QUrl _fullAvatarURLFromPreferences;