Fixed vector and matrix queries

This commit is contained in:
Christophe Riccio
2014-01-04 14:57:59 +01:00
parent 06ac77dad4
commit 6f096fbb31
7 changed files with 226 additions and 214 deletions

View File

@@ -9,62 +9,64 @@
#include <glm/matrix.hpp>
using namespace glm;
int test_matrixCompMult()
{
int Error(0);
{
glm::mat2 m(0, 1, 2, 3);
glm::mat2 n = glm::matrixCompMult(m, m);
Error += n == glm::mat2(0, 1, 4, 9) ? 0 : 1;
mat2 m(0, 1, 2, 3);
mat2 n = matrixCompMult(m, m);
Error += n == mat2(0, 1, 4, 9) ? 0 : 1;
}
{
glm::mat2x3 m(0, 1, 2, 3, 4, 5);
glm::mat2x3 n = glm::matrixCompMult(m, m);
Error += n == glm::mat2x3(0, 1, 4, 9, 16, 25) ? 0 : 1;
mat2x3 m(0, 1, 2, 3, 4, 5);
mat2x3 n = matrixCompMult(m, m);
Error += n == mat2x3(0, 1, 4, 9, 16, 25) ? 0 : 1;
}
{
glm::mat2x4 m(0, 1, 2, 3, 4, 5, 6, 7);
glm::mat2x4 n = glm::matrixCompMult(m, m);
Error += n == glm::mat2x4(0, 1, 4, 9, 16, 25, 36, 49) ? 0 : 1;
mat2x4 m(0, 1, 2, 3, 4, 5, 6, 7);
mat2x4 n = matrixCompMult(m, m);
Error += n == mat2x4(0, 1, 4, 9, 16, 25, 36, 49) ? 0 : 1;
}
{
glm::mat3 m(0, 1, 2, 3, 4, 5, 6, 7, 8);
glm::mat3 n = glm::matrixCompMult(m, m);
Error += n == glm::mat3(0, 1, 4, 9, 16, 25, 36, 49, 64) ? 0 : 1;
mat3 m(0, 1, 2, 3, 4, 5, 6, 7, 8);
mat3 n = matrixCompMult(m, m);
Error += n == mat3(0, 1, 4, 9, 16, 25, 36, 49, 64) ? 0 : 1;
}
{
glm::mat3x2 m(0, 1, 2, 3, 4, 5);
glm::mat3x2 n = glm::matrixCompMult(m, m);
Error += n == glm::mat3x2(0, 1, 4, 9, 16, 25) ? 0 : 1;
mat3x2 m(0, 1, 2, 3, 4, 5);
mat3x2 n = matrixCompMult(m, m);
Error += n == mat3x2(0, 1, 4, 9, 16, 25) ? 0 : 1;
}
{
glm::mat3x4 m(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);
glm::mat3x4 n = glm::matrixCompMult(m, m);
Error += n == glm::mat3x4(0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121) ? 0 : 1;
mat3x4 m(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);
mat3x4 n = matrixCompMult(m, m);
Error += n == mat3x4(0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121) ? 0 : 1;
}
{
glm::mat4 m(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
glm::mat4 n = glm::matrixCompMult(m, m);
Error += n == glm::mat4(0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225) ? 0 : 1;
mat4 m(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
mat4 n = matrixCompMult(m, m);
Error += n == mat4(0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225) ? 0 : 1;
}
{
glm::mat4x2 m(0, 1, 2, 3, 4, 5, 6, 7);
glm::mat4x2 n = glm::matrixCompMult(m, m);
Error += n == glm::mat4x2(0, 1, 4, 9, 16, 25, 36, 49) ? 0 : 1;
mat4x2 m(0, 1, 2, 3, 4, 5, 6, 7);
mat4x2 n = matrixCompMult(m, m);
Error += n == mat4x2(0, 1, 4, 9, 16, 25, 36, 49) ? 0 : 1;
}
{
glm::mat4x3 m(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);
glm::mat4x3 n = glm::matrixCompMult(m, m);
Error += n == glm::mat4x3(0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121) ? 0 : 1;
mat4x3 m(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);
mat4x3 n = matrixCompMult(m, m);
Error += n == mat4x3(0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121) ? 0 : 1;
}
return Error;
@@ -79,62 +81,62 @@ int test_outerProduct()
int test_transpose()
{
int Error(0);
{
glm::mat2 m(0, 1, 2, 3);
glm::mat2 t = glm::transpose(m);
Error += t == glm::mat2(0, 2, 1, 3) ? 0 : 1;
}
int Error(0);
{
glm::mat2x3 m(0, 1, 2, 3, 4, 5);
glm::mat3x2 t = glm::transpose(m);
Error += t == glm::mat3x2(0, 3, 1, 4, 2, 5) ? 0 : 1;
}
{
mat2 m(0, 1, 2, 3);
mat2 t = transpose(m);
Error += t == mat2(0, 2, 1, 3) ? 0 : 1;
}
{
mat2x3 m(0, 1, 2, 3, 4, 5);
mat3x2 t = transpose(m);
Error += t == mat3x2(0, 3, 1, 4, 2, 5) ? 0 : 1;
}
{
mat2x4 m(0, 1, 2, 3, 4, 5, 6, 7);
mat4x2 t = transpose(m);
Error += t == mat4x2(0, 4, 1, 5, 2, 6, 3, 7) ? 0 : 1;
}
{
mat3 m(0, 1, 2, 3, 4, 5, 6, 7, 8);
mat3 t = transpose(m);
Error += t == mat3(0, 3, 6, 1, 4, 7, 2, 5, 8) ? 0 : 1;
}
{
mat3x2 m(0, 1, 2, 3, 4, 5);
mat2x3 t = transpose(m);
Error += t == mat2x3(0, 2, 4, 1, 3, 5) ? 0 : 1;
}
{
mat3x4 m(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);
mat4x3 t = transpose(m);
Error += t == mat4x3(0, 4, 8, 1, 5, 9, 2, 6, 10, 3, 7, 11) ? 0 : 1;
}
{
mat4 m(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
mat4 t = transpose(m);
Error += t == mat4(0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15) ? 0 : 1;
}
{
mat4x2 m(0, 1, 2, 3, 4, 5, 6, 7);
mat2x4 t = transpose(m);
Error += t == mat2x4(0, 2, 4, 6, 1, 3, 5, 7) ? 0 : 1;
}
{
mat4x3 m(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);
mat3x4 t = transpose(m);
Error += t == mat3x4(0, 3, 6, 9, 1, 4, 7, 10, 2, 5, 8, 11) ? 0 : 1;
}
{
glm::mat2x4 m(0, 1, 2, 3, 4, 5, 6, 7);
glm::mat4x2 t = glm::transpose(m);
Error += t == glm::mat4x2(0, 4, 1, 5, 2, 6, 3, 7) ? 0 : 1;
}
{
glm::mat3 m(0, 1, 2, 3, 4, 5, 6, 7, 8);
glm::mat3 t = glm::transpose(m);
Error += t == glm::mat3(0, 3, 6, 1, 4, 7, 2, 5, 8) ? 0 : 1;
}
{
glm::mat3x2 m(0, 1, 2, 3, 4, 5);
glm::mat2x3 t = glm::transpose(m);
Error += t == glm::mat2x3(0, 2, 4, 1, 3, 5) ? 0 : 1;
}
{
glm::mat3x4 m(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);
glm::mat4x3 t = glm::transpose(m);
Error += t == glm::mat4x3(0, 4, 8, 1, 5, 9, 2, 6, 10, 3, 7, 11) ? 0 : 1;
}
{
glm::mat4 m(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
glm::mat4 t = glm::transpose(m);
Error += t == glm::mat4(0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15) ? 0 : 1;
}
{
glm::mat4x2 m(0, 1, 2, 3, 4, 5, 6, 7);
glm::mat2x4 t = glm::transpose(m);
Error += t == glm::mat2x4(0, 2, 4, 6, 1, 3, 5, 7) ? 0 : 1;
}
{
glm::mat4x3 m(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);
glm::mat3x4 t = glm::transpose(m);
Error += t == glm::mat3x4(0, 3, 6, 9, 1, 4, 7, 10, 2, 5, 8, 11) ? 0 : 1;
}
return Error;
}
@@ -154,7 +156,7 @@ int test_inverse()
glm::vec4(0, 1, 0, 0),
glm::vec4(0, 0, 1, 0),
glm::vec4(0, 0, 0, 1));
glm::mat4x4 B4x4 = glm::inverse(A4x4);
glm::mat4x4 B4x4 = inverse(A4x4);
glm::mat4x4 I4x4 = A4x4 * B4x4;
Failed += I4x4 == glm::mat4x4(1) ? 0 : 1;

View File

@@ -184,12 +184,12 @@ int test_Snorm3x10_1x2()
int Error = 0;
std::vector<glm::vec4> Tests;
Tests.push_back(glm::vec4(1.0));
Tests.push_back(glm::vec4(0.0));
Tests.push_back(glm::vec4(2.0));
Tests.push_back(glm::vec4(0.1));
Tests.push_back(glm::vec4(0.5));
Tests.push_back(glm::vec4(0.9));
Tests.push_back(glm::vec4(1.0f));
Tests.push_back(glm::vec4(0.0f));
Tests.push_back(glm::vec4(2.0f));
Tests.push_back(glm::vec4(0.1f));
Tests.push_back(glm::vec4(0.5f));
Tests.push_back(glm::vec4(0.9f));
for(std::size_t i = 0; i < Tests.size(); ++i)
{