From c03ebcc688b2b8ab084cb36691210529b09d78f0 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Wed, 25 Dec 2013 06:30:52 +0100 Subject: [PATCH] Refactored transpose function --- glm/detail/func_matrix.hpp | 19 +- glm/detail/func_matrix.inl | 520 ++++++++++++++++++------------------- 2 files changed, 260 insertions(+), 279 deletions(-) diff --git a/glm/detail/func_matrix.hpp b/glm/detail/func_matrix.hpp index 34f4f61d..e4adc5ba 100644 --- a/glm/detail/func_matrix.hpp +++ b/glm/detail/func_matrix.hpp @@ -56,10 +56,8 @@ namespace glm /// /// @see GLSL matrixCompMult man page /// @see GLSL 4.20.8 specification, section 8.6 Matrix Functions - template - GLM_FUNC_DECL matType matrixCompMult( - matType const & x, - matType const & y); + template class matType> + GLM_FUNC_DECL matType matrixCompMult(matType const & x, matType const & y); /// Treats the first parameter c as a column vector /// and the second parameter r as a row vector @@ -72,9 +70,7 @@ namespace glm /// /// @todo Clarify the declaration to specify that matType doesn't have to be provided when used. template - GLM_FUNC_DECL matType outerProduct( - vecType const & c, - vecType const & r); + GLM_FUNC_DECL matType outerProduct(vecType const & c, vecType const & r); /// Returns the transposed matrix of x /// @@ -83,8 +79,7 @@ namespace glm /// @see GLSL transpose man page /// @see GLSL 4.20.8 specification, section 8.6 Matrix Functions template - GLM_FUNC_DECL typename matType::transpose_type transpose( - matType const & x); + GLM_FUNC_DECL typename matType::transpose_type transpose(matType const & x); /// Return the determinant of a squared matrix. /// @@ -93,8 +88,7 @@ namespace glm /// @see GLSL determinant man page /// @see GLSL 4.20.8 specification, section 8.6 Matrix Functions template class matType> - GLM_FUNC_DECL T determinant( - matType const & m); + GLM_FUNC_DECL T determinant(matType const & m); /// Return the inverse of a squared matrix. /// @@ -103,8 +97,7 @@ namespace glm /// @see GLSL inverse man page /// @see GLSL 4.20.8 specification, section 8.6 Matrix Functions template class matType> - GLM_FUNC_DECL matType inverse( - matType const & m); + GLM_FUNC_DECL matType inverse(matType const & m); /// @} }//namespace glm diff --git a/glm/detail/func_matrix.inl b/glm/detail/func_matrix.inl index 3f178bb2..a3e668bd 100644 --- a/glm/detail/func_matrix.inl +++ b/glm/detail/func_matrix.inl @@ -43,22 +43,6 @@ namespace glm { - // matrixCompMult - template - GLM_FUNC_QUALIFIER matType matrixCompMult - ( - matType const & x, - matType const & y - ) - { - GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'matrixCompMult' only accept floating-point inputs"); - - matType result(matType::_null); - for(length_t i = 0; i < result.length(); ++i) - result[i] = x[i] * y[i]; - return result; - } - // outerProduct template GLM_FUNC_QUALIFIER detail::tmat2x2 outerProduct @@ -237,254 +221,236 @@ namespace glm return m; } - template - GLM_FUNC_QUALIFIER detail::tmat2x2 transpose - ( - detail::tmat2x2 const & m - ) - { - GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'transpose' only accept floating-point inputs"); - - detail::tmat2x2 result(detail::tmat2x2::_null); - result[0][0] = m[0][0]; - result[0][1] = m[1][0]; - result[1][0] = m[0][1]; - result[1][1] = m[1][1]; - return result; - } - - template - GLM_FUNC_QUALIFIER detail::tmat3x3 transpose - ( - detail::tmat3x3 const & m - ) - { - GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'transpose' only accept floating-point inputs"); - - detail::tmat3x3 result(detail::tmat3x3::_null); - result[0][0] = m[0][0]; - result[0][1] = m[1][0]; - result[0][2] = m[2][0]; - - result[1][0] = m[0][1]; - result[1][1] = m[1][1]; - result[1][2] = m[2][1]; - - result[2][0] = m[0][2]; - result[2][1] = m[1][2]; - result[2][2] = m[2][2]; - return result; - } - - template - GLM_FUNC_QUALIFIER detail::tmat4x4 transpose - ( - detail::tmat4x4 const & m - ) - { - GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'transpose' only accept floating-point inputs"); - - detail::tmat4x4 result(detail::tmat4x4::_null); - result[0][0] = m[0][0]; - result[0][1] = m[1][0]; - result[0][2] = m[2][0]; - result[0][3] = m[3][0]; - - result[1][0] = m[0][1]; - result[1][1] = m[1][1]; - result[1][2] = m[2][1]; - result[1][3] = m[3][1]; - - result[2][0] = m[0][2]; - result[2][1] = m[1][2]; - result[2][2] = m[2][2]; - result[2][3] = m[3][2]; - - result[3][0] = m[0][3]; - result[3][1] = m[1][3]; - result[3][2] = m[2][3]; - result[3][3] = m[3][3]; - return result; - } - - template - GLM_FUNC_QUALIFIER detail::tmat2x3 transpose - ( - detail::tmat3x2 const & m - ) - { - GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'transpose' only accept floating-point inputs"); - - detail::tmat2x3 result(detail::tmat2x3::_null); - result[0][0] = m[0][0]; - result[0][1] = m[1][0]; - result[0][2] = m[2][0]; - result[1][0] = m[0][1]; - result[1][1] = m[1][1]; - result[1][2] = m[2][1]; - return result; - } - - template - GLM_FUNC_QUALIFIER detail::tmat3x2 transpose - ( - detail::tmat2x3 const & m - ) - { - GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'transpose' only accept floating-point inputs"); - - detail::tmat3x2 result(detail::tmat3x2::_null); - result[0][0] = m[0][0]; - result[0][1] = m[1][0]; - result[1][0] = m[0][1]; - result[1][1] = m[1][1]; - result[2][0] = m[0][2]; - result[2][1] = m[1][2]; - return result; - } - - template - GLM_FUNC_QUALIFIER detail::tmat2x4 transpose - ( - detail::tmat4x2 const & m - ) - { - GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'transpose' only accept floating-point inputs"); - - detail::tmat2x4 result(detail::tmat2x4::_null); - result[0][0] = m[0][0]; - result[0][1] = m[1][0]; - result[0][2] = m[2][0]; - result[0][3] = m[3][0]; - result[1][0] = m[0][1]; - result[1][1] = m[1][1]; - result[1][2] = m[2][1]; - result[1][3] = m[3][1]; - return result; - } - - template - GLM_FUNC_QUALIFIER detail::tmat4x2 transpose - ( - detail::tmat2x4 const & m - ) - { - GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'transpose' only accept floating-point inputs"); - - detail::tmat4x2 result(detail::tmat4x2::_null); - result[0][0] = m[0][0]; - result[0][1] = m[1][0]; - result[1][0] = m[0][1]; - result[1][1] = m[1][1]; - result[2][0] = m[0][2]; - result[2][1] = m[1][2]; - result[3][0] = m[0][3]; - result[3][1] = m[1][3]; - return result; - } - - template - GLM_FUNC_QUALIFIER detail::tmat3x4 transpose - ( - detail::tmat4x3 const & m - ) - { - GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'transpose' only accept floating-point inputs"); - - detail::tmat3x4 result(detail::tmat3x4::_null); - result[0][0] = m[0][0]; - result[0][1] = m[1][0]; - result[0][2] = m[2][0]; - result[0][3] = m[3][0]; - result[1][0] = m[0][1]; - result[1][1] = m[1][1]; - result[1][2] = m[2][1]; - result[1][3] = m[3][1]; - result[2][0] = m[0][2]; - result[2][1] = m[1][2]; - result[2][2] = m[2][2]; - result[2][3] = m[3][2]; - return result; - } - - template - GLM_FUNC_QUALIFIER detail::tmat4x3 transpose - ( - detail::tmat3x4 const & m - ) - { - GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'transpose' only accept floating-point inputs"); - - detail::tmat4x3 result(detail::tmat4x3::_null); - result[0][0] = m[0][0]; - result[0][1] = m[1][0]; - result[0][2] = m[2][0]; - result[1][0] = m[0][1]; - result[1][1] = m[1][1]; - result[1][2] = m[2][1]; - result[2][0] = m[0][2]; - result[2][1] = m[1][2]; - result[2][2] = m[2][2]; - result[3][0] = m[0][3]; - result[3][1] = m[1][3]; - result[3][2] = m[2][3]; - return result; - } - - template - GLM_FUNC_QUALIFIER typename detail::tmat2x2::value_type determinant - ( - detail::tmat2x2 const & m - ) - { - GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'determinant' only accept floating-point inputs"); - - return m[0][0] * m[1][1] - m[1][0] * m[0][1]; - } - - template - GLM_FUNC_QUALIFIER typename detail::tmat3x3::value_type determinant - ( - detail::tmat3x3 const & m - ) - { - GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'determinant' only accept floating-point inputs"); - - return - + m[0][0] * (m[1][1] * m[2][2] - m[2][1] * m[1][2]) - - m[1][0] * (m[0][1] * m[2][2] - m[2][1] * m[0][2]) - + m[2][0] * (m[0][1] * m[1][2] - m[1][1] * m[0][2]); - } - - template - GLM_FUNC_QUALIFIER typename detail::tmat4x4::value_type determinant - ( - detail::tmat4x4 const & m - ) - { - GLM_STATIC_ASSERT(std::numeric_limits::is_iec559, "'determinant' only accept floating-point inputs"); - - T SubFactor00 = m[2][2] * m[3][3] - m[3][2] * m[2][3]; - T SubFactor01 = m[2][1] * m[3][3] - m[3][1] * m[2][3]; - T SubFactor02 = m[2][1] * m[3][2] - m[3][1] * m[2][2]; - T SubFactor03 = m[2][0] * m[3][3] - m[3][0] * m[2][3]; - T SubFactor04 = m[2][0] * m[3][2] - m[3][0] * m[2][2]; - T SubFactor05 = m[2][0] * m[3][1] - m[3][0] * m[2][1]; - - detail::tvec4 DetCof( - + (m[1][1] * SubFactor00 - m[1][2] * SubFactor01 + m[1][3] * SubFactor02), - - (m[1][0] * SubFactor00 - m[1][2] * SubFactor03 + m[1][3] * SubFactor04), - + (m[1][0] * SubFactor01 - m[1][1] * SubFactor03 + m[1][3] * SubFactor05), - - (m[1][0] * SubFactor02 - m[1][1] * SubFactor04 + m[1][2] * SubFactor05)); - - return m[0][0] * DetCof[0] - + m[0][1] * DetCof[1] - + m[0][2] * DetCof[2] - + m[0][3] * DetCof[3]; - } - namespace detail { + template