From 9b5bec81f2c110f92271abe78154f5599f9c1f2f Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Wed, 25 Dec 2013 05:58:11 +0100 Subject: [PATCH] Factorize glm::inverse code for matrices --- glm/detail/func_matrix.hpp | 68 ++--------- glm/detail/func_matrix.inl | 223 ++++++++++++++++++++----------------- 2 files changed, 130 insertions(+), 161 deletions(-) diff --git a/glm/detail/func_matrix.hpp b/glm/detail/func_matrix.hpp index 238b3ad9..34f4f61d 100644 --- a/glm/detail/func_matrix.hpp +++ b/glm/detail/func_matrix.hpp @@ -40,15 +40,9 @@ #ifndef GLM_CORE_func_matrix #define GLM_CORE_func_matrix -#include "type_mat2x2.hpp" -#include "type_mat2x3.hpp" -#include "type_mat2x4.hpp" -#include "type_mat3x2.hpp" -#include "type_mat3x3.hpp" -#include "type_mat3x4.hpp" -#include "type_mat4x2.hpp" -#include "type_mat4x3.hpp" -#include "type_mat4x4.hpp" +// Dependencies +#include "../detail/precision.hpp" +#include "../detail/setup.hpp" namespace glm { @@ -92,65 +86,25 @@ namespace glm GLM_FUNC_DECL typename matType::transpose_type transpose( matType const & x); - /// Return the determinant of a mat2 matrix. + /// Return the determinant of a squared matrix. /// /// @tparam valType Floating-point scalar types. /// /// @see GLSL determinant man page /// @see GLSL 4.20.8 specification, section 8.6 Matrix Functions - template - GLM_FUNC_DECL typename detail::tmat2x2::value_type determinant( - detail::tmat2x2 const & m); + template class matType> + GLM_FUNC_DECL T determinant( + matType const & m); - /// Return the determinant of a mat3 matrix. - /// - /// @tparam valType Floating-point scalar types. - /// - /// @see GLSL determinant man page - /// @see GLSL 4.20.8 specification, section 8.6 Matrix Functions - template - GLM_FUNC_DECL typename detail::tmat3x3::value_type determinant( - detail::tmat3x3 const & m); - - /// Return the determinant of a mat4 matrix. - /// - /// @tparam valType Floating-point scalar types. - /// - /// @see GLSL determinant man page - /// @see GLSL 4.20.8 specification, section 8.6 Matrix Functions - template - GLM_FUNC_DECL typename detail::tmat4x4::value_type determinant( - detail::tmat4x4 const & m); - - /// Return the inverse of a mat2 matrix. + /// Return the inverse of a squared matrix. /// /// @tparam valType Floating-point scalar types. /// /// @see GLSL inverse man page /// @see GLSL 4.20.8 specification, section 8.6 Matrix Functions - template - GLM_FUNC_DECL detail::tmat2x2 inverse( - detail::tmat2x2 const & m); - - /// Return the inverse of a mat3 matrix. - /// - /// @tparam valType Floating-point scalar types. - /// - /// @see GLSL inverse man page - /// @see GLSL 4.20.8 specification, section 8.6 Matrix Functions - template - GLM_FUNC_DECL detail::tmat3x3 inverse( - detail::tmat3x3 const & m); - - /// Return the inverse of a mat4 matrix. - /// - /// @tparam valType Floating-point scalar types. - /// - /// @see GLSL inverse man page - /// @see GLSL 4.20.8 specification, section 8.6 Matrix Functions - template - GLM_FUNC_DECL detail::tmat4x4 inverse( - detail::tmat4x4 const & m); + template class matType> + 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 d1509e60..3f178bb2 100644 --- a/glm/detail/func_matrix.inl +++ b/glm/detail/func_matrix.inl @@ -30,6 +30,15 @@ #include "../vec2.hpp" #include "../vec3.hpp" #include "../vec4.hpp" +#include "type_mat2x2.hpp" +#include "type_mat2x3.hpp" +#include "type_mat2x4.hpp" +#include "type_mat3x2.hpp" +#include "type_mat3x3.hpp" +#include "type_mat3x4.hpp" +#include "type_mat4x2.hpp" +#include "type_mat4x3.hpp" +#include "type_mat4x4.hpp" #include namespace glm @@ -474,115 +483,121 @@ namespace glm + m[0][3] * DetCof[3]; } +namespace detail +{ + template