Merge branch '0.9.2' into 0.9.3

This commit is contained in:
Christophe Riccio
2011-06-01 17:00:34 +01:00
24 changed files with 584 additions and 143 deletions

View File

@@ -2,28 +2,101 @@
// OpenGL Mathematics Copyright (c) 2005 - 2011 G-Truc Creation (www.g-truc.net)
///////////////////////////////////////////////////////////////////////////////////////////////////
// Created : 2008-08-31
// Updated : 2008-08-31
// Updated : 2011-05-31
// Licence : This source is under MIT License
// File : test/core/type_vec2.cpp
///////////////////////////////////////////////////////////////////////////////////////////////////
#include <glm/glm.hpp>
static int test_operators()
int test_vec2_operators()
{
glm::vec2 A(1.0f);
glm::vec2 B(1.0f);
bool R = A != B;
bool S = A == B;
return (S && !R) ? 0 : 1;
int Error = 0;
{
glm::vec2 A(1.0f);
glm::vec2 B(1.0f);
Error += A != B ? 1 : 0;
Error += A == B ? 0 : 1;
}
{
glm::vec2 A(1.0f);
glm::vec2 C = A + 1.0f;
A += 1.0f;
Error += A.x == 2.0f && A.y == 2.0f ? 0 : 1;
Error += A.x == C.x && A.y == C.y ? 0 : 1;
}
{
glm::vec2 A(1.0f);
glm::vec2 B(2.0f,-1.0f);
glm::vec2 C = A + B;
A += B;
Error += A.x == 3.0f && A.y == 0.0f ? 0 : 1;
Error += A.x == C.x && A.y == C.y ? 0 : 1;
}
{
glm::vec2 A(1.0f);
glm::vec2 C = A - 1.0f;
A -= 1.0f;
Error += A.x == 0.0f && A.y == 0.0f ? 0 : 1;
Error += A.x == C.x && A.y == C.y ? 0 : 1;
}
{
glm::vec2 A(1.0f);
glm::vec2 B(2.0f,-1.0f);
glm::vec2 C = A - B;
A -= B;
Error += A.x == -1.0f && A.y == 2.0f ? 0 : 1;
Error += A.x == C.x && A.y == C.y ? 0 : 1;
}
{
glm::vec2 A(1.0f);
glm::vec2 C = A * 2.0f;
A *= 2.0f;
Error += A.x == 2.0f && A.y == 2.0f ? 0 : 1;
Error += A.x == C.x && A.y == C.y ? 0 : 1;
}
{
glm::vec2 A(2.0f);
glm::vec2 B(2.0f);
glm::vec2 C = A / B;
A /= B;
Error += A.x == 1.0f && A.y == 1.0f ? 0 : 1;
Error += A.x == C.x && A.y == C.y ? 0 : 1;
}
return Error;
}
int test_vec2_ctor()
{
int Error = 0;
{
glm::vec2 A = glm::vec2(2.0f);
glm::vec2 B = glm::vec2(2.0f, 3.0f);
glm::vec2 C = glm::vec2(2.0f, 3.0);
//glm::vec2 D = glm::dvec2(2.0); // Build error TODO: What does the specification says?
glm::vec2 E(glm::dvec2(2.0));
glm::vec2 F(glm::ivec2(2));
}
return Error;
}
int main()
{
int Error = 0;
Error += test_operators();
Error += test_vec2_ctor();
Error += test_vec2_operators();
return Error;
}

View File

@@ -1,18 +1,91 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
// OpenGL Mathematics Copyright (c) 2005 - 2011 G-Truc Creation (www.g-truc.net)
///////////////////////////////////////////////////////////////////////////////////////////////////
// Created : 2010-09-16
// Updated : 2010-09-16
// Created : 2011-05-32
// Updated : 2011-05-32
// Licence : This source is under MIT licence
// File : test/gtc/matrix_transform.cpp
// File : test/gtc/half_float.cpp
///////////////////////////////////////////////////////////////////////////////////////////////////
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/half_float.hpp>
int test_half_precision_scalar()
{
int Error = 0;
Error += sizeof(glm::half) == 2 ? 0 : 1;
return Error;
}
int test_half_precision_vec()
{
int Error = 0;
Error += sizeof(glm::hvec2) == 4 ? 0 : 1;
Error += sizeof(glm::hvec3) == 6 ? 0 : 1;
Error += sizeof(glm::hvec4) == 8 ? 0 : 1;
return Error;
}
int test_half_precision_mat()
{
int Error = 0;
Error += sizeof(glm::hmat2) == 8 ? 0 : 1;
Error += sizeof(glm::hmat3) == 18 ? 0 : 1;
Error += sizeof(glm::hmat4) == 32 ? 0 : 1;
Error += sizeof(glm::hmat2x2) == 8 ? 0 : 1;
Error += sizeof(glm::hmat2x3) == 12 ? 0 : 1;
Error += sizeof(glm::hmat2x4) == 16 ? 0 : 1;
Error += sizeof(glm::hmat3x2) == 12 ? 0 : 1;
Error += sizeof(glm::hmat3x3) == 18 ? 0 : 1;
Error += sizeof(glm::hmat3x4) == 24 ? 0 : 1;
Error += sizeof(glm::hmat4x2) == 16 ? 0 : 1;
Error += sizeof(glm::hmat4x3) == 24 ? 0 : 1;
Error += sizeof(glm::hmat4x4) == 32 ? 0 : 1;
return Error;
}
int test_half_ctor_mat2x2()
{
int Error = 0;
{
glm::hvec2 A(1, 2);
glm::hvec2 B(3, 4);
glm::hmat2 C(A, B);//, 2.0f, 3.0f, 4.0f);
glm::hmat2 D(1, 2, 3, 4);
Error += C[0] == D[0] ? 0 : 1;
Error += C[1] == D[1] ? 0 : 1;
}
{
glm::hvec2 A(1, 2.0);
glm::hvec2 B(3, 4.0);
glm::hmat2 C(A, B);//, 2.0f, 3.0f, 4.0f);
glm::hmat2 D(1, 2.0, 3u, 4.0f);
Error += C[0] == D[0] ? 0 : 1;
Error += C[1] == D[1] ? 0 : 1;
}
return Error;
}
int main()
{
int Failed = 0;
int Error = 0;
return Failed;
Error += test_half_ctor_mat2x2();
Error += test_half_precision_scalar();
Error += test_half_precision_vec();
Error += test_half_precision_mat();
return Error;
}

View File

@@ -11,6 +11,16 @@
#include <glm/gtc/quaternion.hpp>
#include <glm/gtx/epsilon.hpp>
int test_quat_precision()
{
int Error = 0;
Error += sizeof(glm::lowp_quat) <= sizeof(glm::mediump_quat) ? 0 : 1;
Error += sizeof(glm::mediump_quat) <= sizeof(glm::highp_quat) ? 0 : 1;
return Error;
}
int test_quat_type()
{
glm::quat A;
@@ -19,66 +29,12 @@ int test_quat_type()
return 0;
}
int test_quat_slerp()
{
int Error = 0;
glm::quat A(glm::vec3(0, 0, 1));
glm::quat B(glm::vec3(0, 1, 0));
glm::quat C = glm::mix(A, B, 0.5f);
glm::quat D(glm::normalize(glm::vec3(0, 1, 1)));
Error += C == D ? 0 : 1;
return Error;
}
int test_quat_length()
{
int Error = 0;
float A = glm::length(glm::quat(45.0f, glm::vec3(0, 0, 1)));
Error += A == 1.0f ? 0 : 1;
float B = glm::length(glm::quat(90.0f, glm::vec3(0, 0, 2)));
Error += B == 2.0f ? 0 : 1;
return Error;
}
int test_quat_normalize()
{
int Error = 0;
{
glm::quat Q(45.0f, glm::vec3(0, 0, 1));
glm::quat N = glm::normalize(Q);
float L = glm::length(N);
Error += L == 1.0f ? 0 : 1;
}
{
glm::quat Q(45.0f, glm::vec3(0, 0, 2));
glm::quat N = glm::normalize(Q);
float L = glm::length(N);
Error += L == 1.0f ? 0 : 1;
}
{
glm::quat Q(45.0f, glm::vec3(1, 2, 3));
glm::quat N = glm::normalize(Q);
float L = glm::length(N);
Error += L == 1.0f ? 0 : 1;
}
return Error;
}
int main()
{
int Error = 0;
Error += test_quat_precision();
Error += test_quat_type();
Error += test_quat_slerp();
Error += test_quat_length();
Error += test_quat_normalize();
return Error;
}

View File

@@ -1,6 +1,7 @@
glmCreateTestGTC(gtx_bit)
glmCreateTestGTC(gtx_noise)
glmCreateTestGTC(gtx_quaternion)
glmCreateTestGTC(gtx_random)
glmCreateTestGTC(gtx_rotate_vector)
glmCreateTestGTC(gtx_simd_vec4)
glmCreateTestGTC(gtx_simd_mat4)

View File

@@ -11,17 +11,40 @@
#include <glm/gtx/noise.hpp>
#include <iostream>
int main()
int test_simplex()
{
float ValueSNoise2D = glm::simplex(glm::vec2(0.5f));
float ValueSNoise3D = glm::simplex(glm::vec3(0.5f));
float ValueSNoise4D = glm::simplex(glm::vec4(0.5f));
return 0;
}
int test_perlin()
{
float ValueCNoise2D = glm::perlin(glm::vec2(0.5f));
float ValueCNoise3D = glm::perlin(glm::vec3(0.5f));
float ValueCNoise4D = glm::perlin(glm::vec4(0.5f));
return 0;
}
int test_perlin_pedioric()
{
float ValuePNoise2D = glm::perlin(glm::vec2(0.5f), glm::vec2(0.5f));
float ValuePNoise3D = glm::perlin(glm::vec3(0.5f), glm::vec3(0.5f));
float ValuePNoise4D = glm::perlin(glm::vec4(0.5f), glm::vec4(0.5f));
return 0;
}
int main()
{
int Error = 0;
Error += test_simplex();
Error += test_perlin();
Error += test_perlin_pedioric();
return Error;
}

View File

@@ -2,7 +2,7 @@
// OpenGL Mathematics Copyright (c) 2005 - 2011 G-Truc Creation (www.g-truc.net)
///////////////////////////////////////////////////////////////////////////////////////////////////
// Created : 2011-05-25
// Updated : 2011-05-25
// Updated : 2011-05-31
// Licence : This source is under MIT licence
// File : test/gtx/quaternion.cpp
///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -11,6 +11,57 @@
#include <glm/gtx/quaternion.hpp>
#include <glm/gtx/epsilon.hpp>
int test_quat_mix()
{
int Error = 0;
glm::quat A = glm::angleAxis(0.0f, glm::vec3(0, 0, 1));
glm::quat B = glm::angleAxis(90.0f, glm::vec3(0, 0, 1));
glm::quat C = glm::mix(A, B, 0.5f);
glm::quat D = glm::angleAxis(45.0f, glm::vec3(0, 0, 1));
Error += glm::equalEpsilon(C.x, D.x, 0.01f) ? 0 : 1;
Error += glm::equalEpsilon(C.y, D.y, 0.01f) ? 0 : 1;
Error += glm::equalEpsilon(C.z, D.z, 0.01f) ? 0 : 1;
Error += glm::equalEpsilon(C.w, D.w, 0.01f) ? 0 : 1;
return Error;
}
int test_quat_fastMix()
{
int Error = 0;
glm::quat A = glm::angleAxis(0.0f, glm::vec3(0, 0, 1));
glm::quat B = glm::angleAxis(90.0f, glm::vec3(0, 0, 1));
glm::quat C = glm::fastMix(A, B, 0.5f);
glm::quat D = glm::angleAxis(45.0f, glm::vec3(0, 0, 1));
Error += glm::equalEpsilon(C.x, D.x, 0.01f) ? 0 : 1;
Error += glm::equalEpsilon(C.y, D.y, 0.01f) ? 0 : 1;
Error += glm::equalEpsilon(C.z, D.z, 0.01f) ? 0 : 1;
Error += glm::equalEpsilon(C.w, D.w, 0.01f) ? 0 : 1;
return Error;
}
int test_quat_shortMix()
{
int Error = 0;
glm::quat A = glm::angleAxis(0.0f, glm::vec3(0, 0, 1));
glm::quat B = glm::angleAxis(90.0f, glm::vec3(0, 0, 1));
glm::quat C = glm::shortMix(A, B, 0.5f);
glm::quat D = glm::angleAxis(45.0f, glm::vec3(0, 0, 1));
Error += glm::equalEpsilon(C.x, D.x, 0.01f) ? 0 : 1;
Error += glm::equalEpsilon(C.y, D.y, 0.01f) ? 0 : 1;
Error += glm::equalEpsilon(C.z, D.z, 0.01f) ? 0 : 1;
Error += glm::equalEpsilon(C.w, D.w, 0.01f) ? 0 : 1;
return Error;
}
int test_quat_angleAxis()
{
int Error = 0;
@@ -60,12 +111,42 @@ int test_quat_angle()
return Error;
}
int test_quat_normalize()
{
int Error = 0;
{
glm::quat Q = glm::angleAxis(45.0f, glm::vec3(0, 0, 1));
glm::quat N = glm::normalize(Q);
float L = glm::length(N);
Error += glm::equalEpsilon(L, 1.0f, 0.000001f) ? 0 : 1;
}
{
glm::quat Q = glm::angleAxis(45.0f, glm::vec3(0, 0, 2));
glm::quat N = glm::normalize(Q);
float L = glm::length(N);
Error += glm::equalEpsilon(L, 1.0f, 0.000001f) ? 0 : 1;
}
{
glm::quat Q = glm::angleAxis(45.0f, glm::vec3(1, 2, 3));
glm::quat N = glm::normalize(Q);
float L = glm::length(N);
Error += glm::equalEpsilon(L, 1.0f, 0.000001f) ? 0 : 1;
}
return Error;
}
int main()
{
int Error = 0;
Error += test_quat_angle();
Error += test_quat_angleAxis();
Error += test_quat_mix();
Error += test_quat_fastMix();
Error += test_quat_shortMix();
Error += test_quat_normalize();
return Error;
}

98
test/gtx/gtx_random.cpp Normal file
View File

@@ -0,0 +1,98 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
// OpenGL Mathematics Copyright (c) 2005 - 2011 G-Truc Creation (www.g-truc.net)
///////////////////////////////////////////////////////////////////////////////////////////////////
// Created : 2011-05-31
// Updated : 2011-05-31
// Licence : This source is under MIT licence
// File : test/gtx/random.cpp
///////////////////////////////////////////////////////////////////////////////////////////////////
#include <glm/glm.hpp>
#include <glm/gtx/random.hpp>
#include <glm/gtx/epsilon.hpp>
#include <iostream>
int test_signedRand1()
{
int Error = 0;
{
float ResultFloat = 0.0f;
double ResultDouble = 0.0f;
for(std::size_t i = 0; i < 100000; ++i)
{
ResultFloat += glm::signedRand1<float>();
ResultDouble += glm::signedRand1<double>();
}
Error += glm::equalEpsilon(ResultFloat, 0.0f, 0.0001f);
Error += glm::equalEpsilon(ResultDouble, 0.0, 0.0001);
}
return Error;
}
int test_normalizedRand2()
{
int Error = 0;
{
std::size_t Max = 100000;
float ResultFloat = 0.0f;
double ResultDouble = 0.0f;
for(std::size_t i = 0; i < Max; ++i)
{
ResultFloat += glm::length(glm::normalizedRand2<float>());
ResultDouble += glm::length(glm::normalizedRand2<double>());
}
Error += glm::equalEpsilon(ResultFloat, float(Max), 0.0001f);
Error += glm::equalEpsilon(ResultDouble, double(Max), 0.0001);
}
return Error;
}
int test_normalizedRand3()
{
int Error = 0;
{
std::size_t Max = 100000;
float ResultFloatA = 0.0f;
float ResultFloatB = 0.0f;
float ResultFloatC = 0.0f;
double ResultDoubleA = 0.0f;
double ResultDoubleB = 0.0f;
double ResultDoubleC = 0.0f;
for(std::size_t i = 0; i < Max; ++i)
{
ResultFloatA += glm::length(glm::normalizedRand3<float>());
ResultDoubleA += glm::length(glm::normalizedRand3<double>());
ResultFloatB += glm::length(glm::normalizedRand3(2.0f, 2.0f));
ResultDoubleB += glm::length(glm::normalizedRand3(2.0, 2.0));
ResultFloatC += glm::length(glm::normalizedRand3(1.0f, 3.0f));
ResultDoubleC += glm::length(glm::normalizedRand3(1.0, 3.0));
}
Error += glm::equalEpsilon(ResultFloatA, float(Max), 0.0001f) ? 0 : 1;
Error += glm::equalEpsilon(ResultDoubleA, double(Max), 0.0001) ? 0 : 1;
Error += glm::equalEpsilon(ResultFloatB, float(Max * 2), 0.0001f) ? 0 : 1;
Error += glm::equalEpsilon(ResultDoubleB, double(Max * 2), 0.0001) ? 0 : 1;
Error += (ResultFloatC >= float(Max) && ResultFloatC <= float(Max * 3)) ? 0 : 1;
Error += (ResultDoubleC >= double(Max) && ResultDoubleC <= double(Max * 3)) ? 0 : 1;
}
return Error;
}
int main()
{
int Error = 0;
Error += test_signedRand1();
Error += test_normalizedRand2();
Error += test_normalizedRand3();
return Error;
}