Factorize glm::inverse code for matrices
This commit is contained in:
parent
dde5178b84
commit
9b5bec81f2
@ -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 <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/determinant.xml">GLSL determinant man page</a>
|
||||
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.6 Matrix Functions</a>
|
||||
template <typename T, precision P>
|
||||
GLM_FUNC_DECL typename detail::tmat2x2<T, P>::value_type determinant(
|
||||
detail::tmat2x2<T, P> const & m);
|
||||
template <typename T, precision P, template <typename, precision> class matType>
|
||||
GLM_FUNC_DECL T determinant(
|
||||
matType<T, P> const & m);
|
||||
|
||||
/// Return the determinant of a mat3 matrix.
|
||||
///
|
||||
/// @tparam valType Floating-point scalar types.
|
||||
///
|
||||
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/determinant.xml">GLSL determinant man page</a>
|
||||
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.6 Matrix Functions</a>
|
||||
template <typename T, precision P>
|
||||
GLM_FUNC_DECL typename detail::tmat3x3<T, P>::value_type determinant(
|
||||
detail::tmat3x3<T, P> const & m);
|
||||
|
||||
/// Return the determinant of a mat4 matrix.
|
||||
///
|
||||
/// @tparam valType Floating-point scalar types.
|
||||
///
|
||||
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/determinant.xml">GLSL determinant man page</a>
|
||||
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.6 Matrix Functions</a>
|
||||
template <typename T, precision P>
|
||||
GLM_FUNC_DECL typename detail::tmat4x4<T, P>::value_type determinant(
|
||||
detail::tmat4x4<T, P> const & m);
|
||||
|
||||
/// Return the inverse of a mat2 matrix.
|
||||
/// Return the inverse of a squared matrix.
|
||||
///
|
||||
/// @tparam valType Floating-point scalar types.
|
||||
///
|
||||
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/inverse.xml">GLSL inverse man page</a>
|
||||
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.6 Matrix Functions</a>
|
||||
template <typename T, precision P>
|
||||
GLM_FUNC_DECL detail::tmat2x2<T, P> inverse(
|
||||
detail::tmat2x2<T, P> const & m);
|
||||
|
||||
/// Return the inverse of a mat3 matrix.
|
||||
///
|
||||
/// @tparam valType Floating-point scalar types.
|
||||
///
|
||||
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/inverse.xml">GLSL inverse man page</a>
|
||||
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.6 Matrix Functions</a>
|
||||
template <typename T, precision P>
|
||||
GLM_FUNC_DECL detail::tmat3x3<T, P> inverse(
|
||||
detail::tmat3x3<T, P> const & m);
|
||||
|
||||
/// Return the inverse of a mat4 matrix.
|
||||
///
|
||||
/// @tparam valType Floating-point scalar types.
|
||||
///
|
||||
/// @see <a href="http://www.opengl.org/sdk/docs/manglsl/xhtml/inverse.xml">GLSL inverse man page</a>
|
||||
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.6 Matrix Functions</a>
|
||||
template <typename T, precision P>
|
||||
GLM_FUNC_DECL detail::tmat4x4<T, P> inverse(
|
||||
detail::tmat4x4<T, P> const & m);
|
||||
template <typename T, precision P, template <typename, precision> class matType>
|
||||
GLM_FUNC_DECL matType<T, P> inverse(
|
||||
matType<T, P> const & m);
|
||||
|
||||
/// @}
|
||||
}//namespace glm
|
||||
|
@ -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 <limits>
|
||||
|
||||
namespace glm
|
||||
@ -474,15 +483,16 @@ namespace glm
|
||||
+ m[0][3] * DetCof[3];
|
||||
}
|
||||
|
||||
template <typename T, precision P>
|
||||
GLM_FUNC_QUALIFIER detail::tmat2x2<T, P> inverse
|
||||
(
|
||||
detail::tmat2x2<T, P> const & m
|
||||
)
|
||||
{
|
||||
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'inverse' only accept floating-point inputs");
|
||||
namespace detail
|
||||
{
|
||||
template <template <class, precision> class matType, typename T, precision P>
|
||||
struct compute_inverse{};
|
||||
|
||||
//valType Determinant = m[0][0] * m[1][1] - m[1][0] * m[0][1];
|
||||
template <typename T, precision P>
|
||||
struct compute_inverse<detail::tmat2x2, T, P>
|
||||
{
|
||||
static detail::tmat2x2<T, P> call(detail::tmat2x2<T, P> const & m)
|
||||
{
|
||||
T Determinant = determinant(m);
|
||||
|
||||
detail::tmat2x2<T, P> Inverse(
|
||||
@ -493,19 +503,13 @@ namespace glm
|
||||
|
||||
return Inverse;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, precision P>
|
||||
GLM_FUNC_QUALIFIER detail::tmat3x3<T, P> inverse
|
||||
(
|
||||
detail::tmat3x3<T, P> const & m
|
||||
)
|
||||
struct compute_inverse<detail::tmat3x3, T, P>
|
||||
{
|
||||
static detail::tmat3x3<T, P> call(detail::tmat3x3<T, P> const & m)
|
||||
{
|
||||
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'inverse' only accept floating-point inputs");
|
||||
|
||||
//valType Determinant = 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]);
|
||||
|
||||
T Determinant = determinant(m);
|
||||
|
||||
detail::tmat3x3<T, P> Inverse(detail::tmat3x3<T, P>::_null);
|
||||
@ -522,15 +526,13 @@ namespace glm
|
||||
|
||||
return Inverse;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, precision P>
|
||||
GLM_FUNC_QUALIFIER detail::tmat4x4<T, P> inverse
|
||||
(
|
||||
detail::tmat4x4<T, P> const & m
|
||||
)
|
||||
struct compute_inverse<detail::tmat4x4, T, P>
|
||||
{
|
||||
static detail::tmat4x4<T, P> call(detail::tmat4x4<T, P> const & m)
|
||||
{
|
||||
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'inverse' only accept floating-point inputs");
|
||||
|
||||
T Coef00 = m[2][2] * m[3][3] - m[3][2] * m[2][3];
|
||||
T Coef02 = m[1][2] * m[3][3] - m[3][2] * m[1][3];
|
||||
T Coef03 = m[1][2] * m[2][3] - m[2][2] * m[1][3];
|
||||
@ -585,4 +587,17 @@ namespace glm
|
||||
|
||||
return Inverse;
|
||||
}
|
||||
};
|
||||
}//namespace detail
|
||||
|
||||
template <typename T, precision P, template <typename, precision> class matType>
|
||||
GLM_FUNC_DECL matType<T, P> inverse
|
||||
(
|
||||
matType<T, P> const & m
|
||||
)
|
||||
{
|
||||
GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'inverse' only accept floating-point inputs");
|
||||
return detail::compute_inverse<matType, T, P>::call(m);
|
||||
}
|
||||
|
||||
}//namespace glm
|
||||
|
Loading…
x
Reference in New Issue
Block a user