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

@@ -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;
}