Browse Source

Fixed GTX_matrix_interpolation, issue #9

Christophe Riccio 13 years ago
parent
commit
b1ecabdd28
2 changed files with 19 additions and 1 deletions
  1. 6 0
      glm/gtx/matrix_interpolation.hpp
  2. 13 1
      glm/gtx/matrix_interpolation.inl

+ 6 - 0
glm/gtx/matrix_interpolation.hpp

@@ -65,6 +65,12 @@ namespace glm
         detail::tvec3<T> const & axis,
         detail::tvec3<T> const & axis,
         T const angle);
         T const angle);
 
 
+	//! Extracts the rotation part of a matrix.
+    //! From GLM_GTX_matrix_interpolation extension.
+	template <typename T>
+	detail::tmat4x4<T> extractMatrixRotation(
+		detail::tmat4x4<T> const & mat);
+
 	//! Build a interpolation of 4 * 4 matrixes.
 	//! Build a interpolation of 4 * 4 matrixes.
     //! From GLM_GTX_matrix_interpolation extension.
     //! From GLM_GTX_matrix_interpolation extension.
     //! Warning! works only with rotation and/or translation matrixes, scale will generate unexpected results.
     //! Warning! works only with rotation and/or translation matrixes, scale will generate unexpected results.

+ 13 - 1
glm/gtx/matrix_interpolation.inl

@@ -97,6 +97,18 @@ namespace glm
 		);
 		);
 	}
 	}
 
 
+	template <typename T>
+	GLM_FUNC_QUALIFIER detail::tmat4x4<T> extractMatrixRotation(
+		detail::tmat4x4<T> const & mat)
+	{
+		return detail::tmat4x4<T>(
+			mat[0][0], mat[0][1], mat[0][2], 0.0,
+			mat[1][0], mat[1][1], mat[1][2], 0.0,
+			mat[2][0], mat[2][1], mat[2][2], 0.0,
+			0.0,       0.0,       0.0,       1.0
+		);
+	}
+
 	template <typename T>
 	template <typename T>
 	GLM_FUNC_QUALIFIER detail::tmat4x4<T> interpolate
 	GLM_FUNC_QUALIFIER detail::tmat4x4<T> interpolate
 	(
 	(
@@ -109,7 +121,7 @@ namespace glm
 		detail::tvec3<T> dltAxis;
 		detail::tvec3<T> dltAxis;
 		T dltAngle;
 		T dltAngle;
 		axisAngle(dltRotation, dltAxis, dltAngle);
 		axisAngle(dltRotation, dltAxis, dltAngle);
-		detail::tmat4x4<T> out = axisAngleMatrix(dltAxis, dltAngle * delta) * rotationMatrix(m1);
+		detail::tmat4x4<T> out = axisAngleMatrix(dltAxis, dltAngle * delta) * extractMatrixRotation(m1);
 		out[3][0] = m1[3][0] + delta * (m2[3][0] - m1[3][0]);
 		out[3][0] = m1[3][0] + delta * (m2[3][0] - m1[3][0]);
 		out[3][1] = m1[3][1] + delta * (m2[3][1] - m1[3][1]);
 		out[3][1] = m1[3][1] + delta * (m2[3][1] - m1[3][1]);
 		out[3][2] = m1[3][2] + delta * (m2[3][2] - m1[3][2]);
 		out[3][2] = m1[3][2] + delta * (m2[3][2] - m1[3][2]);