From a4ed6568be3cb522023952ba3dff17792ad9d570 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Thu, 1 Oct 2015 22:20:30 +0200 Subject: [PATCH] Fixed GTC_matrix_inverse affineInverse #192 --- glm/gtc/matrix_inverse.inl | 25 +++++++++++++------------ readme.md | 1 + 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/glm/gtc/matrix_inverse.inl b/glm/gtc/matrix_inverse.inl index d88a3319..d2437d5d 100644 --- a/glm/gtc/matrix_inverse.inl +++ b/glm/gtc/matrix_inverse.inl @@ -35,23 +35,24 @@ namespace glm template GLM_FUNC_QUALIFIER tmat3x3 affineInverse(tmat3x3 const & m) { - tmat3x3 Result(m); - Result[2] = tvec3(0, 0, 1); - Result = transpose(Result); - tvec3 Translation = Result * tvec3(-tvec2(m[2]), m[2][2]); - Result[2] = Translation; - return Result; + tmat2x2 const Inv(inverse(tmat2x2(m))); + + return tmat3x3( + tvec3(Inv[0], static_cast(0)), + tvec3(Inv[1], static_cast(0)), + tvec3(-Inv * tvec2(m[2]), static_cast(1))); } template GLM_FUNC_QUALIFIER tmat4x4 affineInverse(tmat4x4 const & m) { - tmat4x4 Result(m); - Result[3] = tvec4(0, 0, 0, 1); - Result = transpose(Result); - tvec4 Translation = Result * tvec4(-tvec3(m[3]), m[3][3]); - Result[3] = Translation; - return Result; + tmat3x3 const Inv(inverse(tmat3x3(m))); + + return tmat4x4( + tvec4(Inv[0], static_cast(0)), + tvec4(Inv[1], static_cast(0)), + tvec4(Inv[2], static_cast(0)), + tvec4(-Inv * tvec3(m[3]), static_cast(1))); } template diff --git a/readme.md b/readme.md index 8265447a..8d18090f 100644 --- a/readme.md +++ b/readme.md @@ -55,6 +55,7 @@ glm::mat4 camera(float Translate, glm::vec2 const & Rotate) ##### Fixes: - Fixed GTC_round floorMultiple/ceilMultiple #412 - Fixed GTC_packing unpackUnorm3x10_1x2 #414 +- Fixed GTC_matrix_inverse affineInverse #192 #### [GLM 0.9.7.1](https://github.com/g-truc/glm/releases/tag/0.9.7.1) - 2015-09-07 ##### Improvements: