From aefeff249346dc823c09b1fb17512d0d41aaeadd Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Mon, 7 Mar 2016 09:50:38 -0800 Subject: [PATCH 1/2] MyAvatar: Use a box instead of a sphere for horizontal re-centering --- interface/src/avatar/MyAvatar.cpp | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 642af5c3e9..7ffd138f26 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -1944,13 +1944,26 @@ bool MyAvatar::FollowHelper::shouldActivateRotation(const MyAvatar& myAvatar, co bool MyAvatar::FollowHelper::shouldActivateHorizontal(const MyAvatar& myAvatar, const glm::mat4& desiredBodyMatrix, const glm::mat4& currentBodyMatrix) const { - const float CYLINDER_RADIUS = 0.3f; - + // -z axis of currentBodyMatrix in world space. + glm::vec3 forward = glm::normalize(glm::vec3(-currentBodyMatrix[0][3], -currentBodyMatrix[1][3], -currentBodyMatrix[2][3])); + // x axis of currentBodyMatrix in world space. + glm::vec3 right = glm::normalize(glm::vec3(currentBodyMatrix[0][0], currentBodyMatrix[1][0], currentBodyMatrix[2][0])); glm::vec3 offset = extractTranslation(desiredBodyMatrix) - extractTranslation(currentBodyMatrix); - glm::vec3 radialOffset(offset.x, 0.0f, offset.z); - float radialDistance = glm::length(radialOffset); - return radialDistance > CYLINDER_RADIUS; + float forwardLeanAmount = glm::dot(forward, offset); + float lateralLeanAmount = glm::dot(right, offset); + + const float MAX_LATERAL_LEAN = 0.3f; + const float MAX_FORWARD_LEAN = 0.15f; + const float MAX_BACKWARD_LEAN = 0.1f; + + if (forwardLeanAmount > 0 && forwardLeanAmount > MAX_FORWARD_LEAN) { + return true; + } else if (forwardLeanAmount < 0 && forwardLeanAmount < -MAX_BACKWARD_LEAN) { + return true; + } + + return fabs(lateralLeanAmount) > MAX_LATERAL_LEAN; } bool MyAvatar::FollowHelper::shouldActivateVertical(const MyAvatar& myAvatar, const glm::mat4& desiredBodyMatrix, const glm::mat4& currentBodyMatrix) const { From 2cbb41fd387a3d866b70503cf3fbca055641f2ac Mon Sep 17 00:00:00 2001 From: Anthony Thibault Date: Mon, 7 Mar 2016 10:11:22 -0800 Subject: [PATCH 2/2] MyAvatar: bug fix for forward/backward lean detection --- interface/src/avatar/MyAvatar.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 7ffd138f26..fb309509a5 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -1945,7 +1945,7 @@ bool MyAvatar::FollowHelper::shouldActivateRotation(const MyAvatar& myAvatar, co bool MyAvatar::FollowHelper::shouldActivateHorizontal(const MyAvatar& myAvatar, const glm::mat4& desiredBodyMatrix, const glm::mat4& currentBodyMatrix) const { // -z axis of currentBodyMatrix in world space. - glm::vec3 forward = glm::normalize(glm::vec3(-currentBodyMatrix[0][3], -currentBodyMatrix[1][3], -currentBodyMatrix[2][3])); + glm::vec3 forward = glm::normalize(glm::vec3(-currentBodyMatrix[0][2], -currentBodyMatrix[1][2], -currentBodyMatrix[2][2])); // x axis of currentBodyMatrix in world space. glm::vec3 right = glm::normalize(glm::vec3(currentBodyMatrix[0][0], currentBodyMatrix[1][0], currentBodyMatrix[2][0])); glm::vec3 offset = extractTranslation(desiredBodyMatrix) - extractTranslation(currentBodyMatrix);