From 115b63a1178fedbd28ed98ec446b3f342d625814 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Wed, 11 Nov 2015 15:54:48 -0800 Subject: [PATCH 1/3] Simplify rotationBetween --- libraries/shared/src/GLMHelpers.cpp | 25 +------------------------ 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/libraries/shared/src/GLMHelpers.cpp b/libraries/shared/src/GLMHelpers.cpp index dc7887c9f8..b57754066b 100644 --- a/libraries/shared/src/GLMHelpers.cpp +++ b/libraries/shared/src/GLMHelpers.cpp @@ -201,30 +201,7 @@ float angleBetween(const glm::vec3& v1, const glm::vec3& v2) { // Helper function return the rotation from the first vector onto the second glm::quat rotationBetween(const glm::vec3& v1, const glm::vec3& v2) { - float angle = angleBetween(v1, v2); - if (glm::isnan(angle) || angle < EPSILON) { - return glm::quat(); - } - glm::vec3 axis; - if (angle > 179.99f * RADIANS_PER_DEGREE) { // 180 degree rotation; must use another axis - axis = glm::cross(v1, glm::vec3(1.0f, 0.0f, 0.0f)); - float axisLength = glm::length(axis); - if (axisLength < EPSILON) { // parallel to x; y will work - axis = glm::normalize(glm::cross(v1, glm::vec3(0.0f, 1.0f, 0.0f))); - } else { - axis /= axisLength; - } - } else { - axis = glm::normalize(glm::cross(v1, v2)); - // It is possible for axis to be nan even when angle is not less than EPSILON. - // For example when angle is small but not tiny but v1 and v2 and have very short lengths. - if (glm::isnan(glm::dot(axis, axis))) { - // set angle and axis to values that will generate an identity rotation - angle = 0.0f; - axis = glm::vec3(1.0f, 0.0f, 0.0f); - } - } - return glm::angleAxis(angle, axis); + return glm::quat(glm::normalize(v1), glm::normalize(v2)); } bool isPointBehindTrianglesPlane(glm::vec3 point, glm::vec3 p0, glm::vec3 p1, glm::vec3 p2) { From e4897a8de77345e08800946c3433f3115cd32cf1 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Wed, 11 Nov 2015 15:58:27 -0800 Subject: [PATCH 2/3] Use new constants --- libraries/script-engine/src/Quat.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/script-engine/src/Quat.cpp b/libraries/script-engine/src/Quat.cpp index 14a6573415..bb74b20be0 100644 --- a/libraries/script-engine/src/Quat.cpp +++ b/libraries/script-engine/src/Quat.cpp @@ -64,15 +64,15 @@ glm::quat Quat::inverse(const glm::quat& q) { } glm::vec3 Quat::getFront(const glm::quat& orientation) { - return orientation * IDENTITY_FRONT; + return orientation * Vectors::FRONT; } glm::vec3 Quat::getRight(const glm::quat& orientation) { - return orientation * IDENTITY_RIGHT; + return orientation * Vectors::RIGHT; } glm::vec3 Quat::getUp(const glm::quat& orientation) { - return orientation * IDENTITY_UP; + return orientation * Vectors::UP; } glm::vec3 Quat::safeEulerAngles(const glm::quat& orientation) { From 118d05d824935f6dfd067c41e2b31667fe6b0227 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Wed, 11 Nov 2015 17:24:50 -0800 Subject: [PATCH 3/3] Use a clearer function --- libraries/shared/src/GLMHelpers.cpp | 2 +- libraries/shared/src/GLMHelpers.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/libraries/shared/src/GLMHelpers.cpp b/libraries/shared/src/GLMHelpers.cpp index b57754066b..fa010a85bd 100644 --- a/libraries/shared/src/GLMHelpers.cpp +++ b/libraries/shared/src/GLMHelpers.cpp @@ -201,7 +201,7 @@ float angleBetween(const glm::vec3& v1, const glm::vec3& v2) { // Helper function return the rotation from the first vector onto the second glm::quat rotationBetween(const glm::vec3& v1, const glm::vec3& v2) { - return glm::quat(glm::normalize(v1), glm::normalize(v2)); + return glm::rotation(glm::normalize(v1), glm::normalize(v2)); } bool isPointBehindTrianglesPlane(glm::vec3 point, glm::vec3 p0, glm::vec3 p1, glm::vec3 p2) { diff --git a/libraries/shared/src/GLMHelpers.h b/libraries/shared/src/GLMHelpers.h index 9c1bbe23a4..8d3410aaf2 100644 --- a/libraries/shared/src/GLMHelpers.h +++ b/libraries/shared/src/GLMHelpers.h @@ -16,6 +16,7 @@ #include #include +#include // Bring the most commonly used GLM types into the default namespace using glm::ivec2;