Prechádzať zdrojové kódy

Fixed GTC_matrix_inverse affineInverse #192

Christophe Riccio 10 rokov pred
rodič
commit
a4ed6568be
2 zmenil súbory, kde vykonal 14 pridanie a 12 odobranie
  1. 13 12
      glm/gtc/matrix_inverse.inl
  2. 1 0
      readme.md

+ 13 - 12
glm/gtc/matrix_inverse.inl

@@ -35,23 +35,24 @@ namespace glm
 	template <typename T, precision P>
 	GLM_FUNC_QUALIFIER tmat3x3<T, P> affineInverse(tmat3x3<T, P> const & m)
 	{
-		tmat3x3<T, P> Result(m);
-		Result[2] = tvec3<T, P>(0, 0, 1);
-		Result = transpose(Result);
-		tvec3<T, P> Translation = Result * tvec3<T, P>(-tvec2<T, P>(m[2]), m[2][2]);
-		Result[2] = Translation;
-		return Result;
+		tmat2x2<T, P> const Inv(inverse(tmat2x2<T, P>(m)));
+
+		return tmat3x3<T, P>(
+			tvec3<T, P>(Inv[0], static_cast<T>(0)),
+			tvec3<T, P>(Inv[1], static_cast<T>(0)),
+			tvec3<T, P>(-Inv * tvec2<T, P>(m[2]), static_cast<T>(1)));
 	}
 
 	template <typename T, precision P>
 	GLM_FUNC_QUALIFIER tmat4x4<T, P> affineInverse(tmat4x4<T, P> const & m)
 	{
-		tmat4x4<T, P> Result(m);
-		Result[3] = tvec4<T, P>(0, 0, 0, 1);
-		Result = transpose(Result);
-		tvec4<T, P> Translation = Result * tvec4<T, P>(-tvec3<T, P>(m[3]), m[3][3]);
-		Result[3] = Translation;
-		return Result;
+		tmat3x3<T, P> const Inv(inverse(tmat3x3<T, P>(m)));
+
+		return tmat4x4<T, P>(
+			tvec4<T, P>(Inv[0], static_cast<T>(0)),
+			tvec4<T, P>(Inv[1], static_cast<T>(0)),
+			tvec4<T, P>(Inv[2], static_cast<T>(0)),
+			tvec4<T, P>(-Inv * tvec3<T, P>(m[3]), static_cast<T>(1)));
 	}
 
 	template <typename T, precision P>

+ 1 - 0
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: