From 6f61bb4d2edbbb6b79fcb11596e91ceae48cae8c Mon Sep 17 00:00:00 2001 From: Olivier Sohn Date: Sat, 21 Oct 2017 21:17:55 +0200 Subject: [PATCH 1/3] Fix rotation when vectors are in the same direction #690 --- glm/gtx/quaternion.inl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/glm/gtx/quaternion.inl b/glm/gtx/quaternion.inl index 5595ec38..f57082fa 100644 --- a/glm/gtx/quaternion.inl +++ b/glm/gtx/quaternion.inl @@ -184,8 +184,10 @@ namespace glm T cosTheta = dot(orig, dest); vec<3, T, Q> rotationAxis; - if(cosTheta >= static_cast(1) - epsilon()) - return quat(); + if(cosTheta >= static_cast(1) - epsilon()) { + // orig and dest point in the same direction : return identity quaternion. + return quat(1, 0, 0, 0); + } if(cosTheta < static_cast(-1) + epsilon()) { From 6bd81b8fbc1038d1c8c7f6fb2c582a89673e9891 Mon Sep 17 00:00:00 2001 From: Olivier Sohn Date: Sat, 21 Oct 2017 21:43:47 +0200 Subject: [PATCH 2/3] use quat_identity --- glm/gtx/quaternion.inl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/glm/gtx/quaternion.inl b/glm/gtx/quaternion.inl index f57082fa..b99b869f 100644 --- a/glm/gtx/quaternion.inl +++ b/glm/gtx/quaternion.inl @@ -185,8 +185,8 @@ namespace glm vec<3, T, Q> rotationAxis; if(cosTheta >= static_cast(1) - epsilon()) { - // orig and dest point in the same direction : return identity quaternion. - return quat(1, 0, 0, 0); + // orig and dest point in the same direction + return quat_identity(); } if(cosTheta < static_cast(-1) + epsilon()) From ddb93dcdc2b4af4b5bac7f4905c3108fad7fc78b Mon Sep 17 00:00:00 2001 From: Olivier Sohn Date: Sat, 21 Oct 2017 21:50:36 +0200 Subject: [PATCH 3/3] fix build --- glm/gtx/quaternion.inl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glm/gtx/quaternion.inl b/glm/gtx/quaternion.inl index b99b869f..b29b53d8 100644 --- a/glm/gtx/quaternion.inl +++ b/glm/gtx/quaternion.inl @@ -186,7 +186,7 @@ namespace glm if(cosTheta >= static_cast(1) - epsilon()) { // orig and dest point in the same direction - return quat_identity(); + return quat_identity(); } if(cosTheta < static_cast(-1) + epsilon())