From abe8cfe90fda01e13fa10ac60dd53726dc27446a Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 26 Jun 2015 16:17:11 -0700 Subject: [PATCH 1/2] Fix avatar displayname to point towards camera Previously it used the camera orientation, which means all display names have the same orientation, and will all rotate when you turn your head. Instead, you only want to change the orientation of a particular display name when you move. --- interface/src/avatar/Avatar.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index d0778481a6..bd2e07eb3a 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -708,9 +708,9 @@ Transform Avatar::calculateDisplayNameTransform(const ViewFrustum& frustum, floa glm::vec3 worldOffset = glm::vec3(screenOffset.x, screenOffset.y, 0.0f) / (float)pixelHeight; // Compute orientation - glm::vec3 eulerAngles = ::safeEulerAngles(frustum.getOrientation()); - eulerAngles.z = 0.0f; // Cancel roll - glm::quat orientation(eulerAngles); // back to quaternions + glm::vec3 dPosition = frustum.getPosition() - getPosition(); + float yawRotation = glm::atan(dPosition.x, dPosition.z); + glm::quat orientation = glm::quat(glm::vec3(0.0f, yawRotation, 0.0f)); // Set transform (The order IS important) result.setTranslation(textPosition); From 760a5bfa37feca4b0ba9f4e6fc03893193fbc1c0 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 26 Jun 2015 17:23:06 -0700 Subject: [PATCH 2/2] Fix call to atan2 when params are 0 --- interface/src/avatar/Avatar.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index bd2e07eb3a..e9388c413d 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -709,7 +709,8 @@ Transform Avatar::calculateDisplayNameTransform(const ViewFrustum& frustum, floa // Compute orientation glm::vec3 dPosition = frustum.getPosition() - getPosition(); - float yawRotation = glm::atan(dPosition.x, dPosition.z); + // If x and z are 0, atan(x, z) is undefined, so default to 0 degrees + float yawRotation = dPosition.x == 0.0f && dPosition.z == 0.0f ? 0.0f : glm::atan(dPosition.x, dPosition.z); glm::quat orientation = glm::quat(glm::vec3(0.0f, yawRotation, 0.0f)); // Set transform (The order IS important)