Added matrix inverse tests and clean up space characters

This commit is contained in:
Christophe Riccio 2012-11-09 03:39:43 +01:00
parent c9a0b87c7b
commit 4fff9b4367
23 changed files with 2664 additions and 2540 deletions

View File

@ -499,10 +499,6 @@ namespace detail
m[1] * s);
}
// X
// X
// X X
// X X
template <typename T>
GLM_FUNC_QUALIFIER tmat2x2<T> operator*
(
@ -527,9 +523,6 @@ namespace detail
m[0][1] * v.x + m[1][1] * v.y);
}
// X X
// X X
// X X
template <typename T>
GLM_FUNC_QUALIFIER typename tmat2x2<T>::row_type operator*
(

View File

@ -641,6 +641,5 @@ namespace detail
{
return (m1[0] != m2[0]) || (m1[1] != m2[1]);
}
} //namespace detail
} //namespace glm

View File

@ -660,6 +660,5 @@ namespace detail
{
return (m1[0] != m2[0]) || (m1[1] != m2[1]);
}
} //namespace detail
} //namespace glm

View File

@ -48,8 +48,8 @@ namespace detail
template <typename T> struct tmat4x3;
template <typename T> struct tmat4x4;
// \brief Template for 3 columns and 2 rows matrix of floating-point numbers.
// \ingroup core_template
/// @brief Template for 3 columns and 2 rows matrix of floating-point numbers.
/// @ingroup core_template
template <typename T>
struct tmat3x2
{
@ -231,7 +231,6 @@ namespace detail
tmat3x2<T> const operator++ (
tmat3x2<T> const & m,
int);
} //namespace detail
/// @addtogroup core_precision

View File

@ -48,8 +48,8 @@ namespace detail
template <typename T> struct tmat4x3;
template <typename T> struct tmat4x4;
// @brief Template for 3 * 3 matrix of floating-point numbers.
// @ingroup core_template
/// @brief Template for 3 * 3 matrix of floating-point numbers.
/// @ingroup core_template
template <typename T>
struct tmat3x3
{
@ -263,7 +263,6 @@ namespace detail
tmat3x3<T> const operator++ (
tmat3x3<T> const & m,
int);
} //namespace detail
/// @addtogroup core_precision

View File

@ -515,11 +515,6 @@ namespace detail
m[0][3] * v.x + m[1][3] * v.y + m[2][3] * v.z);
}
// X X X
// X X X
// X X X
// X X X
// X X X X
template <typename T>
GLM_FUNC_QUALIFIER typename tmat3x4<T>::row_type operator*
(
@ -713,6 +708,5 @@ namespace detail
{
return (m1[0] != m2[0]) || (m1[1] != m2[1]) || (m1[2] != m2[2]);
}
} //namespace detail
} //namespace glm

View File

@ -236,7 +236,6 @@ namespace detail
tmat4x2<T> const operator++ (
tmat4x2<T> const & m,
int);
} //namespace detail
/// @addtogroup core_precision

View File

@ -724,6 +724,5 @@ namespace detail
{
return (m1[0] != m2[0]) || (m1[1] != m2[1]) || (m1[2] != m2[2]) || (m1[3] != m2[3]);
}
} //namespace detail
} //namespace glm

View File

@ -48,8 +48,8 @@ namespace detail
template <typename T> struct tmat4x3;
template <typename T> struct tmat4x4;
// \brief Template for 4 columns and 3 rows matrix of floating-point numbers.
// \ingroup core_template
/// @brief Template for 4 columns and 3 rows matrix of floating-point numbers.
/// @ingroup core_template
template <typename T>
struct tmat4x3
{
@ -234,7 +234,6 @@ namespace detail
tmat4x3<T> const operator++ (
tmat4x3<T> const & m,
int);
}//namespace detail
/// @addtogroup core_precision

View File

@ -732,7 +732,6 @@ namespace detail
{
return (m1[0] != m2[0]) || (m1[1] != m2[1]) || (m1[2] != m2[2]) || (m1[3] != m2[3]);
}
} //namespace detail
} //namespace glm

View File

@ -44,8 +44,8 @@ namespace detail
template <typename T> struct tvec3;
template <typename T> struct tvec4;
// The basic 2D vector type.
// \ingroup core_template
/// The basic 2D vector type.
/// @ingroup core_template
template <typename T>
struct tvec2
{

View File

@ -1024,6 +1024,5 @@ namespace detail
{
return tvec2<T>(this->x, this->y);
}
}//namespace detail
}//namespace glm

View File

@ -44,8 +44,8 @@ namespace detail
template <typename T> struct tvec2;
template <typename T> struct tvec4;
// Basic 3D vector type.
// \ingroup core_template
/// Basic 3D vector type.
/// @ingroup core_template
template <typename T>
struct tvec3
{

View File

@ -56,16 +56,16 @@ namespace glm
/// Returns the component-wise compare of |x - y| < epsilon.
/// @see gtc_epsilon
template <typename genTypeT, typename genTypeU>
bool epsilonEqual(
template <typename genTypeT, typename genTypeU, typename boolType>
boolType epsilonEqual(
genTypeT const & x,
genTypeT const & y,
genTypeU const & epsilon);
/// Returns the component-wise compare of |x - y| >= epsilon.
/// @see gtc_epsilon
template <typename genTypeT, typename genTypeU>
bool epsilonNotEqual(
template <typename genTypeT, typename genTypeU, typename boolType>
boolType epsilonNotEqual(
genTypeT const & x,
genTypeT const & y,
genTypeU const & epsilon);

View File

@ -28,23 +28,67 @@
namespace glm
{
template <typename genType>
template <>
GLM_FUNC_QUALIFIER bool epsilonEqual
(
genType const & x,
genType const & y,
genType const & epsilon
glm::half const & x,
glm::half const & y,
glm::half const & epsilon
)
{
return abs(x - y) < epsilon;
}
template <typename genType>
template <>
GLM_FUNC_QUALIFIER bool epsilonEqual
(
float const & x,
float const & y,
float const & epsilon
)
{
return abs(x - y) < epsilon;
}
template <>
GLM_FUNC_QUALIFIER bool epsilonEqual
(
double const & x,
double const & y,
double const & epsilon
)
{
return abs(x - y) < epsilon;
}
template <>
GLM_FUNC_QUALIFIER bool epsilonNotEqual
(
genType const & x,
genType const & y,
genType const & epsilon
glm::half const & x,
glm::half const & y,
glm::half const & epsilon
)
{
return abs(x - y) >= epsilon;
}
template <>
GLM_FUNC_QUALIFIER bool epsilonNotEqual
(
float const & x,
float const & y,
float const & epsilon
)
{
return abs(x - y) >= epsilon;
}
template <>
GLM_FUNC_QUALIFIER bool epsilonNotEqual
(
double const & x,
double const & y,
double const & epsilon
)
{
return abs(x - y) >= epsilon;
@ -62,76 +106,6 @@ namespace glm
abs(x.y - y.y) < epsilon);
}
template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec3<bool> epsilonEqual
(
detail::tvec3<valType> const & x,
detail::tvec3<valType> const & y,
valType const & epsilon)
{
return detail::tvec3<bool>(
abs(x.x - y.x) < epsilon,
abs(x.y - y.y) < epsilon,
abs(x.z - y.z) < epsilon);
}
template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec4<bool> epsilonEqual
(
detail::tvec4<valType> const & x,
detail::tvec4<valType> const & y,
valType const & epsilon
)
{
return detail::tvec4<bool>(
abs(x.x - y.x) < epsilon,
abs(x.y - y.y) < epsilon,
abs(x.z - y.z) < epsilon,
abs(x.w - y.w) < epsilon);
}
template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec2<bool> epsilonNotEqual
(
detail::tvec2<valType> const & x,
detail::tvec2<valType> const & y,
valType const & epsilon
)
{
return detail::tvec2<bool>(
abs(x.x - y.x) >= epsilon,
abs(x.y - y.y) >= epsilon);
}
template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec3<bool> epsilonNotEqual
(
detail::tvec3<valType> const & x,
detail::tvec3<valType> const & y,
valType const & epsilon
)
{
return detail::tvec3<bool>(
abs(x.x - y.x) >= epsilon,
abs(x.y - y.y) >= epsilon,
abs(x.z - y.z) >= epsilon);
}
template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec4<bool> epsilonNotEqual
(
detail::tvec4<valType> const & x,
detail::tvec4<valType> const & y,
valType const & epsilon
)
{
return detail::tvec4<bool>(
abs(x.x - y.x) >= epsilon,
abs(x.y - y.y) >= epsilon,
abs(x.z - y.z) >= epsilon,
abs(x.w - y.w) >= epsilon);
}
template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec2<bool> epsilonEqual
(
@ -145,6 +119,19 @@ namespace glm
abs(x.y - y.y) < epsilon.y);
}
template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec3<bool> epsilonEqual
(
detail::tvec3<valType> const & x,
detail::tvec3<valType> const & y,
valType const & epsilon)
{
return detail::tvec3<bool>(
abs(x.x - y.x) < epsilon,
abs(x.y - y.y) < epsilon,
abs(x.z - y.z) < epsilon);
}
template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec3<bool> epsilonEqual
(
@ -164,22 +151,22 @@ namespace glm
(
detail::tvec4<valType> const & x,
detail::tvec4<valType> const & y,
detail::tvec4<valType> const & epsilon
valType const & epsilon
)
{
return detail::tvec4<bool>(
abs(x.x - y.x) < epsilon.x,
abs(x.y - y.y) < epsilon.y,
abs(x.z - y.z) < epsilon.z,
abs(x.w - y.w) < epsilon.w);
abs(x.x - y.x) < epsilon,
abs(x.y - y.y) < epsilon,
abs(x.z - y.z) < epsilon,
abs(x.w - y.w) < epsilon);
}
template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec4<bool> epsilonEqual
(
detail::tquat<valType> const & x,
detail::tquat<valType> const & y,
detail::tquat<valType> const & epsilon
detail::tvec4<valType> const & x,
detail::tvec4<valType> const & y,
detail::tvec4<valType> const & epsilon
)
{
return detail::tvec4<bool>(
@ -189,6 +176,19 @@ namespace glm
abs(x.w - y.w) < epsilon.w);
}
template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec2<bool> epsilonNotEqual
(
detail::tvec2<valType> const & x,
detail::tvec2<valType> const & y,
valType const & epsilon
)
{
return detail::tvec2<bool>(
abs(x.x - y.x) >= epsilon,
abs(x.y - y.y) >= epsilon);
}
template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec2<bool> epsilonNotEqual
(
@ -202,6 +202,20 @@ namespace glm
abs(x.y - y.y) >= epsilon.y);
}
template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec3<bool> epsilonNotEqual
(
detail::tvec3<valType> const & x,
detail::tvec3<valType> const & y,
valType const & epsilon
)
{
return detail::tvec3<bool>(
abs(x.x - y.x) >= epsilon,
abs(x.y - y.y) >= epsilon,
abs(x.z - y.z) >= epsilon);
}
template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec3<bool> epsilonNotEqual
(
@ -216,6 +230,21 @@ namespace glm
abs(x.z - y.z) >= epsilon.z);
}
template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec4<bool> epsilonNotEqual
(
detail::tvec4<valType> const & x,
detail::tvec4<valType> const & y,
valType const & epsilon
)
{
return detail::tvec4<bool>(
abs(x.x - y.x) >= epsilon,
abs(x.y - y.y) >= epsilon,
abs(x.z - y.z) >= epsilon,
abs(x.w - y.w) >= epsilon);
}
template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec4<bool> epsilonNotEqual
(
@ -231,6 +260,22 @@ namespace glm
abs(x.w - y.w) >= epsilon.w);
}
/*
template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec4<bool> epsilonEqual
(
detail::tquat<valType> const & x,
detail::tquat<valType> const & y,
detail::tquat<valType> const & epsilon
)
{
return detail::tvec4<bool>(
abs(x.x - y.x) < epsilon.x,
abs(x.y - y.y) < epsilon.y,
abs(x.z - y.z) < epsilon.z,
abs(x.w - y.w) < epsilon.w);
}
template <typename valType>
GLM_FUNC_QUALIFIER detail::tvec4<bool> epsilonNotEqual
(
@ -245,4 +290,6 @@ namespace glm
abs(x.z - y.z) >= epsilon.z,
abs(x.w - y.w) >= epsilon.w);
}
*/
}//namespace glm

View File

@ -34,24 +34,20 @@ int test_inverse()
int Error(0);
{
glm::mat2 Matrix(1, 2, 3, 4);
glm::mat2 Inverse = glm::inverse(Matrix);
glm::mat2 Identity = Matrix * Inverse;
glm::mat2 const Matrix(1, 2, 3, 4);
glm::mat2 const Inverse = glm::inverse(Matrix);
glm::mat2 const Identity = Matrix * Inverse;
Error += glm::epsilonEqual(Identity[0][0], 1.0f, 0.01f) ? 0 : 1;
Error += glm::epsilonEqual(Identity[0][1], 0.0f, 0.01f) ? 0 : 1;
Error += glm::epsilonEqual(Identity[1][0], 0.0f, 0.01f) ? 0 : 1;
Error += glm::epsilonEqual(Identity[1][1], 1.0f, 0.01f) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Identity[0], glm::vec2(1.0f, 0.0f), glm::vec2(0.01f))) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Identity[1], glm::vec2(0.0f, 1.0f), glm::vec2(0.01f))) ? 0 : 1;
}
{
glm::mat2 Matrix(1, 2, 3, 4);
glm::mat2 Identity = Matrix / Matrix;
glm::mat2 const Matrix(1, 2, 3, 4);
glm::mat2 const Identity = Matrix / Matrix;
Error += glm::epsilonEqual(Identity[0][0], 1.0f, 0.01f) ? 0 : 1;
Error += glm::epsilonEqual(Identity[0][1], 0.0f, 0.01f) ? 0 : 1;
Error += glm::epsilonEqual(Identity[1][0], 0.0f, 0.01f) ? 0 : 1;
Error += glm::epsilonEqual(Identity[1][1], 1.0f, 0.01f) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Identity[0], glm::vec2(1.0f, 0.0f), glm::vec2(0.01f))) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Identity[1], glm::vec2(0.0f, 1.0f), glm::vec2(0.01f))) ? 0 : 1;
}
return Error;

View File

@ -8,6 +8,7 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
#include <glm/glm.hpp>
#include <glm/gtc/epsilon.hpp>
#include <cstdio>
void print(glm::dmat3 const & Mat0)
@ -53,12 +54,45 @@ static int test_operators()
return (S && !R) ? 0 : 1;
}
int test_inverse()
{
int Error(0);
{
glm::mat3 const Matrix(
glm::vec3(0.6f, 0.2f, 0.3f),
glm::vec3(0.2f, 0.7f, 0.5f),
glm::vec3(0.3f, 0.5f, 0.7f));
glm::mat3 const Inverse = glm::inverse(Matrix);
glm::mat3 const Identity = Matrix * Inverse;
Error += glm::all(glm::epsilonEqual(Identity[0], glm::vec3(1.0f, 0.0f, 0.0f), glm::vec3(0.01f))) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Identity[1], glm::vec3(0.0f, 1.0f, 0.0f), glm::vec3(0.01f))) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Identity[2], glm::vec3(0.0f, 0.0f, 1.0f), glm::vec3(0.01f))) ? 0 : 1;
}
{
glm::mat3 const Matrix(
glm::vec3(0.6f, 0.2f, 0.3f),
glm::vec3(0.2f, 0.7f, 0.5f),
glm::vec3(0.3f, 0.5f, 0.7f));
glm::mat3 const Identity = Matrix / Matrix;
Error += glm::all(glm::epsilonEqual(Identity[0], glm::vec3(1.0f, 0.0f, 0.0f), glm::vec3(0.01f))) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Identity[1], glm::vec3(0.0f, 1.0f, 0.0f), glm::vec3(0.01f))) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Identity[2], glm::vec3(0.0f, 0.0f, 1.0f), glm::vec3(0.01f))) ? 0 : 1;
}
return Error;
}
int main()
{
int Error = 0;
Error += test_mat3x3();
Error += test_operators();
Error += test_inverse();
return Error;
}

View File

@ -7,8 +7,9 @@
// File : test/core/type_mat4x4.cpp
///////////////////////////////////////////////////////////////////////////////////////////////////
#define GLM_PRECISION_HIGHP_FLOAT
//#define GLM_PRECISION_HIGHP_FLOAT
#include <glm/glm.hpp>
#include <glm/gtc/epsilon.hpp>
#include <cstdio>
void print(glm::dmat4 const & Mat0)
@ -20,7 +21,33 @@ void print(glm::dmat4 const & Mat0)
printf("\tvec4(%2.3f, %2.3f, %2.3f, %2.3f))\n\n", Mat0[3][0], Mat0[3][1], Mat0[3][2], Mat0[3][3]);
}
int test_mat4x4()
void print(glm::mat4 const & Mat0)
{
printf("mat4(\n");
printf("\tvec4(%2.3f, %2.3f, %2.3f, %2.3f)\n", Mat0[0][0], Mat0[0][1], Mat0[0][2], Mat0[0][3]);
printf("\tvec4(%2.3f, %2.3f, %2.3f, %2.3f)\n", Mat0[1][0], Mat0[1][1], Mat0[1][2], Mat0[1][3]);
printf("\tvec4(%2.3f, %2.3f, %2.3f, %2.3f)\n", Mat0[2][0], Mat0[2][1], Mat0[2][2], Mat0[2][3]);
printf("\tvec4(%2.3f, %2.3f, %2.3f, %2.3f))\n\n", Mat0[3][0], Mat0[3][1], Mat0[3][2], Mat0[3][3]);
}
int test_inverse_mat4x4()
{
glm::mat4 Mat0(
glm::vec4(0.6f, 0.2f, 0.3f, 0.4f),
glm::vec4(0.2f, 0.7f, 0.5f, 0.3f),
glm::vec4(0.3f, 0.5f, 0.7f, 0.2f),
glm::vec4(0.4f, 0.3f, 0.2f, 0.6f));
glm::mat4 Inv0 = glm::inverse(Mat0);
glm::mat4 Res0 = Mat0 * Inv0;
print(Mat0);
print(Inv0);
print(Res0);
return 0;
}
int test_inverse_dmat4x4()
{
glm::dmat4 Mat0(
glm::dvec4(0.6f, 0.2f, 0.3f, 0.4f),
@ -56,12 +83,54 @@ static bool test_operators()
return (S && !R) ? 0 : 1;
}
int test_inverse()
{
int Error(0);
{
glm::mat4 const Matrix(
glm::vec4(0.6f, 0.2f, 0.3f, 0.4f),
glm::vec4(0.2f, 0.7f, 0.5f, 0.3f),
glm::vec4(0.3f, 0.5f, 0.7f, 0.2f),
glm::vec4(0.4f, 0.3f, 0.2f, 0.6f));
glm::mat4 const Inverse = glm::inverse(Matrix);
glm::mat4 const Identity = Matrix * Inverse;
print(Matrix);
print(Inverse);
print(Identity);
Error += glm::all(glm::epsilonEqual(Identity[0], glm::vec4(1.0f, 0.0f, 0.0f, 0.0f), glm::vec4(0.01f))) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Identity[1], glm::vec4(0.0f, 1.0f, 0.0f, 0.0f), glm::vec4(0.01f))) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Identity[2], glm::vec4(0.0f, 0.0f, 1.0f, 0.0f), glm::vec4(0.01f))) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Identity[3], glm::vec4(0.0f, 0.0f, 0.0f, 1.0f), glm::vec4(0.01f))) ? 0 : 1;
}
{
glm::mat4 const Matrix(
glm::vec4(0.6f, 0.2f, 0.3f, 0.4f),
glm::vec4(0.2f, 0.7f, 0.5f, 0.3f),
glm::vec4(0.3f, 0.5f, 0.7f, 0.2f),
glm::vec4(0.4f, 0.3f, 0.2f, 0.6f));
glm::mat4 const Identity = Matrix / Matrix;
Error += glm::all(glm::epsilonEqual(Identity[0], glm::vec4(1.0f, 0.0f, 0.0f, 0.0f), glm::vec4(0.01f))) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Identity[1], glm::vec4(0.0f, 1.0f, 0.0f, 0.0f), glm::vec4(0.01f))) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Identity[2], glm::vec4(0.0f, 0.0f, 1.0f, 0.0f), glm::vec4(0.01f))) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Identity[3], glm::vec4(0.0f, 0.0f, 0.0f, 1.0f), glm::vec4(0.01f))) ? 0 : 1;
}
return Error;
}
int main()
{
int Error = 0;
Error += test_mat4x4();
Error += test_inverse_dmat4x4();
Error += test_inverse_mat4x4();
Error += test_operators();
Error += test_inverse();
return Error;
}