From b4c5bb6c1a494c8d24eaa205a244577c44b854d8 Mon Sep 17 00:00:00 2001 From: christophe Date: Sun, 12 Apr 2020 18:32:33 +0200 Subject: [PATCH] Fixed singularity check for quatLookAt #770 --- glm/gtc/quaternion.inl | 6 ++++-- readme.md | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/glm/gtc/quaternion.inl b/glm/gtc/quaternion.inl index 9dd037ee..06f9f020 100644 --- a/glm/gtc/quaternion.inl +++ b/glm/gtc/quaternion.inl @@ -175,7 +175,8 @@ namespace glm mat<3, 3, T, Q> Result; Result[2] = -direction; - Result[0] = normalize(cross(up, Result[2])); + vec<3, T, Q> const& Right = cross(up, Result[2]); + Result[0] = Right * inversesqrt(max(static_cast(0.00001), dot(Right, Right))); Result[1] = cross(Result[2], Result[0]); return quat_cast(Result); @@ -187,7 +188,8 @@ namespace glm mat<3, 3, T, Q> Result; Result[2] = direction; - Result[0] = normalize(cross(up, Result[2])); + vec<3, T, Q> const& Right = cross(up, Result[2]); + Result[0] = Right * inversesqrt(max(static_cast(0.00001), dot(Right, Right))); Result[1] = cross(Result[2], Result[0]); return quat_cast(Result); diff --git a/readme.md b/readme.md index 8971f179..7c15330f 100644 --- a/readme.md +++ b/readme.md @@ -65,6 +65,7 @@ glm::mat4 camera(float Translate, glm::vec2 const& Rotate) - Fixed unnecessary warnings from matrix_projection.inl #995 - Fixed quaternion slerp overload which interpolates with extra spins #996 - Fixed for glm::length using arch64 #992 +- Fixed singularity check for quatLookAt #770 ### [GLM 0.9.9.7](https://github.com/g-truc/glm/releases/tag/0.9.9.7) - 2020-01-05 #### Improvements: