Fixed GTX_matrix_interpolation, issue #9

This commit is contained in:
Christophe Riccio 2012-09-19 19:14:45 +02:00
parent 7e3f00d034
commit b1ecabdd28
2 changed files with 19 additions and 1 deletions

View File

@ -65,6 +65,12 @@ namespace glm
detail::tvec3<T> const & axis,
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.
//! From GLM_GTX_matrix_interpolation extension.
//! Warning! works only with rotation and/or translation matrixes, scale will generate unexpected results.

View File

@ -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>
GLM_FUNC_QUALIFIER detail::tmat4x4<T> interpolate
(
@ -109,7 +121,7 @@ namespace glm
detail::tvec3<T> dltAxis;
T 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][1] = m1[3][1] + delta * (m2[3][1] - m1[3][1]);
out[3][2] = m1[3][2] + delta * (m2[3][2] - m1[3][2]);