[ADD] template project with correct name

This commit is contained in:
Sem van der Hoeven
2021-05-18 10:33:08 +02:00
parent 73538d9a93
commit 2f1a8e77e8
1699 changed files with 331415 additions and 0 deletions

View File

@@ -0,0 +1,58 @@
glmCreateTestGTC(gtx)
glmCreateTestGTC(gtx_associated_min_max)
glmCreateTestGTC(gtx_closest_point)
glmCreateTestGTC(gtx_color_encoding)
glmCreateTestGTC(gtx_color_space_YCoCg)
glmCreateTestGTC(gtx_color_space)
glmCreateTestGTC(gtx_common)
glmCreateTestGTC(gtx_compatibility)
glmCreateTestGTC(gtx_component_wise)
glmCreateTestGTC(gtx_easing)
glmCreateTestGTC(gtx_euler_angle)
glmCreateTestGTC(gtx_extend)
glmCreateTestGTC(gtx_extended_min_max)
glmCreateTestGTC(gtx_exterior_product)
glmCreateTestGTC(gtx_fast_exponential)
glmCreateTestGTC(gtx_fast_square_root)
glmCreateTestGTC(gtx_fast_trigonometry)
glmCreateTestGTC(gtx_functions)
glmCreateTestGTC(gtx_gradient_paint)
glmCreateTestGTC(gtx_handed_coordinate_space)
glmCreateTestGTC(gtx_integer)
glmCreateTestGTC(gtx_intersect)
glmCreateTestGTC(gtx_io)
glmCreateTestGTC(gtx_load)
glmCreateTestGTC(gtx_log_base)
glmCreateTestGTC(gtx_matrix_cross_product)
glmCreateTestGTC(gtx_matrix_decompose)
glmCreateTestGTC(gtx_matrix_factorisation)
glmCreateTestGTC(gtx_matrix_interpolation)
glmCreateTestGTC(gtx_matrix_major_storage)
glmCreateTestGTC(gtx_matrix_operation)
glmCreateTestGTC(gtx_matrix_query)
glmCreateTestGTC(gtx_matrix_transform_2d)
glmCreateTestGTC(gtx_norm)
glmCreateTestGTC(gtx_normal)
glmCreateTestGTC(gtx_normalize_dot)
glmCreateTestGTC(gtx_number_precision)
glmCreateTestGTC(gtx_orthonormalize)
glmCreateTestGTC(gtx_optimum_pow)
glmCreateTestGTC(gtx_perpendicular)
glmCreateTestGTC(gtx_polar_coordinates)
glmCreateTestGTC(gtx_projection)
glmCreateTestGTC(gtx_quaternion)
glmCreateTestGTC(gtx_dual_quaternion)
glmCreateTestGTC(gtx_range)
glmCreateTestGTC(gtx_rotate_normalized_axis)
glmCreateTestGTC(gtx_rotate_vector)
glmCreateTestGTC(gtx_scalar_multiplication)
glmCreateTestGTC(gtx_scalar_relational)
glmCreateTestGTC(gtx_spline)
glmCreateTestGTC(gtx_string_cast)
glmCreateTestGTC(gtx_texture)
glmCreateTestGTC(gtx_type_aligned)
glmCreateTestGTC(gtx_type_trait)
glmCreateTestGTC(gtx_vec_swizzle)
glmCreateTestGTC(gtx_vector_angle)
glmCreateTestGTC(gtx_vector_query)
glmCreateTestGTC(gtx_wrap)

8
lib/glm/test/gtx/gtx.cpp Normal file
View File

@@ -0,0 +1,8 @@
#include <glm/ext.hpp>
int main()
{
int Error = 0;
return Error;
}

View File

@@ -0,0 +1,10 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtc/type_precision.hpp>
#include <glm/gtx/associated_min_max.hpp>
int main()
{
int Error(0);
return Error;
}

View File

@@ -0,0 +1,9 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/closest_point.hpp>
int main()
{
int Error(0);
return Error;
}

View File

@@ -0,0 +1,51 @@
#include <glm/gtx/color_encoding.hpp>
#include <glm/gtc/color_space.hpp>
#include <glm/gtc/epsilon.hpp>
#include <glm/gtc/constants.hpp>
namespace srgb
{
int test()
{
int Error(0);
glm::vec3 const ColorSourceRGB(1.0, 0.5, 0.0);
/*
{
glm::vec3 const ColorSRGB = glm::convertLinearSRGBToD65XYZ(ColorSourceRGB);
glm::vec3 const ColorRGB = glm::convertD65XYZToLinearSRGB(ColorSRGB);
Error += glm::all(glm::epsilonEqual(ColorSourceRGB, ColorRGB, 0.00001f)) ? 0 : 1;
}
*/
{
glm::vec3 const ColorSRGB = glm::convertLinearToSRGB(ColorSourceRGB, 2.8f);
glm::vec3 const ColorRGB = glm::convertSRGBToLinear(ColorSRGB, 2.8f);
Error += glm::all(glm::epsilonEqual(ColorSourceRGB, ColorRGB, 0.00001f)) ? 0 : 1;
}
glm::vec4 const ColorSourceRGBA(1.0, 0.5, 0.0, 1.0);
{
glm::vec4 const ColorSRGB = glm::convertLinearToSRGB(ColorSourceRGBA);
glm::vec4 const ColorRGB = glm::convertSRGBToLinear(ColorSRGB);
Error += glm::all(glm::epsilonEqual(ColorSourceRGBA, ColorRGB, 0.00001f)) ? 0 : 1;
}
{
glm::vec4 const ColorSRGB = glm::convertLinearToSRGB(ColorSourceRGBA, 2.8f);
glm::vec4 const ColorRGB = glm::convertSRGBToLinear(ColorSRGB, 2.8f);
Error += glm::all(glm::epsilonEqual(ColorSourceRGBA, ColorRGB, 0.00001f)) ? 0 : 1;
}
return Error;
}
}//namespace srgb
int main()
{
int Error(0);
Error += srgb::test();
return Error;
}

View File

@@ -0,0 +1,20 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/color_space.hpp>
int test_saturation()
{
int Error(0);
glm::vec4 Color = glm::saturation(1.0f, glm::vec4(1.0, 0.5, 0.0, 1.0));
return Error;
}
int main()
{
int Error(0);
Error += test_saturation();
return Error;
}

View File

@@ -0,0 +1,9 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/color_space_YCoCg.hpp>
int main()
{
int Error(0);
return Error;
}

View File

@@ -0,0 +1,161 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/common.hpp>
#include <glm/gtc/integer.hpp>
#include <glm/gtc/epsilon.hpp>
#include <glm/vector_relational.hpp>
#include <glm/common.hpp>
namespace fmod_
{
template<typename genType>
GLM_FUNC_QUALIFIER genType modTrunc(genType a, genType b)
{
return a - b * glm::trunc(a / b);
}
int test()
{
int Error(0);
{
float A0(3.0);
float B0(2.0f);
float C0 = glm::fmod(A0, B0);
Error += glm::abs(C0 - 1.0f) < 0.00001f ? 0 : 1;
glm::vec4 A1(3.0);
float B1(2.0f);
glm::vec4 C1 = glm::fmod(A1, B1);
Error += glm::all(glm::epsilonEqual(C1, glm::vec4(1.0f), 0.00001f)) ? 0 : 1;
glm::vec4 A2(3.0);
glm::vec4 B2(2.0f);
glm::vec4 C2 = glm::fmod(A2, B2);
Error += glm::all(glm::epsilonEqual(C2, glm::vec4(1.0f), 0.00001f)) ? 0 : 1;
glm::ivec4 A3(3);
int B3(2);
glm::ivec4 C3 = glm::fmod(A3, B3);
Error += glm::all(glm::equal(C3, glm::ivec4(1))) ? 0 : 1;
glm::ivec4 A4(3);
glm::ivec4 B4(2);
glm::ivec4 C4 = glm::fmod(A4, B4);
Error += glm::all(glm::equal(C4, glm::ivec4(1))) ? 0 : 1;
}
{
float A0(22.0);
float B0(-10.0f);
float C0 = glm::fmod(A0, B0);
Error += glm::abs(C0 - 2.0f) < 0.00001f ? 0 : 1;
glm::vec4 A1(22.0);
float B1(-10.0f);
glm::vec4 C1 = glm::fmod(A1, B1);
Error += glm::all(glm::epsilonEqual(C1, glm::vec4(2.0f), 0.00001f)) ? 0 : 1;
glm::vec4 A2(22.0);
glm::vec4 B2(-10.0f);
glm::vec4 C2 = glm::fmod(A2, B2);
Error += glm::all(glm::epsilonEqual(C2, glm::vec4(2.0f), 0.00001f)) ? 0 : 1;
glm::ivec4 A3(22);
int B3(-10);
glm::ivec4 C3 = glm::fmod(A3, B3);
Error += glm::all(glm::equal(C3, glm::ivec4(2))) ? 0 : 1;
glm::ivec4 A4(22);
glm::ivec4 B4(-10);
glm::ivec4 C4 = glm::fmod(A4, B4);
Error += glm::all(glm::equal(C4, glm::ivec4(2))) ? 0 : 1;
}
// http://stackoverflow.com/questions/7610631/glsl-mod-vs-hlsl-fmod
{
for (float y = -10.0f; y < 10.0f; y += 0.1f)
for (float x = -10.0f; x < 10.0f; x += 0.1f)
{
float const A(std::fmod(x, y));
//float const B(std::remainder(x, y));
float const C(glm::fmod(x, y));
float const D(modTrunc(x, y));
//Error += glm::epsilonEqual(A, B, 0.0001f) ? 0 : 1;
//assert(!Error);
Error += glm::epsilonEqual(A, C, 0.0001f) ? 0 : 1;
assert(!Error);
Error += glm::epsilonEqual(A, D, 0.00001f) ? 0 : 1;
assert(!Error);
}
}
return Error;
}
}//namespace fmod_
int test_isdenormal()
{
int Error = 0;
bool A = glm::isdenormal(1.0f);
Error += !A ? 0 : 1;
glm::bvec1 B = glm::isdenormal(glm::vec1(1.0f));
Error += !glm::any(B) ? 0 : 1;
glm::bvec2 C = glm::isdenormal(glm::vec2(1.0f));
Error += !glm::any(C) ? 0 : 1;
glm::bvec3 D = glm::isdenormal(glm::vec3(1.0f));
Error += !glm::any(D) ? 0 : 1;
glm::bvec4 E = glm::isdenormal(glm::vec4(1.0f));
Error += !glm::any(E) ? 0 : 1;
return Error;
}
int test_openBounded()
{
int Error = 0;
Error += glm::all(glm::openBounded(glm::ivec2(2), glm::ivec2(1), glm::ivec2(3))) ? 0 : 1;
Error += !glm::all(glm::openBounded(glm::ivec2(1), glm::ivec2(1), glm::ivec2(3))) ? 0 : 1;
Error += !glm::all(glm::openBounded(glm::ivec2(3), glm::ivec2(1), glm::ivec2(3))) ? 0 : 1;
return Error;
}
int test_closeBounded()
{
int Error = 0;
Error += glm::all(glm::closeBounded(glm::ivec2(2), glm::ivec2(1), glm::ivec2(3))) ? 0 : 1;
Error += glm::all(glm::closeBounded(glm::ivec2(1), glm::ivec2(1), glm::ivec2(3))) ? 0 : 1;
Error += glm::all(glm::closeBounded(glm::ivec2(3), glm::ivec2(1), glm::ivec2(3))) ? 0 : 1;
return Error;
}
int main()
{
int Error = 0;
Error += test_isdenormal();
Error += ::fmod_::test();
Error += test_openBounded();
Error += test_closeBounded();
return Error;
}

View File

@@ -0,0 +1,19 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/compatibility.hpp>
int main()
{
int Error(0);
Error += glm::isfinite(1.0f) ? 0 : 1;
Error += glm::isfinite(1.0) ? 0 : 1;
Error += glm::isfinite(-1.0f) ? 0 : 1;
Error += glm::isfinite(-1.0) ? 0 : 1;
Error += glm::all(glm::isfinite(glm::vec4(1.0f))) ? 0 : 1;
Error += glm::all(glm::isfinite(glm::dvec4(1.0))) ? 0 : 1;
Error += glm::all(glm::isfinite(glm::vec4(-1.0f))) ? 0 : 1;
Error += glm::all(glm::isfinite(glm::dvec4(-1.0))) ? 0 : 1;
return Error;
}

View File

@@ -0,0 +1,116 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/component_wise.hpp>
#include <glm/gtc/type_precision.hpp>
#include <glm/gtc/epsilon.hpp>
#include <glm/gtc/constants.hpp>
#include <limits>
namespace compNormalize
{
int run()
{
int Error(0);
{
glm::vec4 const A = glm::compNormalize<float>(glm::u8vec4(0, 127, 128, 255));
Error += glm::epsilonEqual(A.x, 0.0f, glm::epsilon<float>()) ? 0 : 1;
Error += A.y < 0.5f ? 0 : 1;
Error += A.z > 0.5f ? 0 : 1;
Error += glm::epsilonEqual(A.w, 1.0f, glm::epsilon<float>()) ? 0 : 1;
}
{
glm::vec4 const A = glm::compNormalize<float>(glm::i8vec4(-128, -1, 0, 127));
Error += glm::epsilonEqual(A.x,-1.0f, glm::epsilon<float>()) ? 0 : 1;
Error += A.y < 0.0f ? 0 : 1;
Error += A.z > 0.0f ? 0 : 1;
Error += glm::epsilonEqual(A.w, 1.0f, glm::epsilon<float>()) ? 0 : 1;
}
{
glm::vec4 const A = glm::compNormalize<float>(glm::u16vec4(
std::numeric_limits<glm::u16>::min(),
(std::numeric_limits<glm::u16>::max() >> 1) + 0,
(std::numeric_limits<glm::u16>::max() >> 1) + 1,
std::numeric_limits<glm::u16>::max()));
Error += glm::epsilonEqual(A.x, 0.0f, glm::epsilon<float>()) ? 0 : 1;
Error += A.y < 0.5f ? 0 : 1;
Error += A.z > 0.5f ? 0 : 1;
Error += glm::epsilonEqual(A.w, 1.0f, glm::epsilon<float>()) ? 0 : 1;
}
{
glm::vec4 const A = glm::compNormalize<float>(glm::i16vec4(
std::numeric_limits<glm::i16>::min(),
static_cast<glm::i16>(-1),
static_cast<glm::i16>(0),
std::numeric_limits<glm::i16>::max()));
Error += glm::epsilonEqual(A.x,-1.0f, glm::epsilon<float>()) ? 0 : 1;
Error += A.y < 0.0f ? 0 : 1;
Error += A.z > 0.0f ? 0 : 1;
Error += glm::epsilonEqual(A.w, 1.0f, glm::epsilon<float>()) ? 0 : 1;
}
return Error;
}
}//namespace compNormalize
namespace compScale
{
int run()
{
int Error(0);
{
glm::u8vec4 const A = glm::compScale<glm::u8>(glm::vec4(0.0f, 0.2f, 0.5f, 1.0f));
Error += A.x == std::numeric_limits<glm::u8>::min() ? 0 : 1;
Error += A.y < (std::numeric_limits<glm::u8>::max() >> 2) ? 0 : 1;
Error += A.z == 127 ? 0 : 1;
Error += A.w == 255 ? 0 : 1;
}
{
glm::i8vec4 const A = glm::compScale<glm::i8>(glm::vec4(0.0f,-1.0f, 0.5f, 1.0f));
Error += A.x == 0 ? 0 : 1;
Error += A.y == -128 ? 0 : 1;
Error += A.z == 63 ? 0 : 1;
Error += A.w == 127 ? 0 : 1;
}
{
glm::u16vec4 const A = glm::compScale<glm::u16>(glm::vec4(0.0f, 0.2f, 0.5f, 1.0f));
Error += A.x == std::numeric_limits<glm::u16>::min() ? 0 : 1;
Error += A.y < (std::numeric_limits<glm::u16>::max() >> 2) ? 0 : 1;
Error += A.z == 32767 ? 0 : 1;
Error += A.w == 65535 ? 0 : 1;
}
{
glm::i16vec4 const A = glm::compScale<glm::i16>(glm::vec4(0.0f,-1.0f, 0.5f, 1.0f));
Error += A.x == 0 ? 0 : 1;
Error += A.y == -32768 ? 0 : 1;
Error += A.z == 16383 ? 0 : 1;
Error += A.w == 32767 ? 0 : 1;
}
return Error;
}
}// compScale
int main()
{
int Error(0);
Error += compNormalize::run();
Error += compScale::run();
return Error;
}

View File

@@ -0,0 +1,205 @@
#define GLM_ENABLE_EXPERIMENTAL
#define GLM_FORCE_CTOR_INIT
#include <glm/gtx/dual_quaternion.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/epsilon.hpp>
#include <glm/gtx/euler_angles.hpp>
#include <glm/vector_relational.hpp>
#if GLM_HAS_TRIVIAL_QUERIES
# include <type_traits>
#endif
int myrand()
{
static int holdrand = 1;
return (((holdrand = holdrand * 214013L + 2531011L) >> 16) & 0x7fff);
}
float myfrand() // returns values from -1 to 1 inclusive
{
return float(double(myrand()) / double( 0x7ffff )) * 2.0f - 1.0f;
}
int test_dquat_type()
{
glm::dvec3 vA;
glm::dquat dqA, dqB;
glm::ddualquat C(dqA, dqB);
glm::ddualquat B(dqA);
glm::ddualquat D(dqA, vA);
return 0;
}
int test_scalars()
{
float const Epsilon = 0.0001f;
int Error(0);
glm::quat src_q1 = glm::quat(1.0f,2.0f,3.0f,4.0f);
glm::quat src_q2 = glm::quat(5.0f,6.0f,7.0f,8.0f);
glm::dualquat src1(src_q1,src_q2);
{
glm::dualquat dst1 = src1 * 2.0f;
glm::dualquat dst2 = 2.0f * src1;
glm::dualquat dst3 = src1;
dst3 *= 2.0f;
glm::dualquat dstCmp(src_q1 * 2.0f,src_q2 * 2.0f);
Error += glm::all(glm::epsilonEqual(dst1.real,dstCmp.real, Epsilon)) && glm::all(glm::epsilonEqual(dst1.dual,dstCmp.dual, Epsilon)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(dst2.real,dstCmp.real, Epsilon)) && glm::all(glm::epsilonEqual(dst2.dual,dstCmp.dual, Epsilon)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(dst3.real,dstCmp.real, Epsilon)) && glm::all(glm::epsilonEqual(dst3.dual,dstCmp.dual, Epsilon)) ? 0 : 1;
}
{
glm::dualquat dst1 = src1 / 2.0f;
glm::dualquat dst2 = src1;
dst2 /= 2.0f;
glm::dualquat dstCmp(src_q1 / 2.0f,src_q2 / 2.0f);
Error += glm::all(glm::epsilonEqual(dst1.real,dstCmp.real, Epsilon)) && glm::all(glm::epsilonEqual(dst1.dual,dstCmp.dual, Epsilon)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(dst2.real,dstCmp.real, Epsilon)) && glm::all(glm::epsilonEqual(dst2.dual,dstCmp.dual, Epsilon)) ? 0 : 1;
}
return Error;
}
int test_inverse()
{
int Error(0);
float const Epsilon = 0.0001f;
glm::dualquat dqid = glm::dual_quat_identity<float, glm::defaultp>();
glm::mat4x4 mid(1.0f);
for (int j = 0; j < 100; ++j)
{
glm::mat4x4 rot = glm::yawPitchRoll(myfrand() * 360.0f, myfrand() * 360.0f, myfrand() * 360.0f);
glm::vec3 vt = glm::vec3(myfrand() * 10.0f, myfrand() * 10.0f, myfrand() * 10.0f);
glm::mat4x4 m = glm::translate(mid, vt) * rot;
glm::quat qr = glm::quat_cast(m);
glm::dualquat dq(qr);
glm::dualquat invdq = glm::inverse(dq);
glm::dualquat r1 = invdq * dq;
glm::dualquat r2 = dq * invdq;
Error += glm::all(glm::epsilonEqual(r1.real, dqid.real, Epsilon)) && glm::all(glm::epsilonEqual(r1.dual, dqid.dual, Epsilon)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(r2.real, dqid.real, Epsilon)) && glm::all(glm::epsilonEqual(r2.dual, dqid.dual, Epsilon)) ? 0 : 1;
// testing commutative property
glm::dualquat r ( glm::quat( myfrand() * glm::pi<float>() * 2.0f, myfrand(), myfrand(), myfrand() ),
glm::vec3(myfrand() * 10.0f, myfrand() * 10.0f, myfrand() * 10.0f) );
glm::dualquat riq = (r * invdq) * dq;
glm::dualquat rqi = (r * dq) * invdq;
Error += glm::all(glm::epsilonEqual(riq.real, rqi.real, Epsilon)) && glm::all(glm::epsilonEqual(riq.dual, rqi.dual, Epsilon)) ? 0 : 1;
}
return Error;
}
int test_mul()
{
int Error(0);
float const Epsilon = 0.0001f;
glm::mat4x4 mid(1.0f);
for (int j = 0; j < 100; ++j)
{
// generate random rotations and translations and compare transformed by matrix and dualquats random points
glm::vec3 vt1 = glm::vec3(myfrand() * 10.0f, myfrand() * 10.0f, myfrand() * 10.0f);
glm::vec3 vt2 = glm::vec3(myfrand() * 10.0f, myfrand() * 10.0f, myfrand() * 10.0f);
glm::mat4x4 rot1 = glm::yawPitchRoll(myfrand() * 360.0f, myfrand() * 360.0f, myfrand() * 360.0f);
glm::mat4x4 rot2 = glm::yawPitchRoll(myfrand() * 360.0f, myfrand() * 360.0f, myfrand() * 360.0f);
glm::mat4x4 m1 = glm::translate(mid, vt1) * rot1;
glm::mat4x4 m2 = glm::translate(mid, vt2) * rot2;
glm::mat4x4 m3 = m2 * m1;
glm::mat4x4 m4 = m1 * m2;
glm::quat qrot1 = glm::quat_cast(rot1);
glm::quat qrot2 = glm::quat_cast(rot2);
glm::dualquat dq1 = glm::dualquat(qrot1,vt1);
glm::dualquat dq2 = glm::dualquat(qrot2,vt2);
glm::dualquat dq3 = dq2 * dq1;
glm::dualquat dq4 = dq1 * dq2;
for (int i = 0; i < 100; ++i)
{
glm::vec4 src_pt = glm::vec4(myfrand() * 4.0f, myfrand() * 5.0f, myfrand() * 3.0f,1.0f);
// test both multiplication orders
glm::vec4 dst_pt_m3 = m3 * src_pt;
glm::vec4 dst_pt_dq3 = dq3 * src_pt;
glm::vec4 dst_pt_m3_i = glm::inverse(m3) * src_pt;
glm::vec4 dst_pt_dq3_i = src_pt * dq3;
glm::vec4 dst_pt_m4 = m4 * src_pt;
glm::vec4 dst_pt_dq4 = dq4 * src_pt;
glm::vec4 dst_pt_m4_i = glm::inverse(m4) * src_pt;
glm::vec4 dst_pt_dq4_i = src_pt * dq4;
Error += glm::all(glm::epsilonEqual(dst_pt_m3, dst_pt_dq3, Epsilon)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(dst_pt_m4, dst_pt_dq4, Epsilon)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(dst_pt_m3_i, dst_pt_dq3_i, Epsilon)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(dst_pt_m4_i, dst_pt_dq4_i, Epsilon)) ? 0 : 1;
}
}
return Error;
}
int test_dual_quat_ctr()
{
int Error(0);
# if GLM_HAS_TRIVIAL_QUERIES
// Error += std::is_trivially_default_constructible<glm::dualquat>::value ? 0 : 1;
// Error += std::is_trivially_default_constructible<glm::ddualquat>::value ? 0 : 1;
// Error += std::is_trivially_copy_assignable<glm::dualquat>::value ? 0 : 1;
// Error += std::is_trivially_copy_assignable<glm::ddualquat>::value ? 0 : 1;
Error += std::is_trivially_copyable<glm::dualquat>::value ? 0 : 1;
Error += std::is_trivially_copyable<glm::ddualquat>::value ? 0 : 1;
Error += std::is_copy_constructible<glm::dualquat>::value ? 0 : 1;
Error += std::is_copy_constructible<glm::ddualquat>::value ? 0 : 1;
# endif
return Error;
}
int test_size()
{
int Error = 0;
Error += 32 == sizeof(glm::dualquat) ? 0 : 1;
Error += 64 == sizeof(glm::ddualquat) ? 0 : 1;
Error += glm::dualquat().length() == 2 ? 0 : 1;
Error += glm::ddualquat().length() == 2 ? 0 : 1;
Error += glm::dualquat::length() == 2 ? 0 : 1;
Error += glm::ddualquat::length() == 2 ? 0 : 1;
return Error;
}
int main()
{
int Error = 0;
Error += test_dual_quat_ctr();
Error += test_dquat_type();
Error += test_scalars();
Error += test_inverse();
Error += test_mul();
Error += test_size();
return Error;
}

View File

@@ -0,0 +1,65 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/glm.hpp>
#include <glm/gtx/quaternion.hpp>
#include <glm/gtx/easing.hpp>
namespace
{
template<typename T>
void _test_easing()
{
T a = static_cast<T>(0.5);
T r;
r = glm::linearInterpolation(a);
r = glm::quadraticEaseIn(a);
r = glm::quadraticEaseOut(a);
r = glm::quadraticEaseInOut(a);
r = glm::cubicEaseIn(a);
r = glm::cubicEaseOut(a);
r = glm::cubicEaseInOut(a);
r = glm::quarticEaseIn(a);
r = glm::quarticEaseOut(a);
r = glm::quinticEaseInOut(a);
r = glm::sineEaseIn(a);
r = glm::sineEaseOut(a);
r = glm::sineEaseInOut(a);
r = glm::circularEaseIn(a);
r = glm::circularEaseOut(a);
r = glm::circularEaseInOut(a);
r = glm::exponentialEaseIn(a);
r = glm::exponentialEaseOut(a);
r = glm::exponentialEaseInOut(a);
r = glm::elasticEaseIn(a);
r = glm::elasticEaseOut(a);
r = glm::elasticEaseInOut(a);
r = glm::backEaseIn(a);
r = glm::backEaseOut(a);
r = glm::backEaseInOut(a);
r = glm::bounceEaseIn(a);
r = glm::bounceEaseOut(a);
r = glm::bounceEaseInOut(a);
}
}
int main()
{
int Error = 0;
_test_easing<float>();
_test_easing<double>();
return Error;
}

View File

@@ -0,0 +1,539 @@
// Code sample from Filippo Ramaciotti
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtx/matrix_cross_product.hpp>
#include <glm/gtx/matrix_operation.hpp>
#include <glm/gtc/epsilon.hpp>
#include <glm/gtx/string_cast.hpp>
#include <glm/gtx/euler_angles.hpp>
#include <cstdio>
#include <vector>
#include <utility>
namespace test_eulerAngleX
{
int test()
{
int Error = 0;
float const Angle(glm::pi<float>() * 0.5f);
glm::vec3 const X(1.0f, 0.0f, 0.0f);
glm::vec4 const Y(0.0f, 1.0f, 0.0f, 1.0f);
glm::vec4 const Y1 = glm::rotate(glm::mat4(1.0f), Angle, X) * Y;
glm::vec4 const Y2 = glm::eulerAngleX(Angle) * Y;
glm::vec4 const Y3 = glm::eulerAngleXY(Angle, 0.0f) * Y;
glm::vec4 const Y4 = glm::eulerAngleYX(0.0f, Angle) * Y;
glm::vec4 const Y5 = glm::eulerAngleXZ(Angle, 0.0f) * Y;
glm::vec4 const Y6 = glm::eulerAngleZX(0.0f, Angle) * Y;
glm::vec4 const Y7 = glm::eulerAngleYXZ(0.0f, Angle, 0.0f) * Y;
Error += glm::all(glm::epsilonEqual(Y1, Y2, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Y1, Y3, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Y1, Y4, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Y1, Y5, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Y1, Y6, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Y1, Y7, 0.00001f)) ? 0 : 1;
glm::vec4 const Z(0.0f, 0.0f, 1.0f, 1.0f);
glm::vec4 const Z1 = glm::rotate(glm::mat4(1.0f), Angle, X) * Z;
glm::vec4 const Z2 = glm::eulerAngleX(Angle) * Z;
glm::vec4 const Z3 = glm::eulerAngleXY(Angle, 0.0f) * Z;
glm::vec4 const Z4 = glm::eulerAngleYX(0.0f, Angle) * Z;
glm::vec4 const Z5 = glm::eulerAngleXZ(Angle, 0.0f) * Z;
glm::vec4 const Z6 = glm::eulerAngleZX(0.0f, Angle) * Z;
glm::vec4 const Z7 = glm::eulerAngleYXZ(0.0f, Angle, 0.0f) * Z;
Error += glm::all(glm::epsilonEqual(Z1, Z2, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Z1, Z3, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Z1, Z4, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Z1, Z5, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Z1, Z6, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Z1, Z7, 0.00001f)) ? 0 : 1;
return Error;
}
}//namespace test_eulerAngleX
namespace test_eulerAngleY
{
int test()
{
int Error = 0;
float const Angle(glm::pi<float>() * 0.5f);
glm::vec3 const Y(0.0f, 1.0f, 0.0f);
glm::vec4 const X(1.0f, 0.0f, 0.0f, 1.0f);
glm::vec4 const X1 = glm::rotate(glm::mat4(1.0f), Angle, Y) * X;
glm::vec4 const X2 = glm::eulerAngleY(Angle) * X;
glm::vec4 const X3 = glm::eulerAngleYX(Angle, 0.0f) * X;
glm::vec4 const X4 = glm::eulerAngleXY(0.0f, Angle) * X;
glm::vec4 const X5 = glm::eulerAngleYZ(Angle, 0.0f) * X;
glm::vec4 const X6 = glm::eulerAngleZY(0.0f, Angle) * X;
glm::vec4 const X7 = glm::eulerAngleYXZ(Angle, 0.0f, 0.0f) * X;
Error += glm::all(glm::epsilonEqual(X1, X2, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(X1, X3, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(X1, X4, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(X1, X5, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(X1, X6, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(X1, X7, 0.00001f)) ? 0 : 1;
glm::vec4 const Z(0.0f, 0.0f, 1.0f, 1.0f);
glm::vec4 const Z1 = glm::eulerAngleY(Angle) * Z;
glm::vec4 const Z2 = glm::rotate(glm::mat4(1.0f), Angle, Y) * Z;
glm::vec4 const Z3 = glm::eulerAngleYX(Angle, 0.0f) * Z;
glm::vec4 const Z4 = glm::eulerAngleXY(0.0f, Angle) * Z;
glm::vec4 const Z5 = glm::eulerAngleYZ(Angle, 0.0f) * Z;
glm::vec4 const Z6 = glm::eulerAngleZY(0.0f, Angle) * Z;
glm::vec4 const Z7 = glm::eulerAngleYXZ(Angle, 0.0f, 0.0f) * Z;
Error += glm::all(glm::epsilonEqual(Z1, Z2, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Z1, Z3, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Z1, Z4, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Z1, Z5, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Z1, Z6, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Z1, Z7, 0.00001f)) ? 0 : 1;
return Error;
}
}//namespace test_eulerAngleY
namespace test_eulerAngleZ
{
int test()
{
int Error = 0;
float const Angle(glm::pi<float>() * 0.5f);
glm::vec3 const Z(0.0f, 0.0f, 1.0f);
glm::vec4 const X(1.0f, 0.0f, 0.0f, 1.0f);
glm::vec4 const X1 = glm::rotate(glm::mat4(1.0f), Angle, Z) * X;
glm::vec4 const X2 = glm::eulerAngleZ(Angle) * X;
glm::vec4 const X3 = glm::eulerAngleZX(Angle, 0.0f) * X;
glm::vec4 const X4 = glm::eulerAngleXZ(0.0f, Angle) * X;
glm::vec4 const X5 = glm::eulerAngleZY(Angle, 0.0f) * X;
glm::vec4 const X6 = glm::eulerAngleYZ(0.0f, Angle) * X;
glm::vec4 const X7 = glm::eulerAngleYXZ(0.0f, 0.0f, Angle) * X;
Error += glm::all(glm::epsilonEqual(X1, X2, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(X1, X3, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(X1, X4, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(X1, X5, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(X1, X6, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(X1, X7, 0.00001f)) ? 0 : 1;
glm::vec4 const Y(1.0f, 0.0f, 0.0f, 1.0f);
glm::vec4 const Z1 = glm::rotate(glm::mat4(1.0f), Angle, Z) * Y;
glm::vec4 const Z2 = glm::eulerAngleZ(Angle) * Y;
glm::vec4 const Z3 = glm::eulerAngleZX(Angle, 0.0f) * Y;
glm::vec4 const Z4 = glm::eulerAngleXZ(0.0f, Angle) * Y;
glm::vec4 const Z5 = glm::eulerAngleZY(Angle, 0.0f) * Y;
glm::vec4 const Z6 = glm::eulerAngleYZ(0.0f, Angle) * Y;
glm::vec4 const Z7 = glm::eulerAngleYXZ(0.0f, 0.0f, Angle) * Y;
Error += glm::all(glm::epsilonEqual(Z1, Z2, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Z1, Z3, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Z1, Z4, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Z1, Z5, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Z1, Z6, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(Z1, Z7, 0.00001f)) ? 0 : 1;
return Error;
}
}//namespace test_eulerAngleZ
namespace test_derivedEulerAngles
{
bool epsilonEqual(glm::mat4 const& mat1, glm::mat4 const& mat2, glm::mat4::value_type const& epsilon)
{
return glm::all(glm::epsilonEqual(mat1[0], mat2[0], epsilon)) ?
(
glm::all(glm::epsilonEqual(mat1[1], mat2[1], epsilon)) ?
(
glm::all(glm::epsilonEqual(mat1[2], mat2[2], epsilon)) ?
(
glm::all(glm::epsilonEqual(mat1[3], mat2[3], epsilon)) ? true : false
) : false
) : false
) : false;
}
template<typename RotationFunc, typename TestDerivedFunc>
int test(RotationFunc rotationFunc, TestDerivedFunc testDerivedFunc, const glm::vec3& basis)
{
int Error = 0;
typedef glm::vec3::value_type value;
value const zeroAngle(0.0f);
value const Angle(glm::pi<float>() * 0.75f);
value const negativeAngle(-Angle);
value const zeroAngleVelocity(0.0f);
value const AngleVelocity(glm::pi<float>() * 0.27f);
value const negativeAngleVelocity(-AngleVelocity);
typedef std::pair<value,value> AngleAndAngleVelocity;
std::vector<AngleAndAngleVelocity> testPairs;
testPairs.push_back(AngleAndAngleVelocity(zeroAngle, zeroAngleVelocity));
testPairs.push_back(AngleAndAngleVelocity(zeroAngle, AngleVelocity));
testPairs.push_back(AngleAndAngleVelocity(zeroAngle, negativeAngleVelocity));
testPairs.push_back(AngleAndAngleVelocity(Angle, zeroAngleVelocity));
testPairs.push_back(AngleAndAngleVelocity(Angle, AngleVelocity));
testPairs.push_back(AngleAndAngleVelocity(Angle, negativeAngleVelocity));
testPairs.push_back(AngleAndAngleVelocity(negativeAngle, zeroAngleVelocity));
testPairs.push_back(AngleAndAngleVelocity(negativeAngle, AngleVelocity));
testPairs.push_back(AngleAndAngleVelocity(negativeAngle, negativeAngleVelocity));
for (size_t i = 0, size = testPairs.size(); i < size; ++i)
{
AngleAndAngleVelocity const& pair = testPairs.at(i);
glm::mat4 const W = glm::matrixCross4(basis * pair.second);
glm::mat4 const rotMt = glm::transpose(rotationFunc(pair.first));
glm::mat4 const derivedRotM = testDerivedFunc(pair.first, pair.second);
Error += epsilonEqual(W, derivedRotM * rotMt, 0.00001f) ? 0 : 1;
}
return Error;
}
}//namespace test_derivedEulerAngles
namespace test_eulerAngleXY
{
int test()
{
int Error = 0;
glm::vec4 const V(1.0f);
float const AngleX(glm::pi<float>() * 0.5f);
float const AngleY(glm::pi<float>() * 0.25f);
glm::vec3 const axisX(1.0f, 0.0f, 0.0f);
glm::vec3 const axisY(0.0f, 1.0f, 0.0f);
glm::vec4 const V1 = (glm::rotate(glm::mat4(1.0f), AngleX, axisX) * glm::rotate(glm::mat4(1.0f), AngleY, axisY)) * V;
glm::vec4 const V2 = glm::eulerAngleXY(AngleX, AngleY) * V;
glm::vec4 const V3 = glm::eulerAngleX(AngleX) * glm::eulerAngleY(AngleY) * V;
Error += glm::all(glm::epsilonEqual(V1, V2, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(V1, V3, 0.00001f)) ? 0 : 1;
return Error;
}
}//namespace test_eulerAngleXY
namespace test_eulerAngleYX
{
int test()
{
int Error = 0;
glm::vec4 const V(1.0f);
float const AngleX(glm::pi<float>() * 0.5f);
float const AngleY(glm::pi<float>() * 0.25f);
glm::vec3 const axisX(1.0f, 0.0f, 0.0f);
glm::vec3 const axisY(0.0f, 1.0f, 0.0f);
glm::vec4 const V1 = (glm::rotate(glm::mat4(1.0f), AngleY, axisY) * glm::rotate(glm::mat4(1.0f), AngleX, axisX)) * V;
glm::vec4 const V2 = glm::eulerAngleYX(AngleY, AngleX) * V;
glm::vec4 const V3 = glm::eulerAngleY(AngleY) * glm::eulerAngleX(AngleX) * V;
Error += glm::all(glm::epsilonEqual(V1, V2, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(V1, V3, 0.00001f)) ? 0 : 1;
return Error;
}
}//namespace test_eulerAngleYX
namespace test_eulerAngleXZ
{
int test()
{
int Error = 0;
glm::vec4 const V(1.0f);
float const AngleX(glm::pi<float>() * 0.5f);
float const AngleZ(glm::pi<float>() * 0.25f);
glm::vec3 const axisX(1.0f, 0.0f, 0.0f);
glm::vec3 const axisZ(0.0f, 0.0f, 1.0f);
glm::vec4 const V1 = (glm::rotate(glm::mat4(1.0f), AngleX, axisX) * glm::rotate(glm::mat4(1.0f), AngleZ, axisZ)) * V;
glm::vec4 const V2 = glm::eulerAngleXZ(AngleX, AngleZ) * V;
glm::vec4 const V3 = glm::eulerAngleX(AngleX) * glm::eulerAngleZ(AngleZ) * V;
Error += glm::all(glm::epsilonEqual(V1, V2, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(V1, V3, 0.00001f)) ? 0 : 1;
return Error;
}
}//namespace test_eulerAngleXZ
namespace test_eulerAngleZX
{
int test()
{
int Error = 0;
glm::vec4 const V(1.0f);
float const AngleX(glm::pi<float>() * 0.5f);
float const AngleZ(glm::pi<float>() * 0.25f);
glm::vec3 const axisX(1.0f, 0.0f, 0.0f);
glm::vec3 const axisZ(0.0f, 0.0f, 1.0f);
glm::vec4 const V1 = (glm::rotate(glm::mat4(1.0f), AngleZ, axisZ) * glm::rotate(glm::mat4(1.0f), AngleX, axisX)) * V;
glm::vec4 const V2 = glm::eulerAngleZX(AngleZ, AngleX) * V;
glm::vec4 const V3 = glm::eulerAngleZ(AngleZ) * glm::eulerAngleX(AngleX) * V;
Error += glm::all(glm::epsilonEqual(V1, V2, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(V1, V3, 0.00001f)) ? 0 : 1;
return Error;
}
}//namespace test_eulerAngleZX
namespace test_eulerAngleYZ
{
int test()
{
int Error = 0;
glm::vec4 const V(1.0f);
float const AngleY(glm::pi<float>() * 0.5f);
float const AngleZ(glm::pi<float>() * 0.25f);
glm::vec3 const axisX(1.0f, 0.0f, 0.0f);
glm::vec3 const axisY(0.0f, 1.0f, 0.0f);
glm::vec3 const axisZ(0.0f, 0.0f, 1.0f);
glm::vec4 const V1 = (glm::rotate(glm::mat4(1.0f), AngleY, axisY) * glm::rotate(glm::mat4(1.0f), AngleZ, axisZ)) * V;
glm::vec4 const V2 = glm::eulerAngleYZ(AngleY, AngleZ) * V;
glm::vec4 const V3 = glm::eulerAngleY(AngleY) * glm::eulerAngleZ(AngleZ) * V;
Error += glm::all(glm::epsilonEqual(V1, V2, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(V1, V3, 0.00001f)) ? 0 : 1;
return Error;
}
}//namespace test_eulerAngleYZ
namespace test_eulerAngleZY
{
int test()
{
int Error = 0;
glm::vec4 const V(1.0f);
float const AngleY(glm::pi<float>() * 0.5f);
float const AngleZ(glm::pi<float>() * 0.25f);
glm::vec3 const axisX(1.0f, 0.0f, 0.0f);
glm::vec3 const axisY(0.0f, 1.0f, 0.0f);
glm::vec3 const axisZ(0.0f, 0.0f, 1.0f);
glm::vec4 const V1 = (glm::rotate(glm::mat4(1.0f), AngleZ, axisZ) * glm::rotate(glm::mat4(1.0f), AngleY, axisY)) * V;
glm::vec4 const V2 = glm::eulerAngleZY(AngleZ, AngleY) * V;
glm::vec4 const V3 = glm::eulerAngleZ(AngleZ) * glm::eulerAngleY(AngleY) * V;
Error += glm::all(glm::epsilonEqual(V1, V2, 0.00001f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(V1, V3, 0.00001f)) ? 0 : 1;
return Error;
}
}//namespace test_eulerAngleZY
namespace test_eulerAngleYXZ
{
int test()
{
glm::f32 first = 1.046f;
glm::f32 second = 0.52f;
glm::f32 third = -0.785f;
glm::fmat4 rotationEuler = glm::eulerAngleYXZ(first, second, third);
glm::fmat4 rotationInvertedY = glm::eulerAngleY(-1.f*first) * glm::eulerAngleX(second) * glm::eulerAngleZ(third);
glm::fmat4 rotationDumb = glm::fmat4();
rotationDumb = glm::rotate(rotationDumb, first, glm::fvec3(0,1,0));
rotationDumb = glm::rotate(rotationDumb, second, glm::fvec3(1,0,0));
rotationDumb = glm::rotate(rotationDumb, third, glm::fvec3(0,0,1));
std::printf("%s\n", glm::to_string(glm::fmat3(rotationEuler)).c_str());
std::printf("%s\n", glm::to_string(glm::fmat3(rotationDumb)).c_str());
std::printf("%s\n", glm::to_string(glm::fmat3(rotationInvertedY)).c_str());
std::printf("\nRESIDUAL\n");
std::printf("%s\n", glm::to_string(glm::fmat3(rotationEuler-(rotationDumb))).c_str());
std::printf("%s\n", glm::to_string(glm::fmat3(rotationEuler-(rotationInvertedY))).c_str());
return 0;
}
}//namespace eulerAngleYXZ
namespace test_eulerAngles
{
template<typename TestRotationFunc>
int test(TestRotationFunc testRotationFunc, glm::vec3 const& I, glm::vec3 const& J, glm::vec3 const& K)
{
int Error = 0;
typedef glm::mat4::value_type value;
value const minAngle(-glm::pi<value>());
value const maxAngle(glm::pi<value>());
value const maxAngleWithDelta(maxAngle - 0.0000001f);
value const minMidAngle(-glm::pi<value>() * 0.5f);
value const maxMidAngle(glm::pi<value>() * 0.5f);
std::vector<glm::vec3> testEulerAngles;
testEulerAngles.push_back(glm::vec3(1.046f, 0.52f, -0.785f));
testEulerAngles.push_back(glm::vec3(minAngle, minMidAngle, minAngle));
testEulerAngles.push_back(glm::vec3(minAngle, minMidAngle, maxAngle));
testEulerAngles.push_back(glm::vec3(minAngle, minMidAngle, maxAngleWithDelta));
testEulerAngles.push_back(glm::vec3(minAngle, maxMidAngle, minAngle));
testEulerAngles.push_back(glm::vec3(minAngle, maxMidAngle, maxAngle));
testEulerAngles.push_back(glm::vec3(minAngle, maxMidAngle, maxAngleWithDelta));
testEulerAngles.push_back(glm::vec3(maxAngle, minMidAngle, minAngle));
testEulerAngles.push_back(glm::vec3(maxAngle, minMidAngle, maxAngle));
testEulerAngles.push_back(glm::vec3(maxAngle, minMidAngle, maxAngleWithDelta));
testEulerAngles.push_back(glm::vec3(maxAngleWithDelta, minMidAngle, maxAngle));
testEulerAngles.push_back(glm::vec3(maxAngleWithDelta, minMidAngle, maxAngleWithDelta));
testEulerAngles.push_back(glm::vec3(maxAngle, maxMidAngle, minAngle));
testEulerAngles.push_back(glm::vec3(maxAngleWithDelta, maxMidAngle, minAngle));
testEulerAngles.push_back(glm::vec3(maxAngle, maxMidAngle, maxAngle));
testEulerAngles.push_back(glm::vec3(maxAngle, maxMidAngle, maxAngleWithDelta));
testEulerAngles.push_back(glm::vec3(maxAngleWithDelta, maxMidAngle, maxAngle));
testEulerAngles.push_back(glm::vec3(maxAngleWithDelta, maxMidAngle, maxAngleWithDelta));
testEulerAngles.push_back(glm::vec3(minAngle, 0.0f, minAngle));
testEulerAngles.push_back(glm::vec3(minAngle, 0.0f, maxAngle));
testEulerAngles.push_back(glm::vec3(maxAngle, maxAngle, minAngle));
testEulerAngles.push_back(glm::vec3(maxAngle, maxAngle, maxAngle));
for (size_t i = 0, size = testEulerAngles.size(); i < size; ++i)
{
glm::vec3 const& angles = testEulerAngles.at(i);
glm::mat4 const rotationEuler = testRotationFunc(angles.x, angles.y, angles.z);
glm::mat4 rotationDumb = glm::diagonal4x4(glm::mat4::col_type(1.0f));
rotationDumb = glm::rotate(rotationDumb, angles.x, I);
rotationDumb = glm::rotate(rotationDumb, angles.y, J);
rotationDumb = glm::rotate(rotationDumb, angles.z, K);
glm::vec4 const V(1.0f,1.0f,1.0f,1.0f);
glm::vec4 const V1 = rotationEuler * V;
glm::vec4 const V2 = rotationDumb * V;
Error += glm::all(glm::epsilonEqual(V1, V2, 0.00001f)) ? 0 : 1;
}
return Error;
}
}//namespace test_extractsEulerAngles
namespace test_extractsEulerAngles
{
template<typename RotationFunc, typename TestExtractionFunc>
int test(RotationFunc rotationFunc, TestExtractionFunc testExtractionFunc)
{
int Error = 0;
typedef glm::mat4::value_type value;
value const minAngle(-glm::pi<value>());
value const maxAngle(glm::pi<value>());
value const maxAngleWithDelta(maxAngle - 0.0000001f);
value const minMidAngle(-glm::pi<value>() * 0.5f);
value const maxMidAngle(glm::pi<value>() * 0.5f);
std::vector<glm::vec3> testEulerAngles;
testEulerAngles.push_back(glm::vec3(1.046f, 0.52f, -0.785f));
testEulerAngles.push_back(glm::vec3(minAngle, minMidAngle, minAngle));
testEulerAngles.push_back(glm::vec3(minAngle, minMidAngle, maxAngle));
testEulerAngles.push_back(glm::vec3(minAngle, minMidAngle, maxAngleWithDelta));
testEulerAngles.push_back(glm::vec3(minAngle, maxMidAngle, minAngle));
testEulerAngles.push_back(glm::vec3(minAngle, maxMidAngle, maxAngle));
testEulerAngles.push_back(glm::vec3(minAngle, maxMidAngle, maxAngleWithDelta));
testEulerAngles.push_back(glm::vec3(maxAngle, minMidAngle, minAngle));
testEulerAngles.push_back(glm::vec3(maxAngle, minMidAngle, maxAngle));
testEulerAngles.push_back(glm::vec3(maxAngle, minMidAngle, maxAngleWithDelta));
testEulerAngles.push_back(glm::vec3(maxAngleWithDelta, minMidAngle, maxAngle));
testEulerAngles.push_back(glm::vec3(maxAngleWithDelta, minMidAngle, maxAngleWithDelta));
testEulerAngles.push_back(glm::vec3(maxAngle, maxMidAngle, minAngle));
testEulerAngles.push_back(glm::vec3(maxAngleWithDelta, maxMidAngle, minAngle));
testEulerAngles.push_back(glm::vec3(maxAngle, maxMidAngle, maxAngle));
testEulerAngles.push_back(glm::vec3(maxAngle, maxMidAngle, maxAngleWithDelta));
testEulerAngles.push_back(glm::vec3(maxAngleWithDelta, maxMidAngle, maxAngle));
testEulerAngles.push_back(glm::vec3(maxAngleWithDelta, maxMidAngle, maxAngleWithDelta));
testEulerAngles.push_back(glm::vec3(minAngle, 0.0f, minAngle));
testEulerAngles.push_back(glm::vec3(minAngle, 0.0f, maxAngle));
testEulerAngles.push_back(glm::vec3(maxAngle, maxAngle, minAngle));
testEulerAngles.push_back(glm::vec3(maxAngle, maxAngle, maxAngle));
for (size_t i = 0, size = testEulerAngles.size(); i < size; ++i)
{
glm::vec3 const& angles = testEulerAngles.at(i);
glm::mat4 const rotation = rotationFunc(angles.x, angles.y, angles.z);
glm::vec3 extractedEulerAngles(0.0f);
testExtractionFunc(rotation, extractedEulerAngles.x, extractedEulerAngles.y, extractedEulerAngles.z);
glm::mat4 const extractedRotation = rotationFunc(extractedEulerAngles.x, extractedEulerAngles.y, extractedEulerAngles.z);
glm::vec4 const V(1.0f,1.0f,1.0f,1.0f);
glm::vec4 const V1 = rotation * V;
glm::vec4 const V2 = extractedRotation * V;
Error += glm::all(glm::epsilonEqual(V1, V2, 0.00001f)) ? 0 : 1;
}
return Error;
}
}//namespace test_extractsEulerAngles
int main()
{
int Error = 0;
typedef glm::mat4::value_type value;
glm::vec3 const X(1.0f, 0.0f, 0.0f);
glm::vec3 const Y(0.0f, 1.0f, 0.0f);
glm::vec3 const Z(0.0f, 0.0f, 1.0f);
Error += test_eulerAngleX::test();
Error += test_eulerAngleY::test();
Error += test_eulerAngleZ::test();
Error += test_derivedEulerAngles::test(glm::eulerAngleX<value>, glm::derivedEulerAngleX<value>, X);
Error += test_derivedEulerAngles::test(glm::eulerAngleY<value>, glm::derivedEulerAngleY<value>, Y);
Error += test_derivedEulerAngles::test(glm::eulerAngleZ<value>, glm::derivedEulerAngleZ<value>, Z);
Error += test_eulerAngleXY::test();
Error += test_eulerAngleYX::test();
Error += test_eulerAngleXZ::test();
Error += test_eulerAngleZX::test();
Error += test_eulerAngleYZ::test();
Error += test_eulerAngleZY::test();
Error += test_eulerAngleYXZ::test();
Error += test_eulerAngles::test(glm::eulerAngleXZX<value>, X, Z, X);
Error += test_eulerAngles::test(glm::eulerAngleXYX<value>, X, Y, X);
Error += test_eulerAngles::test(glm::eulerAngleYXY<value>, Y, X, Y);
Error += test_eulerAngles::test(glm::eulerAngleYZY<value>, Y, Z, Y);
Error += test_eulerAngles::test(glm::eulerAngleZYZ<value>, Z, Y, Z);
Error += test_eulerAngles::test(glm::eulerAngleZXZ<value>, Z, X, Z);
Error += test_eulerAngles::test(glm::eulerAngleXZY<value>, X, Z, Y);
Error += test_eulerAngles::test(glm::eulerAngleYZX<value>, Y, Z, X);
Error += test_eulerAngles::test(glm::eulerAngleZYX<value>, Z, Y, X);
Error += test_eulerAngles::test(glm::eulerAngleZXY<value>, Z, X, Y);
Error += test_extractsEulerAngles::test(glm::eulerAngleYXZ<value>, glm::extractEulerAngleYXZ<value>);
Error += test_extractsEulerAngles::test(glm::eulerAngleXZX<value>, glm::extractEulerAngleXZX<value>);
Error += test_extractsEulerAngles::test(glm::eulerAngleXYX<value>, glm::extractEulerAngleXYX<value>);
Error += test_extractsEulerAngles::test(glm::eulerAngleYXY<value>, glm::extractEulerAngleYXY<value>);
Error += test_extractsEulerAngles::test(glm::eulerAngleYZY<value>, glm::extractEulerAngleYZY<value>);
Error += test_extractsEulerAngles::test(glm::eulerAngleZYZ<value>, glm::extractEulerAngleZYZ<value>);
Error += test_extractsEulerAngles::test(glm::eulerAngleZXZ<value>, glm::extractEulerAngleZXZ<value>);
Error += test_extractsEulerAngles::test(glm::eulerAngleXZY<value>, glm::extractEulerAngleXZY<value>);
Error += test_extractsEulerAngles::test(glm::eulerAngleYZX<value>, glm::extractEulerAngleYZX<value>);
Error += test_extractsEulerAngles::test(glm::eulerAngleZYX<value>, glm::extractEulerAngleZYX<value>);
Error += test_extractsEulerAngles::test(glm::eulerAngleZXY<value>, glm::extractEulerAngleZXY<value>);
return Error;
}

View File

@@ -0,0 +1,9 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/extend.hpp>
int main()
{
int Error(0);
return Error;
}

View File

@@ -0,0 +1,101 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/extended_min_max.hpp>
#include <glm/gtc/vec1.hpp>
#include <glm/gtc/constants.hpp>
#include <glm/ext/scalar_relational.hpp>
#include <glm/ext/vector_relational.hpp>
// This file has divisions by zero to test isnan
#if GLM_COMPILER & GLM_COMPILER_VC
# pragma warning(disable : 4723)
#endif
namespace fmin_
{
static int test()
{
int Error = 0;
float Zero_f = 0.0f;
glm::vec1 A0 = glm::fmin(glm::vec1(1), glm::vec1(Zero_f / 0.0f));
Error += glm::equal(A0.x, 1.0f, glm::epsilon<float>()) ? 0 : 1;
glm::vec1 A1 = glm::fmin(glm::vec1(Zero_f / 0.0f), glm::vec1(1));
Error += glm::equal(A1.x, 1.0f, glm::epsilon<float>()) ? 0 : 1;
glm::vec2 B0 = glm::fmin(glm::vec2(1), glm::vec2(1));
glm::vec2 B1 = glm::fmin(glm::vec2(1), 1.0f);
bool B2 = glm::all(glm::equal(B0, B1, glm::epsilon<float>()));
Error += B2 ? 0 : 1;
glm::vec3 C0 = glm::fmin(glm::vec3(1), glm::vec3(1));
glm::vec3 C1 = glm::fmin(glm::vec3(1), 1.0f);
bool C2 = glm::all(glm::equal(C0, C1, glm::epsilon<float>()));
Error += C2 ? 0 : 1;
glm::vec4 D0 = glm::fmin(glm::vec4(1), glm::vec4(1));
glm::vec4 D1 = glm::fmin(glm::vec4(1), 1.0f);
bool D2 = glm::all(glm::equal(D0, D1, glm::epsilon<float>()));
Error += D2 ? 0 : 1;
return Error;
}
}//namespace fmin_
namespace fmax_
{
static int test()
{
int Error = 0;
float Zero_f = 0.0f;
glm::vec1 A0 = glm::fmax(glm::vec1(1), glm::vec1(Zero_f / 0.0f));
Error += glm::equal(A0.x, 1.0f, glm::epsilon<float>()) ? 0 : 1;
glm::vec1 A1 = glm::fmax(glm::vec1(Zero_f / 0.0f), glm::vec1(1));
Error += glm::equal(A0.x, 1.0f, glm::epsilon<float>()) ? 0 : 1;
glm::vec2 B0 = glm::fmax(glm::vec2(1), glm::vec2(1));
glm::vec2 B1 = glm::fmax(glm::vec2(1), 1.0f);
bool B2 = glm::all(glm::equal(B0, B1, glm::epsilon<float>()));
Error += B2 ? 0 : 1;
glm::vec3 C0 = glm::fmax(glm::vec3(1), glm::vec3(1));
glm::vec3 C1 = glm::fmax(glm::vec3(1), 1.0f);
bool C2 = glm::all(glm::equal(C0, C1, glm::epsilon<float>()));
Error += C2 ? 0 : 1;
glm::vec4 D0 = glm::fmax(glm::vec4(1), glm::vec4(1));
glm::vec4 D1 = glm::fmax(glm::vec4(1), 1.0f);
bool D2 = glm::all(glm::equal(D0, D1, glm::epsilon<float>()));
Error += D2 ? 0 : 1;
return Error;
}
}//namespace fmax_
namespace fclamp_
{
static int test()
{
int Error = 0;
float Zero_f = 0.0f;
glm::vec1 A0 = glm::fclamp(glm::vec1(1), glm::vec1(Zero_f / 0.0f), glm::vec1(2.0f));
Error += glm::equal(A0.x, 1.0f, glm::epsilon<float>()) ? 0 : 1;
return Error;
}
}//namespace fclamp_
int main()
{
int Error = 0;
Error += fmin_::test();
Error += fmax_::test();
Error += fclamp_::test();
return Error;
}

View File

@@ -0,0 +1,39 @@
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.g-truc.net)
///
/// Copyright (c) 2005 - 2015 G-Truc Creation (www.g-truc.net)
/// Permission is hereby granted, free of charge, to any person obtaining a copy
/// of this software and associated documentation files (the "Software"), to deal
/// in the Software without restriction, including without limitation the rights
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in
/// all copies or substantial portions of the Software.
///
/// Restrictions:
/// By making use of the Software for military purposes, you choose to make
/// a Bunny unhappy.
///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.
///
/// @file test/gtx/gtx_extented_min_max.cpp
/// @date 2013-10-25 / 2014-11-25
/// @author Christophe Riccio
///////////////////////////////////////////////////////////////////////////////////
#include <glm/gtx/extended_min_max.hpp>
int main()
{
int Error(0);
return Error;
}

View File

@@ -0,0 +1,14 @@
#include <glm/gtx/exterior_product.hpp>
#include <glm/gtc/epsilon.hpp>
#include <glm/vec2.hpp>
int main()
{
int Error = 0;
float const f = glm::cross(glm::vec2(1.0f, 1.0f), glm::vec2(1.0f, 1.0f));
Error += glm::epsilonEqual(f, 0.0f, 0.001f) ? 0 : 1;
return Error;
}

View File

@@ -0,0 +1,9 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/fast_exponential.hpp>
int main()
{
int Error(0);
return Error;
}

View File

@@ -0,0 +1,45 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/fast_square_root.hpp>
#include <glm/gtc/type_precision.hpp>
#include <glm/gtc/epsilon.hpp>
#include <glm/vector_relational.hpp>
int test_fastInverseSqrt()
{
int Error = 0;
Error += glm::epsilonEqual(glm::fastInverseSqrt(1.0f), 1.0f, 0.01f) ? 0 : 1;
Error += glm::epsilonEqual(glm::fastInverseSqrt(1.0), 1.0, 0.01) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(glm::fastInverseSqrt(glm::vec2(1.0f)), glm::vec2(1.0f), 0.01f)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(glm::fastInverseSqrt(glm::dvec3(1.0)), glm::dvec3(1.0), 0.01)) ? 0 : 1;
Error += glm::all(glm::epsilonEqual(glm::fastInverseSqrt(glm::dvec4(1.0)), glm::dvec4(1.0), 0.01)) ? 0 : 1;
return Error;
}
int test_fastDistance()
{
int Error = 0;
float const A = glm::fastDistance(0.0f, 1.0f);
float const B = glm::fastDistance(glm::vec2(0.0f), glm::vec2(1.0f, 0.0f));
float const C = glm::fastDistance(glm::vec3(0.0f), glm::vec3(1.0f, 0.0f, 0.0f));
float const D = glm::fastDistance(glm::vec4(0.0f), glm::vec4(1.0f, 0.0f, 0.0f, 0.0f));
Error += glm::epsilonEqual(A, 1.0f, 0.01f) ? 0 : 1;
Error += glm::epsilonEqual(B, 1.0f, 0.01f) ? 0 : 1;
Error += glm::epsilonEqual(C, 1.0f, 0.01f) ? 0 : 1;
Error += glm::epsilonEqual(D, 1.0f, 0.01f) ? 0 : 1;
return Error;
}
int main()
{
int Error = 0;
Error += test_fastInverseSqrt();
Error += test_fastDistance();
return Error;
}

View File

@@ -0,0 +1,564 @@
#include <glm/ext/scalar_ulp.hpp>
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtc/type_precision.hpp>
#include <glm/gtx/fast_trigonometry.hpp>
#include <glm/gtx/integer.hpp>
#include <glm/gtx/common.hpp>
#include <glm/gtc/constants.hpp>
#include <glm/gtc/vec1.hpp>
#include <glm/trigonometric.hpp>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
namespace fastCos
{
int perf(bool NextFloat)
{
const float begin = -glm::pi<float>();
const float end = glm::pi<float>();
float result = 0.f;
const std::clock_t timestamp1 = std::clock();
for(float i = begin; i < end; i = NextFloat ? glm::nextFloat(i) : i += 0.1f)
result = glm::fastCos(i);
const std::clock_t timestamp2 = std::clock();
for(float i = begin; i < end; i = NextFloat ? glm::nextFloat(i) : i += 0.1f)
result = glm::cos(i);
const std::clock_t timestamp3 = std::clock();
const std::clock_t time_fast = timestamp2 - timestamp1;
const std::clock_t time_default = timestamp3 - timestamp2;
std::printf("fastCos Time %d clocks\n", static_cast<int>(time_fast));
std::printf("cos Time %d clocks\n", static_cast<int>(time_default));
return time_fast <= time_default ? 0 : 1;
}
}//namespace fastCos
namespace fastSin
{
/*
float sin(float x) {
float temp;
temp = (x + M_PI) / ((2 * M_PI) - M_PI);
return limited_sin((x + M_PI) - ((2 * M_PI) - M_PI) * temp));
}
*/
int perf(bool NextFloat)
{
const float begin = -glm::pi<float>();
const float end = glm::pi<float>();
float result = 0.f;
const std::clock_t timestamp1 = std::clock();
for(float i = begin; i < end; i = NextFloat ? glm::nextFloat(i) : i += 0.1f)
result = glm::fastSin(i);
const std::clock_t timestamp2 = std::clock();
for(float i = begin; i < end; i = NextFloat ? glm::nextFloat(i) : i += 0.1f)
result = glm::sin(i);
const std::clock_t timestamp3 = std::clock();
const std::clock_t time_fast = timestamp2 - timestamp1;
const std::clock_t time_default = timestamp3 - timestamp2;
std::printf("fastSin Time %d clocks\n", static_cast<int>(time_fast));
std::printf("sin Time %d clocks\n", static_cast<int>(time_default));
return time_fast <= time_default ? 0 : 1;
}
}//namespace fastSin
namespace fastTan
{
int perf(bool NextFloat)
{
const float begin = -glm::pi<float>();
const float end = glm::pi<float>();
float result = 0.f;
const std::clock_t timestamp1 = std::clock();
for(float i = begin; i < end; i = NextFloat ? glm::nextFloat(i) : i += 0.1f)
result = glm::fastTan(i);
const std::clock_t timestamp2 = std::clock();
for (float i = begin; i < end; i = NextFloat ? glm::nextFloat(i) : i += 0.1f)
result = glm::tan(i);
const std::clock_t timestamp3 = std::clock();
const std::clock_t time_fast = timestamp2 - timestamp1;
const std::clock_t time_default = timestamp3 - timestamp2;
std::printf("fastTan Time %d clocks\n", static_cast<int>(time_fast));
std::printf("tan Time %d clocks\n", static_cast<int>(time_default));
return time_fast <= time_default ? 0 : 1;
}
}//namespace fastTan
namespace fastAcos
{
int perf(bool NextFloat)
{
const float begin = -glm::pi<float>();
const float end = glm::pi<float>();
float result = 0.f;
const std::clock_t timestamp1 = std::clock();
for(float i = begin; i < end; i = NextFloat ? glm::nextFloat(i) : i += 0.1f)
result = glm::fastAcos(i);
const std::clock_t timestamp2 = std::clock();
for(float i = begin; i < end; i = NextFloat ? glm::nextFloat(i) : i += 0.1f)
result = glm::acos(i);
const std::clock_t timestamp3 = std::clock();
const std::clock_t time_fast = timestamp2 - timestamp1;
const std::clock_t time_default = timestamp3 - timestamp2;
std::printf("fastAcos Time %d clocks\n", static_cast<int>(time_fast));
std::printf("acos Time %d clocks\n", static_cast<int>(time_default));
return time_fast <= time_default ? 0 : 1;
}
}//namespace fastAcos
namespace fastAsin
{
int perf(bool NextFloat)
{
const float begin = -glm::pi<float>();
const float end = glm::pi<float>();
float result = 0.f;
const std::clock_t timestamp1 = std::clock();
for(float i = begin; i < end; i = NextFloat ? glm::nextFloat(i) : i += 0.1f)
result = glm::fastAsin(i);
const std::clock_t timestamp2 = std::clock();
for(float i = begin; i < end; i = NextFloat ? glm::nextFloat(i) : i += 0.1f)
result = glm::asin(i);
const std::clock_t timestamp3 = std::clock();
const std::clock_t time_fast = timestamp2 - timestamp1;
const std::clock_t time_default = timestamp3 - timestamp2;
std::printf("fastAsin Time %d clocks\n", static_cast<int>(time_fast));
std::printf("asin Time %d clocks\n", static_cast<int>(time_default));
return time_fast <= time_default ? 0 : 1;
}
}//namespace fastAsin
namespace fastAtan
{
int perf(bool NextFloat)
{
const float begin = -glm::pi<float>();
const float end = glm::pi<float>();
float result = 0.f;
const std::clock_t timestamp1 = std::clock();
for(float i = begin; i < end; i = NextFloat ? glm::nextFloat(i) : i += 0.1f)
result = glm::fastAtan(i);
const std::clock_t timestamp2 = std::clock();
for(float i = begin; i < end; i = NextFloat ? glm::nextFloat(i) : i += 0.1f)
result = glm::atan(i);
const std::clock_t timestamp3 = std::clock();
const std::clock_t time_fast = timestamp2 - timestamp1;
const std::clock_t time_default = timestamp3 - timestamp2;
std::printf("fastAtan Time %d clocks\n", static_cast<int>(time_fast));
std::printf("atan Time %d clocks\n", static_cast<int>(time_default));
return time_fast <= time_default ? 0 : 1;
}
}//namespace fastAtan
namespace taylorCos
{
using glm::qualifier;
using glm::length_t;
glm::vec4 const AngleShift(0.0f, glm::half_pi<float>(), glm::pi<float>(), glm::three_over_two_pi<float>());
template<length_t L, typename T, qualifier Q>
GLM_FUNC_QUALIFIER glm::vec<L, T, Q> taylorSeriesNewCos(glm::vec<L, T, Q> const& x)
{
glm::vec<L, T, Q> const Powed2(x * x);
glm::vec<L, T, Q> const Powed4(Powed2 * Powed2);
glm::vec<L, T, Q> const Powed6(Powed4 * Powed2);
glm::vec<L, T, Q> const Powed8(Powed4 * Powed4);
return static_cast<T>(1)
- Powed2 * static_cast<T>(0.5)
+ Powed4 * static_cast<T>(0.04166666666666666666666666666667)
- Powed6 * static_cast<T>(0.00138888888888888888888888888889)
+ Powed8 * static_cast<T>(2.4801587301587301587301587301587e-5);
}
template<length_t L, typename T, qualifier Q>
GLM_FUNC_QUALIFIER glm::vec<L, T, Q> taylorSeriesNewCos6(glm::vec<L, T, Q> const& x)
{
glm::vec<L, T, Q> const Powed2(x * x);
glm::vec<L, T, Q> const Powed4(Powed2 * Powed2);
glm::vec<L, T, Q> const Powed6(Powed4 * Powed2);
return static_cast<T>(1)
- Powed2 * static_cast<T>(0.5)
+ Powed4 * static_cast<T>(0.04166666666666666666666666666667)
- Powed6 * static_cast<T>(0.00138888888888888888888888888889);
}
template<glm::length_t L, qualifier Q>
GLM_FUNC_QUALIFIER glm::vec<L, float, Q> fastAbs(glm::vec<L, float, Q> x)
{
int* Pointer = reinterpret_cast<int*>(&x[0]);
Pointer[0] &= 0x7fffffff;
Pointer[1] &= 0x7fffffff;
Pointer[2] &= 0x7fffffff;
Pointer[3] &= 0x7fffffff;
return x;
}
template<glm::length_t L, typename T, qualifier Q>
GLM_FUNC_QUALIFIER glm::vec<L, T, Q> fastCosNew(glm::vec<L, T, Q> const& x)
{
glm::vec<L, T, Q> const Angle0_PI(fastAbs(fmod(x + glm::pi<T>(), glm::two_pi<T>()) - glm::pi<T>()));
return taylorSeriesNewCos6(x);
/*
vec<L, bool, Q> const FirstQuarterPi(lessThanEqual(Angle0_PI, vec<L, T, Q>(glm::half_pi<T>())));
vec<L, T, Q> const RevertAngle(mix(vec<L, T, Q>(glm::pi<T>()), vec<L, T, Q>(0), FirstQuarterPi));
vec<L, T, Q> const ReturnSign(mix(vec<L, T, Q>(-1), vec<L, T, Q>(1), FirstQuarterPi));
vec<L, T, Q> const SectionAngle(RevertAngle - Angle0_PI);
return ReturnSign * taylorSeriesNewCos(SectionAngle);
*/
}
int perf_fastCosNew(float Begin, float End, std::size_t Samples)
{
std::vector<glm::vec4> Results;
Results.resize(Samples);
float const Steps = (End - Begin) / static_cast<float>(Samples);
std::clock_t const TimeStampBegin = std::clock();
for(std::size_t i = 0; i < Samples; ++i)
Results[i] = fastCosNew(AngleShift + glm::vec4(Begin + Steps * static_cast<float>(i)));
std::clock_t const TimeStampEnd = std::clock();
std::printf("fastCosNew %d clocks\n", static_cast<int>(TimeStampEnd - TimeStampBegin));
int Error = 0;
for(std::size_t i = 0; i < Samples; ++i)
Error += Results[i].x >= -1.0f && Results[i].x <= 1.0f ? 0 : 1;
return Error;
}
template<length_t L, typename T, qualifier Q>
GLM_FUNC_QUALIFIER glm::vec<L, T, Q> deterministic_fmod(glm::vec<L, T, Q> const& x, T y)
{
return x - y * trunc(x / y);
}
template<length_t L, typename T, qualifier Q>
GLM_FUNC_QUALIFIER glm::vec<L, T, Q> fastCosDeterminisctic(glm::vec<L, T, Q> const& x)
{
glm::vec<L, T, Q> const Angle0_PI(abs(deterministic_fmod(x + glm::pi<T>(), glm::two_pi<T>()) - glm::pi<T>()));
glm::vec<L, bool, Q> const FirstQuarterPi(lessThanEqual(Angle0_PI, glm::vec<L, T, Q>(glm::half_pi<T>())));
glm::vec<L, T, Q> const RevertAngle(mix(glm::vec<L, T, Q>(glm::pi<T>()), glm::vec<L, T, Q>(0), FirstQuarterPi));
glm::vec<L, T, Q> const ReturnSign(mix(glm::vec<L, T, Q>(-1), glm::vec<L, T, Q>(1), FirstQuarterPi));
glm::vec<L, T, Q> const SectionAngle(RevertAngle - Angle0_PI);
return ReturnSign * taylorSeriesNewCos(SectionAngle);
}
int perf_fastCosDeterminisctic(float Begin, float End, std::size_t Samples)
{
std::vector<glm::vec4> Results;
Results.resize(Samples);
float const Steps = (End - Begin) / static_cast<float>(Samples);
std::clock_t const TimeStampBegin = std::clock();
for(std::size_t i = 0; i < Samples; ++i)
Results[i] = taylorCos::fastCosDeterminisctic(AngleShift + glm::vec4(Begin + Steps * static_cast<float>(i)));
std::clock_t const TimeStampEnd = std::clock();
std::printf("fastCosDeterminisctic %d clocks\n", static_cast<int>(TimeStampEnd - TimeStampBegin));
int Error = 0;
for(std::size_t i = 0; i < Samples; ++i)
Error += Results[i].x >= -1.0f && Results[i].x <= 1.0f ? 0 : 1;
return Error;
}
template<length_t L, typename T, qualifier Q>
GLM_FUNC_QUALIFIER glm::vec<L, T, Q> taylorSeriesRefCos(glm::vec<L, T, Q> const& x)
{
return static_cast<T>(1)
- (x * x) / glm::factorial(static_cast<T>(2))
+ (x * x * x * x) / glm::factorial(static_cast<T>(4))
- (x * x * x * x * x * x) / glm::factorial(static_cast<T>(6))
+ (x * x * x * x * x * x * x * x) / glm::factorial(static_cast<T>(8));
}
template<length_t L, typename T, qualifier Q>
GLM_FUNC_QUALIFIER glm::vec<L, T, Q> fastRefCos(glm::vec<L, T, Q> const& x)
{
glm::vec<L, T, Q> const Angle0_PI(glm::abs(fmod(x + glm::pi<T>(), glm::two_pi<T>()) - glm::pi<T>()));
// return taylorSeriesRefCos(Angle0_PI);
glm::vec<L, bool, Q> const FirstQuarterPi(lessThanEqual(Angle0_PI, glm::vec<L, T, Q>(glm::half_pi<T>())));
glm::vec<L, T, Q> const RevertAngle(mix(glm::vec<L, T, Q>(glm::pi<T>()), glm::vec<L, T, Q>(0), FirstQuarterPi));
glm::vec<L, T, Q> const ReturnSign(mix(glm::vec<L, T, Q>(-1), glm::vec<L, T, Q>(1), FirstQuarterPi));
glm::vec<L, T, Q> const SectionAngle(RevertAngle - Angle0_PI);
return ReturnSign * taylorSeriesRefCos(SectionAngle);
}
int perf_fastCosRef(float Begin, float End, std::size_t Samples)
{
std::vector<glm::vec4> Results;
Results.resize(Samples);
float const Steps = (End - Begin) / static_cast<float>(Samples);
std::clock_t const TimeStampBegin = std::clock();
for(std::size_t i = 0; i < Samples; ++i)
Results[i] = taylorCos::fastRefCos(AngleShift + glm::vec4(Begin + Steps * static_cast<float>(i)));
std::clock_t const TimeStampEnd = std::clock();
std::printf("fastCosRef %d clocks\n", static_cast<int>(TimeStampEnd - TimeStampBegin));
int Error = 0;
for(std::size_t i = 0; i < Samples; ++i)
Error += Results[i].x >= -1.0f && Results[i].x <= 1.0f ? 0 : 1;
return Error;
}
int perf_fastCosOld(float Begin, float End, std::size_t Samples)
{
std::vector<glm::vec4> Results;
Results.resize(Samples);
float const Steps = (End - Begin) / static_cast<float>(Samples);
std::clock_t const TimeStampBegin = std::clock();
for(std::size_t i = 0; i < Samples; ++i)
Results[i] = glm::fastCos(AngleShift + glm::vec4(Begin + Steps * static_cast<float>(i)));
std::clock_t const TimeStampEnd = std::clock();
std::printf("fastCosOld %d clocks\n", static_cast<int>(TimeStampEnd - TimeStampBegin));
int Error = 0;
for(std::size_t i = 0; i < Samples; ++i)
Error += Results[i].x >= -1.0f && Results[i].x <= 1.0f ? 0 : 1;
return Error;
}
int perf_cos(float Begin, float End, std::size_t Samples)
{
std::vector<glm::vec4> Results;
Results.resize(Samples);
float const Steps = (End - Begin) / static_cast<float>(Samples);
std::clock_t const TimeStampBegin = std::clock();
for(std::size_t i = 0; i < Samples; ++i)
Results[i] = glm::cos(AngleShift + glm::vec4(Begin + Steps * static_cast<float>(i)));
std::clock_t const TimeStampEnd = std::clock();
std::printf("cos %d clocks\n", static_cast<int>(TimeStampEnd - TimeStampBegin));
int Error = 0;
for(std::size_t i = 0; i < Samples; ++i)
Error += Results[i].x >= -1.0f && Results[i].x <= 1.0f ? 0 : 1;
return Error;
}
int perf(std::size_t const Samples)
{
int Error = 0;
float const Begin = -glm::pi<float>();
float const End = glm::pi<float>();
Error += perf_cos(Begin, End, Samples);
Error += perf_fastCosOld(Begin, End, Samples);
Error += perf_fastCosRef(Begin, End, Samples);
//Error += perf_fastCosNew(Begin, End, Samples);
Error += perf_fastCosDeterminisctic(Begin, End, Samples);
return Error;
}
int test()
{
int Error = 0;
//for(float Angle = -4.0f * glm::pi<float>(); Angle < 4.0f * glm::pi<float>(); Angle += 0.1f)
//for(float Angle = -720.0f; Angle < 720.0f; Angle += 0.1f)
for(float Angle = 0.0f; Angle < 180.0f; Angle += 0.1f)
{
float const modAngle = std::fmod(glm::abs(Angle), 360.f);
assert(modAngle >= 0.0f && modAngle <= 360.f);
float const radAngle = glm::radians(modAngle);
float const Cos0 = std::cos(radAngle);
float const Cos1 = taylorCos::fastRefCos(glm::fvec1(radAngle)).x;
Error += glm::abs(Cos1 - Cos0) < 0.1f ? 0 : 1;
//float const Cos2 = taylorCos::fastCosNew(glm::fvec1(radAngle)).x;
//Error += glm::abs(Cos2 - Cos0) < 0.1f ? 0 : 1;
assert(!Error);
}
return Error;
}
}//namespace taylorCos
namespace taylor2
{
glm::vec4 const AngleShift(0.0f, glm::pi<float>() * 0.5f, glm::pi<float>() * 1.0f, glm::pi<float>() * 1.5f);
float taylorCosA(float x)
{
return 1.f
- (x * x) * (1.f / 2.f)
+ (x * x * x * x) * (1.f / 24.f)
- (x * x * x * x * x * x) * (1.f / 720.f)
+ (x * x * x * x * x * x * x * x) * (1.f / 40320.f);
}
float taylorCosB(float x)
{
return 1.f
- (x * x) * (1.f / 2.f)
+ (x * x * x * x) * (1.f / 24.f)
- (x * x * x * x * x * x) * (1.f / 720.f)
+ (x * x * x * x * x * x * x * x) * (1.f / 40320.f);
}
float taylorCosC(float x)
{
return 1.f
- (x * x) * (1.f / 2.f)
+ ((x * x) * (x * x)) * (1.f / 24.f)
- (((x * x) * (x * x)) * (x * x)) * (1.f / 720.f)
+ (((x * x) * (x * x)) * ((x * x) * (x * x))) * (1.f / 40320.f);
}
int perf_taylorCosA(float Begin, float End, std::size_t Samples)
{
std::vector<float> Results;
Results.resize(Samples);
float const Steps = (End - Begin) / static_cast<float>(Samples);
std::clock_t const TimeStampBegin = std::clock();
for(std::size_t i = 0; i < Samples; ++i)
Results[i] = taylorCosA(AngleShift.x + Begin + Steps * static_cast<float>(i));
std::clock_t const TimeStampEnd = std::clock();
std::printf("taylorCosA %d clocks\n", static_cast<int>(TimeStampEnd - TimeStampBegin));
int Error = 0;
for(std::size_t i = 0; i < Samples; ++i)
Error += Results[i] >= -1.0f && Results[i] <= 1.0f ? 0 : 1;
return Error;
}
int perf_taylorCosB(float Begin, float End, std::size_t Samples)
{
std::vector<float> Results;
Results.resize(Samples);
float const Steps = (End - Begin) / static_cast<float>(Samples);
std::clock_t const TimeStampBegin = std::clock();
for(std::size_t i = 0; i < Samples; ++i)
Results[i] = taylorCosB(AngleShift.x + Begin + Steps * static_cast<float>(i));
std::clock_t const TimeStampEnd = std::clock();
std::printf("taylorCosB %d clocks\n", static_cast<int>(TimeStampEnd - TimeStampBegin));
int Error = 0;
for(std::size_t i = 0; i < Samples; ++i)
Error += Results[i] >= -1.0f && Results[i] <= 1.0f ? 0 : 1;
return Error;
}
int perf_taylorCosC(float Begin, float End, std::size_t Samples)
{
std::vector<float> Results;
Results.resize(Samples);
float const Steps = (End - Begin) / static_cast<float>(Samples);
std::clock_t const TimeStampBegin = std::clock();
for(std::size_t i = 0; i < Samples; ++i)
Results[i] = taylorCosC(AngleShift.x + Begin + Steps * static_cast<float>(i));
std::clock_t const TimeStampEnd = std::clock();
std::printf("taylorCosC %d clocks\n", static_cast<int>(TimeStampEnd - TimeStampBegin));
int Error = 0;
for(std::size_t i = 0; i < Samples; ++i)
Error += Results[i] >= -1.0f && Results[i] <= 1.0f ? 0 : 1;
return Error;
}
int perf(std::size_t Samples)
{
int Error = 0;
float const Begin = -glm::pi<float>();
float const End = glm::pi<float>();
Error += perf_taylorCosA(Begin, End, Samples);
Error += perf_taylorCosB(Begin, End, Samples);
Error += perf_taylorCosC(Begin, End, Samples);
return Error;
}
}//namespace taylor2
int main()
{
int Error(0);
Error += ::taylor2::perf(1000);
Error += ::taylorCos::test();
Error += ::taylorCos::perf(1000);
# ifdef NDEBUG
::fastCos::perf(false);
::fastSin::perf(false);
::fastTan::perf(false);
::fastAcos::perf(false);
::fastAsin::perf(false);
::fastAtan::perf(false);
# endif//NDEBUG
return Error;
}

View File

@@ -0,0 +1,36 @@
#include <glm/gtx/functions.hpp>
#include <glm/ext/vector_float2.hpp>
#include <vector>
int test_gauss_1d()
{
int Error = 0;
std::vector<float> Result(20);
for(std::size_t i = 0, n = Result.size(); i < n; ++i)
Result[i] = glm::gauss(static_cast<float>(i) * 0.1f, 0.0f, 1.0f);
return Error;
}
int test_gauss_2d()
{
int Error = 0;
std::vector<float> Result(20);
for(std::size_t i = 0, n = Result.size(); i < n; ++i)
Result[i] = glm::gauss(glm::vec2(static_cast<float>(i)) * 0.1f, glm::vec2(0.0f), glm::vec2(1.0f));
return Error;
}
int main()
{
int Error = 0;
Error += test_gauss_1d();
Error += test_gauss_2d();
return Error;
}

View File

@@ -0,0 +1,34 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/gradient_paint.hpp>
int test_radialGradient()
{
int Error = 0;
float Gradient = glm::radialGradient(glm::vec2(0), 1.0f, glm::vec2(1), glm::vec2(0.5));
Error += Gradient != 0.0f ? 0 : 1;
return Error;
}
int test_linearGradient()
{
int Error = 0;
float Gradient = glm::linearGradient(glm::vec2(0), glm::vec2(1), glm::vec2(0.5));
Error += Gradient != 0.0f ? 0 : 1;
return Error;
}
int main()
{
int Error = 0;
Error += test_radialGradient();
Error += test_linearGradient();
return Error;
}

View File

@@ -0,0 +1,9 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/handed_coordinate_space.hpp>
int main()
{
int Error(0);
return Error;
}

View File

@@ -0,0 +1,18 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
// OpenGL Mathematics Copyright (c) 2005 - 2013 G-Truc Creation (www.g-truc.net)
///////////////////////////////////////////////////////////////////////////////////////////////////
// Created : 2013-10-25
// Updated : 2013-10-25
// Licence : This source is under MIT licence
// File : test/gtx/associated_min_max.cpp
///////////////////////////////////////////////////////////////////////////////////////////////////
#include <glm/gtc/type_precision.hpp>
#include <glm/gtx/associated_min_max.hpp>
int main()
{
int Error(0);
return Error;
}

View File

@@ -0,0 +1,108 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/exponential.hpp>
#include <glm/gtc/epsilon.hpp>
#include <glm/gtx/integer.hpp>
#include <cstdio>
/*
int test_floor_log2()
{
int Error = 0;
for(std::size_t i = 1; i < 1000000; ++i)
{
glm::uint A = glm::floor_log2(glm::uint(i));
glm::uint B = glm::uint(glm::floor(glm::log2(double(i)))); // Will fail with float, lack of accuracy
Error += A == B ? 0 : 1;
assert(!Error);
}
return Error;
}
*/
int test_log2()
{
int Error = 0;
for(std::size_t i = 1; i < 24; ++i)
{
glm::uint A = glm::log2(glm::uint(1 << i));
glm::uint B = glm::uint(glm::log2(double(1 << i)));
//Error += glm::equalEpsilon(double(A), B, 1.0) ? 0 : 1;
Error += glm::abs(double(A) - B) <= 24 ? 0 : 1;
assert(!Error);
std::printf("Log2(%d) error A=%d, B=%d\n", 1 << i, A, B);
}
std::printf("log2 error=%d\n", Error);
return Error;
}
int test_nlz()
{
int Error = 0;
for(glm::uint i = 1; i < glm::uint(33); ++i)
Error += glm::nlz(i) == glm::uint(31u) - glm::findMSB(i) ? 0 : 1;
//printf("%d, %d\n", glm::nlz(i), 31u - glm::findMSB(i));
return Error;
}
int test_pow_uint()
{
int Error = 0;
glm::uint const p0 = glm::pow(2u, 0u);
Error += p0 == 1u ? 0 : 1;
glm::uint const p1 = glm::pow(2u, 1u);
Error += p1 == 2u ? 0 : 1;
glm::uint const p2 = glm::pow(2u, 2u);
Error += p2 == 4u ? 0 : 1;
return Error;
}
int test_pow_int()
{
int Error = 0;
int const p0 = glm::pow(2, 0u);
Error += p0 == 1 ? 0 : 1;
int const p1 = glm::pow(2, 1u);
Error += p1 == 2 ? 0 : 1;
int const p2 = glm::pow(2, 2u);
Error += p2 == 4 ? 0 : 1;
int const p0n = glm::pow(-2, 0u);
Error += p0n == -1 ? 0 : 1;
int const p1n = glm::pow(-2, 1u);
Error += p1n == -2 ? 0 : 1;
int const p2n = glm::pow(-2, 2u);
Error += p2n == 4 ? 0 : 1;
return Error;
}
int main()
{
int Error = 0;
Error += test_nlz();
// Error += test_floor_log2();
Error += test_log2();
Error += test_pow_uint();
Error += test_pow_int();
return Error;
}

View File

@@ -0,0 +1,88 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/glm.hpp>
#include <glm/gtc/epsilon.hpp>
#include <glm/gtx/intersect.hpp>
int test_intersectRayPlane()
{
int Error = 0;
glm::vec3 const PlaneOrigin(0, 0, 1);
glm::vec3 const PlaneNormal(0, 0, -1);
glm::vec3 const RayOrigin(0, 0, 0);
glm::vec3 const RayDir(0, 0, 1);
// check that inversion of the plane normal has no effect
{
float Distance = 0;
bool const Result = glm::intersectRayPlane(RayOrigin, RayDir, PlaneOrigin, PlaneNormal, Distance);
Error += glm::abs(Distance - 1.f) <= std::numeric_limits<float>::epsilon() ? 0 : 1;
Error += Result ? 0 : 1;
}
{
float Distance = 0;
bool const Result = glm::intersectRayPlane(RayOrigin, RayDir, PlaneOrigin, -1.f * PlaneNormal, Distance);
Error += glm::abs(Distance - 1.f) <= std::numeric_limits<float>::epsilon() ? 0 : 1;
Error += Result ? 0 : 1;
}
// check if plane is before of behind the ray origin
{
float Distance = 9.9999f; // value should not be changed
bool const Result = glm::intersectRayPlane(RayOrigin, RayDir, -1.f * PlaneOrigin, PlaneNormal, Distance);
Error += glm::abs(Distance - 9.9999f) <= std::numeric_limits<float>::epsilon() ? 0 : 1;
Error += Result ? 1 : 0; // there is no intersection in front of the ray origin, only behind
}
return Error;
}
int test_intersectRayTriangle()
{
int Error = 0;
glm::vec3 const Orig(0, 0, 2);
glm::vec3 const Dir(0, 0, -1);
glm::vec3 const Vert0(0, 0, 0);
glm::vec3 const Vert1(-1, -1, 0);
glm::vec3 const Vert2(1, -1, 0);
glm::vec2 BaryPosition(0);
float Distance = 0;
bool const Result = glm::intersectRayTriangle(Orig, Dir, Vert0, Vert1, Vert2, BaryPosition, Distance);
Error += glm::all(glm::epsilonEqual(BaryPosition, glm::vec2(0), std::numeric_limits<float>::epsilon())) ? 0 : 1;
Error += glm::abs(Distance - 2.f) <= std::numeric_limits<float>::epsilon() ? 0 : 1;
Error += Result ? 0 : 1;
return Error;
}
int test_intersectLineTriangle()
{
int Error = 0;
glm::vec3 const Orig(0, 0, 2);
glm::vec3 const Dir(0, 0, -1);
glm::vec3 const Vert0(0, 0, 0);
glm::vec3 const Vert1(-1, -1, 0);
glm::vec3 const Vert2(1, -1, 0);
glm::vec3 Position(2.0f, 0.0f, 0.0f);
bool const Result = glm::intersectLineTriangle(Orig, Dir, Vert0, Vert1, Vert2, Position);
Error += glm::all(glm::epsilonEqual(Position, glm::vec3(2.0f, 0.0f, 0.0f), std::numeric_limits<float>::epsilon())) ? 0 : 1;
Error += Result ? 0 : 1;
return Error;
}
int main()
{
int Error = 0;
Error += test_intersectRayPlane();
Error += test_intersectRayTriangle();
Error += test_intersectLineTriangle();
return Error;
}

186
lib/glm/test/gtx/gtx_io.cpp Normal file
View File

@@ -0,0 +1,186 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/glm.hpp>
#if GLM_LANG & GLM_LANG_CXXMS_FLAG
#include <glm/gtc/type_precision.hpp>
#include <glm/gtx/io.hpp>
#include <iostream>
#include <sstream>
#include <typeinfo>
namespace
{
template<typename CTy, typename CTr>
std::basic_ostream<CTy,CTr>& operator<<(std::basic_ostream<CTy,CTr>& os, glm::qualifier const& a)
{
typename std::basic_ostream<CTy,CTr>::sentry const cerberus(os);
if (cerberus)
{
switch (a) {
case glm::highp: os << "uhi"; break;
case glm::mediump: os << "umd"; break;
case glm::lowp: os << "ulo"; break;
# if GLM_CONFIG_ALIGNED_GENTYPES == GLM_ENABLE
case glm::aligned_highp: os << "ahi"; break;
case glm::aligned_mediump: os << "amd"; break;
case glm::aligned_lowp: os << "alo"; break;
# endif
}
}
return os;
}
template<typename U, glm::qualifier P, typename T, typename CTy, typename CTr>
std::basic_string<CTy> type_name(std::basic_ostream<CTy,CTr>&, T const&)
{
std::basic_ostringstream<CTy,CTr> ostr;
if (typeid(T) == typeid(glm::qua<U,P>)) { ostr << "quat"; }
else if (typeid(T) == typeid(glm::vec<2, U,P>)) { ostr << "vec2"; }
else if (typeid(T) == typeid(glm::vec<3, U,P>)) { ostr << "vec3"; }
else if (typeid(T) == typeid(glm::vec<4, U,P>)) { ostr << "vec4"; }
else if (typeid(T) == typeid(glm::mat<2, 2, U,P>)) { ostr << "mat2x2"; }
else if (typeid(T) == typeid(glm::mat<2, 3, U,P>)) { ostr << "mat2x3"; }
else if (typeid(T) == typeid(glm::mat<2, 4, U,P>)) { ostr << "mat2x4"; }
else if (typeid(T) == typeid(glm::mat<3, 2, U,P>)) { ostr << "mat3x2"; }
else if (typeid(T) == typeid(glm::mat<3, 3, U,P>)) { ostr << "mat3x3"; }
else if (typeid(T) == typeid(glm::mat<3, 4, U,P>)) { ostr << "mat3x4"; }
else if (typeid(T) == typeid(glm::mat<4, 2, U,P>)) { ostr << "mat4x2"; }
else if (typeid(T) == typeid(glm::mat<4, 3, U,P>)) { ostr << "mat4x3"; }
else if (typeid(T) == typeid(glm::mat<4, 4, U,P>)) { ostr << "mat4x4"; }
else { ostr << "unknown"; }
ostr << '<' << typeid(U).name() << ',' << P << '>';
return ostr.str();
}
} // namespace {
template<typename T, glm::qualifier P, typename OS>
int test_io_quat(OS& os)
{
os << '\n' << typeid(OS).name() << '\n';
glm::qua<T, P> const q(1, 0, 0, 0);
{
glm::io::basic_format_saver<typename OS::char_type> const iofs(os);
os << glm::io::precision(2) << glm::io::width(1 + 2 + 1 + 2)
<< type_name<T, P>(os, q) << ": " << q << '\n';
}
{
glm::io::basic_format_saver<typename OS::char_type> const iofs(os);
os << glm::io::unformatted
<< type_name<T, P>(os, q) << ": " << q << '\n';
}
return 0;
}
template<typename T, glm::qualifier P, typename OS>
int test_io_vec(OS& os)
{
os << '\n' << typeid(OS).name() << '\n';
glm::vec<2, T,P> const v2(0, 1);
glm::vec<3, T,P> const v3(2, 3, 4);
glm::vec<4, T,P> const v4(5, 6, 7, 8);
os << type_name<T,P>(os, v2) << ": " << v2 << '\n'
<< type_name<T,P>(os, v3) << ": " << v3 << '\n'
<< type_name<T,P>(os, v4) << ": " << v4 << '\n';
glm::io::basic_format_saver<typename OS::char_type> const iofs(os);
os << glm::io::precision(2) << glm::io::width(1 + 2 + 1 + 2)
<< type_name<T,P>(os, v2) << ": " << v2 << '\n'
<< type_name<T,P>(os, v3) << ": " << v3 << '\n'
<< type_name<T,P>(os, v4) << ": " << v4 << '\n';
return 0;
}
template<typename T, glm::qualifier P, typename OS>
int test_io_mat(OS& os, glm::io::order_type otype)
{
os << '\n' << typeid(OS).name() << '\n';
glm::vec<2, T,P> const v2_1( 0, 1);
glm::vec<2, T,P> const v2_2( 2, 3);
glm::vec<2, T,P> const v2_3( 4, 5);
glm::vec<2, T,P> const v2_4( 6, 7);
glm::vec<3, T,P> const v3_1( 8, 9, 10);
glm::vec<3, T,P> const v3_2(11, 12, 13);
glm::vec<3, T,P> const v3_3(14, 15, 16);
glm::vec<3, T,P> const v3_4(17, 18, 19);
glm::vec<4, T,P> const v4_1(20, 21, 22, 23);
glm::vec<4, T,P> const v4_2(24, 25, 26, 27);
glm::vec<4, T,P> const v4_3(28, 29, 30, 31);
glm::vec<4, T,P> const v4_4(32, 33, 34, 35);
glm::io::basic_format_saver<typename OS::char_type> const iofs(os);
os << glm::io::precision(2) << glm::io::width(1 + 2 + 1 + 2)
<< glm::io::order(otype)
<< "mat2x2<" << typeid(T).name() << ',' << P << ">: " << glm::mat<2, 2, T,P>(v2_1, v2_2) << '\n'
<< "mat2x3<" << typeid(T).name() << ',' << P << ">: " << glm::mat<2, 3, T,P>(v3_1, v3_2) << '\n'
<< "mat2x4<" << typeid(T).name() << ',' << P << ">: " << glm::mat<2, 4, T,P>(v4_1, v4_2) << '\n'
<< "mat3x2<" << typeid(T).name() << ',' << P << ">: " << glm::mat<3, 2, T,P>(v2_1, v2_2, v2_3) << '\n'
<< "mat3x3<" << typeid(T).name() << ',' << P << ">: " << glm::mat<3, 3, T,P>(v3_1, v3_2, v3_3) << '\n'
<< "mat3x4<" << typeid(T).name() << ',' << P << ">: " << glm::mat<3, 4, T,P>(v4_1, v4_2, v4_3) << '\n'
<< "mat4x2<" << typeid(T).name() << ',' << P << ">: " << glm::mat<4, 2, T,P>(v2_1, v2_2, v2_3, v2_4) << '\n'
<< "mat4x3<" << typeid(T).name() << ',' << P << ">: " << glm::mat<4, 3, T,P>(v3_1, v3_2, v3_3, v3_4) << '\n'
<< "mat4x4<" << typeid(T).name() << ',' << P << ">: " << glm::mat<4, 4, T,P>(v4_1, v4_2, v4_3, v4_4) << '\n';
os << glm::io::unformatted
<< glm::io::order(otype)
<< "mat2x2<" << typeid(T).name() << ',' << P << ">: " << glm::mat<2, 2, T,P>(v2_1, v2_2) << '\n'
<< "mat2x3<" << typeid(T).name() << ',' << P << ">: " << glm::mat<2, 3, T,P>(v3_1, v3_2) << '\n'
<< "mat2x4<" << typeid(T).name() << ',' << P << ">: " << glm::mat<2, 4, T,P>(v4_1, v4_2) << '\n'
<< "mat3x2<" << typeid(T).name() << ',' << P << ">: " << glm::mat<3, 2, T,P>(v2_1, v2_2, v2_3) << '\n'
<< "mat3x3<" << typeid(T).name() << ',' << P << ">: " << glm::mat<3, 3, T,P>(v3_1, v3_2, v3_3) << '\n'
<< "mat3x4<" << typeid(T).name() << ',' << P << ">: " << glm::mat<3, 4, T,P>(v4_1, v4_2, v4_3) << '\n'
<< "mat4x2<" << typeid(T).name() << ',' << P << ">: " << glm::mat<4, 2, T,P>(v2_1, v2_2, v2_3, v2_4) << '\n'
<< "mat4x3<" << typeid(T).name() << ',' << P << ">: " << glm::mat<4, 3, T,P>(v3_1, v3_2, v3_3, v3_4) << '\n'
<< "mat4x4<" << typeid(T).name() << ',' << P << ">: " << glm::mat<4, 4, T,P>(v4_1, v4_2, v4_3, v4_4) << '\n';
return 0;
}
int main()
{
int Error(0);
Error += test_io_quat<float, glm::highp>(std::cout);
Error += test_io_quat<float, glm::highp>(std::wcout);
Error += test_io_quat<int, glm::mediump>(std::cout);
Error += test_io_quat<int, glm::mediump>(std::wcout);
Error += test_io_quat<glm::uint, glm::lowp>(std::cout);
Error += test_io_quat<glm::uint, glm::lowp>(std::wcout);
Error += test_io_vec<float, glm::highp>(std::cout);
Error += test_io_vec<float, glm::highp>(std::wcout);
Error += test_io_vec<int, glm::mediump>(std::cout);
Error += test_io_vec<int, glm::mediump>(std::wcout);
Error += test_io_vec<glm::uint, glm::lowp>(std::cout);
Error += test_io_vec<glm::uint, glm::lowp>(std::wcout);
Error += test_io_mat<float, glm::highp>(std::cout, glm::io::column_major);
Error += test_io_mat<float, glm::lowp>(std::wcout, glm::io::column_major);
Error += test_io_mat<float, glm::highp>(std::cout, glm::io::row_major);
Error += test_io_mat<float, glm::lowp>(std::wcout, glm::io::row_major);
return Error;
}
#else
int main()
{
return 0;
}
#endif// GLM_LANG & GLM_LANG_CXXMS_FLAG

View File

@@ -0,0 +1,124 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/glm.hpp>
/*
#if GLM_CONFIG_SIMD == GLM_ENABLE
#include <glm/gtx/common.hpp>
#include <glm/gtc/integer.hpp>
#include <glm/gtc/epsilon.hpp>
#include <glm/gtc/type_aligned.hpp>
#include <glm/ext/vector_relational.hpp>
namespace glm
{
enum genTypeEnum
{
QUALIFIER_HIGHP,
QUALIFIER_MEDIUMP,
QUALIFIER_LOWP
};
template <typename genType>
struct genTypeTrait
{};
template <length_t L, typename T>
struct genTypeTrait<vec<L, T, aligned_highp> >
{
static const genTypeEnum GENTYPE = QUALIFIER_HIGHP;
};
template <length_t L, typename T>
struct genTypeTrait<vec<L, T, aligned_mediump> >
{
static const genTypeEnum GENTYPE = QUALIFIER_MEDIUMP;
};
template <length_t L, typename T>
struct genTypeTrait<vec<L, T, aligned_lowp> >
{
static const genTypeEnum GENTYPE = QUALIFIER_LOWP;
};
template<length_t L, typename T, qualifier Q, bool isAligned>
struct load_gentype
{
};
# if GLM_ARCH & GLM_ARCH_SSE_BIT
template<qualifier Q>
struct load_gentype<4, float, Q, true>
{
GLM_FUNC_QUALIFIER GLM_CONSTEXPR static vec<4, float, Q> load(float const* Mem)
{
vec<4, float, Q> Result;
Result.data = _mm_loadu_ps(Mem);
return Result;
}
};
# endif//GLM_ARCH & GLM_ARCH_SSE_BIT
template<typename genType>
GLM_FUNC_QUALIFIER GLM_CONSTEXPR genType example_identity()
{
return detail::init_gentype<genType, detail::genTypeTrait<genType>::GENTYPE>::identity();
}
template <typename genType, typename valType>
genType load(valType const* Mem)
{
}
aligned_vec4 loadu(float const* Mem)
{
aligned_vec4 Result;
# if GLM_ARCH & GLM_ARCH_SSE_BIT
Result.data = _mm_loadu_ps(Mem);
# else
Result[0] = *(Mem + 0);
Result[1] = *(Mem + 1);
Result[2] = *(Mem + 2);
Result[3] = *(Mem + 3);
# endif//GLM_ARCH & GLM_ARCH_SSE_BIT
return Result;
}
aligned_vec4 loada(float const* Mem)
{
aligned_vec4 Result;
# if GLM_ARCH & GLM_ARCH_SSE_BIT
Result.data = _mm_load_ps(Mem);
# else
Result[0] = *(Mem + 0);
Result[1] = *(Mem + 1);
Result[2] = *(Mem + 2);
Result[3] = *(Mem + 3);
# endif//GLM_ARCH & GLM_ARCH_SSE_BIT
return Result;
}
}//namespace glm
int test_vec4_load()
{
int Error = 0;
float Data[] = {1.f, 2.f, 3.f, 4.f};
glm::aligned_vec4 const V = glm::loadu(Data);
Error += glm::all(glm::equal(V, glm::aligned_vec4(1.f, 2.f, 3.f, 4.f), glm::epsilon<float>())) ? 0 : 1;
return Error;
}
#endif
*/
int main()
{
int Error = 0;
/*
# if GLM_CONFIG_SIMD == GLM_ENABLE
Error += test_vec4_load();
# endif
*/
return Error;
}

View File

@@ -0,0 +1,54 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/log_base.hpp>
#include <glm/gtc/vec1.hpp>
#include <glm/gtc/epsilon.hpp>
#include <glm/exponential.hpp>
namespace test_log
{
int run()
{
int Error = 0;
{
float A = glm::log(10.f, 2.0f);
float B = glm::log2(10.f);
Error += glm::epsilonEqual(A, B, 0.00001f) ? 0 : 1;
}
{
glm::vec1 A = glm::log(glm::vec1(10.f), glm::vec1(2.0f));
glm::vec1 B = glm::log2(glm::vec1(10.f));
Error += glm::all(glm::epsilonEqual(A, B, glm::vec1(0.00001f))) ? 0 : 1;
}
{
glm::vec2 A = glm::log(glm::vec2(10.f), glm::vec2(2.0f));
glm::vec2 B = glm::log2(glm::vec2(10.f));
Error += glm::all(glm::epsilonEqual(A, B, glm::vec2(0.00001f))) ? 0 : 1;
}
{
glm::vec3 A = glm::log(glm::vec3(10.f), glm::vec3(2.0f));
glm::vec3 B = glm::log2(glm::vec3(10.f));
Error += glm::all(glm::epsilonEqual(A, B, glm::vec3(0.00001f))) ? 0 : 1;
}
{
glm::vec4 A = glm::log(glm::vec4(10.f), glm::vec4(2.0f));
glm::vec4 B = glm::log2(glm::vec4(10.f));
Error += glm::all(glm::epsilonEqual(A, B, glm::vec4(0.00001f))) ? 0 : 1;
}
return Error;
}
}//namespace test_log
int main()
{
int Error(0);
Error += test_log::run();
return Error;
}

View File

@@ -0,0 +1,9 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/matrix_cross_product.hpp>
int main()
{
int Error(0);
return Error;
}

View File

@@ -0,0 +1,19 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/matrix_decompose.hpp>
int main()
{
int Error(0);
glm::mat4 Matrix(1);
glm::vec3 Scale;
glm::quat Orientation;
glm::vec3 Translation;
glm::vec3 Skew(1);
glm::vec4 Perspective(1);
glm::decompose(Matrix, Scale, Orientation, Translation, Skew, Perspective);
return Error;
}

View File

@@ -0,0 +1,105 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/matrix_factorisation.hpp>
#include <glm/gtc/constants.hpp>
#include <glm/gtc/epsilon.hpp>
template <glm::length_t C, glm::length_t R, typename T, glm::qualifier Q>
int test_qr(glm::mat<C, R, T, Q> m)
{
int Error = 0;
T const epsilon = static_cast<T>(1e-10);
glm::mat<(C < R ? C : R), R, T, Q> q(-999);
glm::mat<C, (C < R ? C : R), T, Q> r(-999);
glm::qr_decompose(m, q, r);
//Test if q*r really equals the input matrix
glm::mat<C, R, T, Q> tm = q*r;
glm::mat<C, R, T, Q> err = tm - m;
for (glm::length_t i = 0; i < C; i++)
for (glm::length_t j = 0; j < R; j++)
Error += glm::abs(err[i][j]) > epsilon ? 1 : 0;
//Test if the columns of q are orthonormal
for (glm::length_t i = 0; i < (C < R ? C : R); i++)
{
Error += (length(q[i]) - 1) > epsilon ? 1 : 0;
for (glm::length_t j = 0; j<i; j++)
Error += glm::abs(dot(q[i], q[j])) > epsilon ? 1 : 0;
}
//Test if the matrix r is upper triangular
for (glm::length_t i = 0; i < C; i++)
for (glm::length_t j = i + 1; j < (C < R ? C : R); j++)
Error += glm::epsilonEqual(r[i][j], static_cast<T>(0), glm::epsilon<T>()) ? 0 : 1;
return Error;
}
template <glm::length_t C, glm::length_t R, typename T, glm::qualifier Q>
int test_rq(glm::mat<C, R, T, Q> m)
{
int Error = 0;
T const epsilon = static_cast<T>(1e-10);
glm::mat<C, (C < R ? C : R), T, Q> q(-999);
glm::mat<(C < R ? C : R), R, T, Q> r(-999);
glm::rq_decompose(m, r, q);
//Test if q*r really equals the input matrix
glm::mat<C, R, T, Q> tm = r*q;
glm::mat<C, R, T, Q> err = tm - m;
for (glm::length_t i = 0; i < C; i++)
for (glm::length_t j = 0; j < R; j++)
Error += glm::abs(err[i][j]) > epsilon ? 1 : 0;
//Test if the rows of q are orthonormal
glm::mat<(C < R ? C : R), C, T, Q> tq = transpose(q);
for (glm::length_t i = 0; i < (C < R ? C : R); i++)
{
Error += (length(tq[i]) - 1) > epsilon ? 1 : 0;
for (glm::length_t j = 0; j<i; j++)
Error += glm::abs(dot(tq[i], tq[j])) > epsilon ? 1 : 0;
}
//Test if the matrix r is upper triangular
for (glm::length_t i = 0; i < (C < R ? C : R); i++)
for (glm::length_t j = R - (C < R ? C : R) + i + 1; j < R; j++)
Error += glm::epsilonEqual(r[i][j], static_cast<T>(0), glm::epsilon<T>()) ? 0 : 1;
return Error;
}
int main()
{
int Error = 0;
//Test QR square
Error += test_qr(glm::dmat3(12.0, 6.0, -4.0, -51.0, 167.0, 24.0, 4.0, -68.0, -41.0)) ? 1 : 0;
//Test RQ square
Error += test_rq(glm::dmat3(12.0, 6.0, -4.0, -51.0, 167.0, 24.0, 4.0, -68.0, -41.0)) ? 1 : 0;
//Test QR triangular 1
Error += test_qr(glm::dmat3x4(12.0, 6.0, -4.0, -51.0, 167.0, 24.0, 4.0, -68.0, -41.0, 7.0, 2.0, 15.0)) ? 1 : 0;
//Test QR triangular 2
Error += test_qr(glm::dmat4x3(12.0, 6.0, -4.0, -51.0, 167.0, 24.0, 4.0, -68.0, -41.0, 7.0, 2.0, 15.0)) ? 1 : 0;
//Test RQ triangular 1 : Fails at the triangular test
Error += test_rq(glm::dmat3x4(12.0, 6.0, -4.0, -51.0, 167.0, 24.0, 4.0, -68.0, -41.0, 7.0, 2.0, 15.0)) ? 1 : 0;
//Test QR triangular 2
Error += test_rq(glm::dmat4x3(12.0, 6.0, -4.0, -51.0, 167.0, 24.0, 4.0, -68.0, -41.0, 7.0, 2.0, 15.0)) ? 1 : 0;
return Error;
}

View File

@@ -0,0 +1,59 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtc/quaternion.hpp>
#include <glm/gtx/matrix_interpolation.hpp>
#include <iostream>
static int test_axisAngle()
{
int Error = 0;
glm::mat4 m1(-0.9946f, 0.0f, -0.104531f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f,
0.104531f, 0.0f, -0.9946f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f);
glm::mat4 m2(-0.992624f, 0.0f, -0.121874f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f,
0.121874f, 0.0f, -0.992624f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f);
glm::mat4 const m1rot = glm::extractMatrixRotation(m1);
glm::mat4 const dltRotation = m2 * glm::transpose(m1rot);
glm::vec3 dltAxis(0.0f);
float dltAngle = 0.0f;
glm::axisAngle(dltRotation, dltAxis, dltAngle);
std::cout << "dltAxis: (" << dltAxis.x << ", " << dltAxis.y << ", " << dltAxis.z << "), dltAngle: " << dltAngle << std::endl;
glm::quat q = glm::quat_cast(dltRotation);
std::cout << "q: (" << q.x << ", " << q.y << ", " << q.z << ", " << q.w << ")" << std::endl;
float yaw = glm::yaw(q);
std::cout << "Yaw: " << yaw << std::endl;
return Error;
}
static int test_rotate()
{
glm::mat4 m2(1.0);
float myAngle = 1.0f;
m2 = glm::rotate(m2, myAngle, glm::vec3(1.0f, 0.0f, 0.0f));
glm::vec3 m2Axis;
float m2Angle;
glm::axisAngle(m2, m2Axis, m2Angle);
return 0;
}
int main()
{
int Error = 0;
Error += test_axisAngle();
Error += test_rotate();
return Error;
}

View File

@@ -0,0 +1,9 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/matrix_major_storage.hpp>
int main()
{
int Error(0);
return Error;
}

View File

@@ -0,0 +1,9 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/matrix_operation.hpp>
int main()
{
int Error(0);
return Error;
}

View File

@@ -0,0 +1,66 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/matrix_query.hpp>
int test_isNull()
{
int Error(0);
bool TestA = glm::isNull(glm::mat4(0), 0.00001f);
Error += TestA ? 0 : 1;
return Error;
}
int test_isIdentity()
{
int Error(0);
{
bool TestA = glm::isIdentity(glm::mat2(1), 0.00001f);
Error += TestA ? 0 : 1;
}
{
bool TestA = glm::isIdentity(glm::mat3(1), 0.00001f);
Error += TestA ? 0 : 1;
}
{
bool TestA = glm::isIdentity(glm::mat4(1), 0.00001f);
Error += TestA ? 0 : 1;
}
return Error;
}
int test_isNormalized()
{
int Error(0);
bool TestA = glm::isNormalized(glm::mat4(1), 0.00001f);
Error += TestA ? 0 : 1;
return Error;
}
int test_isOrthogonal()
{
int Error(0);
bool TestA = glm::isOrthogonal(glm::mat4(1), 0.00001f);
Error += TestA ? 0 : 1;
return Error;
}
int main()
{
int Error(0);
Error += test_isNull();
Error += test_isIdentity();
Error += test_isNormalized();
Error += test_isOrthogonal();
return Error;
}

View File

@@ -0,0 +1,9 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/matrix_transform_2d.hpp>
int main()
{
int Error(0);
return Error;
}

View File

@@ -0,0 +1,18 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
// OpenGL Mathematics Copyright (c) 2005 - 2013 G-Truc Creation (www.g-truc.net)
///////////////////////////////////////////////////////////////////////////////////////////////////
// Created : 2013-10-25
// Updated : 2013-10-25
// Licence : This source is under MIT licence
// File : test/gtx/associated_min_max.cpp
///////////////////////////////////////////////////////////////////////////////////////////////////
#include <glm/gtc/type_precision.hpp>
#include <glm/gtx/associated_min_max.hpp>
int main()
{
int Error(0);
return Error;
}

View File

@@ -0,0 +1,81 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/norm.hpp>
int test_lMaxNorm()
{
int Error(0);
{
float norm = glm::lMaxNorm(glm::vec3(-1, -2, -3));
Error += glm::epsilonEqual(norm, 3.f, 0.00001f) ? 0 : 1;
}
{
float norm = glm::lMaxNorm(glm::vec3(2, 3, 1));
Error += glm::epsilonEqual(norm, 3.f, 0.00001f) ? 0 : 1;
}
return Error;
}
int test_lxNorm()
{
int Error(0);
{
unsigned int depth_1 = 1;
float normA = glm::lxNorm(glm::vec3(2, 3, 1), depth_1);
float normB = glm::l1Norm(glm::vec3(2, 3, 1));
Error += glm::epsilonEqual(normA, normB, 0.00001f) ? 0 : 1;
Error += glm::epsilonEqual(normA, 6.f, 0.00001f) ? 0 : 1;
}
{
unsigned int depth_1 = 1;
float normA = glm::lxNorm(glm::vec3(-1, -2, -3), depth_1);
float normB = glm::l1Norm(glm::vec3(-1, -2, -3));
Error += glm::epsilonEqual(normA, normB, 0.00001f) ? 0 : 1;
Error += glm::epsilonEqual(normA, 6.f, 0.00001f) ? 0 : 1;
}
{
unsigned int depth_2 = 2;
float normA = glm::lxNorm(glm::vec3(2, 3, 1), depth_2);
float normB = glm::l2Norm(glm::vec3(2, 3, 1));
Error += glm::epsilonEqual(normA, normB, 0.00001f) ? 0 : 1;
Error += glm::epsilonEqual(normA, 3.741657387f, 0.00001f) ? 0 : 1;
}
{
unsigned int depth_2 = 2;
float normA = glm::lxNorm(glm::vec3(-1, -2, -3), depth_2);
float normB = glm::l2Norm(glm::vec3(-1, -2, -3));
Error += glm::epsilonEqual(normA, normB, 0.00001f) ? 0 : 1;
Error += glm::epsilonEqual(normA, 3.741657387f, 0.00001f) ? 0 : 1;
}
{
unsigned int oddDepth = 3;
float norm = glm::lxNorm(glm::vec3(2, 3, 1), oddDepth);
Error += glm::epsilonEqual(norm, 3.301927249f, 0.00001f) ? 0 : 1;
}
{
unsigned int oddDepth = 3;
float norm = glm::lxNorm(glm::vec3(-1, -2, -3), oddDepth);
Error += glm::epsilonEqual(norm, 3.301927249f, 0.00001f) ? 0 : 1;
}
return Error;
}
int main()
{
int Error(0);
Error += test_lMaxNorm();
Error += test_lxNorm();
return Error;
}

View File

@@ -0,0 +1,9 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/normal.hpp>
int main()
{
int Error(0);
return Error;
}

View File

@@ -0,0 +1,9 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/normalize_dot.hpp>
int main()
{
int Error(0);
return Error;
}

View File

@@ -0,0 +1,9 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/number_precision.hpp>
int main()
{
int Error(0);
return Error;
}

View File

@@ -0,0 +1,9 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/optimum_pow.hpp>
int main()
{
int Error(0);
return Error;
}

View File

@@ -0,0 +1,9 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/orthonormalize.hpp>
int main()
{
int Error(0);
return Error;
}

View File

@@ -0,0 +1,9 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/perpendicular.hpp>
int main()
{
int Error(0);
return Error;
}

View File

@@ -0,0 +1,9 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/polar_coordinates.hpp>
int main()
{
int Error(0);
return Error;
}

View File

@@ -0,0 +1,9 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/projection.hpp>
int main()
{
int Error(0);
return Error;
}

View File

@@ -0,0 +1,107 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtc/epsilon.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtx/transform.hpp>
#include <glm/gtx/quaternion.hpp>
#include <glm/gtx/compatibility.hpp>
#include <glm/ext.hpp>
int test_quat_fastMix()
{
int Error = 0;
glm::quat A = glm::angleAxis(0.0f, glm::vec3(0, 0, 1));
glm::quat B = glm::angleAxis(glm::pi<float>() * 0.5f, glm::vec3(0, 0, 1));
glm::quat C = glm::fastMix(A, B, 0.5f);
glm::quat D = glm::angleAxis(glm::pi<float>() * 0.25f, glm::vec3(0, 0, 1));
Error += glm::epsilonEqual(C.x, D.x, 0.01f) ? 0 : 1;
Error += glm::epsilonEqual(C.y, D.y, 0.01f) ? 0 : 1;
Error += glm::epsilonEqual(C.z, D.z, 0.01f) ? 0 : 1;
Error += glm::epsilonEqual(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(glm::pi<float>() * 0.5f, glm::vec3(0, 0, 1));
glm::quat C = glm::shortMix(A, B, 0.5f);
glm::quat D = glm::angleAxis(glm::pi<float>() * 0.25f, glm::vec3(0, 0, 1));
Error += glm::epsilonEqual(C.x, D.x, 0.01f) ? 0 : 1;
Error += glm::epsilonEqual(C.y, D.y, 0.01f) ? 0 : 1;
Error += glm::epsilonEqual(C.z, D.z, 0.01f) ? 0 : 1;
Error += glm::epsilonEqual(C.w, D.w, 0.01f) ? 0 : 1;
return Error;
}
int test_orientation()
{
int Error = 0;
{
glm::quat q(1.0f, 0.0f, 0.0f, 1.0f);
float p = glm::roll(q);
Error += glm::epsilonEqual(p, glm::pi<float>() * 0.5f, 0.0001f) ? 0 : 1;
}
{
glm::quat q(1.0f, 0.0f, 0.0f, 1.0f);
float p = glm::pitch(q);
Error += glm::epsilonEqual(p, 0.f, 0.0001f) ? 0 : 1;
}
{
glm::quat q(1.0f, 0.0f, 0.0f, 1.0f);
float p = glm::yaw(q);
Error += glm::epsilonEqual(p, 0.f, 0.0001f) ? 0 : 1;
}
return Error;
}
int test_rotation()
{
int Error(0);
glm::vec3 v(1, 0, 0);
glm::vec3 u(0, 1, 0);
glm::quat Rotation = glm::rotation(v, u);
float Angle = glm::angle(Rotation);
Error += glm::abs(Angle - glm::pi<float>() * 0.5f) < glm::epsilon<float>() ? 0 : 1;
return Error;
}
int test_log()
{
int Error(0);
glm::quat q;
glm::quat p = glm::log(q);
glm::quat r = glm::exp(p);
return Error;
}
int main()
{
int Error = 0;
Error += test_log();
Error += test_rotation();
Error += test_orientation();
Error += test_quat_fastMix();
Error += test_quat_shortMix();
return Error;
}

View File

@@ -0,0 +1,99 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
// OpenGL Mathematics Copyright (c) 2005 - 2012 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.000001f) ? 0 : 1;
Error += glm::equalEpsilon(ResultDouble, double(Max), 0.000001) ? 0 : 1;
assert(!Error);
}
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;
}

View File

@@ -0,0 +1,83 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtc/constants.hpp>
#include <glm/ext/scalar_relational.hpp>
#include <glm/ext/vector_relational.hpp>
#include <glm/glm.hpp>
#if GLM_HAS_RANGE_FOR
#include <glm/gtx/range.hpp>
int test_vec()
{
int Error = 0;
{
glm::ivec3 const v(1, 2, 3);
int count = 0;
glm::ivec3 Result(0);
for(int x : v)
{
Result[count] = x;
count++;
}
Error += count == 3 ? 0 : 1;
Error += v == Result ? 0 : 1;
}
{
glm::ivec3 v(1, 2, 3);
for(int& x : v)
x = 0;
Error += glm::all(glm::equal(v, glm::ivec3(0))) ? 0 : 1;
}
return Error;
}
int test_mat()
{
int Error = 0;
{
glm::mat4x3 m(1.0f);
int count = 0;
float Sum = 0.0f;
for(float x : m)
{
count++;
Sum += x;
}
Error += count == 12 ? 0 : 1;
Error += glm::equal(Sum, 3.0f, 0.001f) ? 0 : 1;
}
{
glm::mat4x3 m(1.0f);
for (float& x : m) { x = 0; }
glm::vec4 v(1, 1, 1, 1);
Error += glm::all(glm::equal(m*v, glm::vec3(0, 0, 0), glm::epsilon<float>())) ? 0 : 1;
}
return Error;
}
int main()
{
int Error = 0;
Error += test_vec();
Error += test_mat();
return Error;
}
#else
int main()
{
return 0;
}
#endif//GLM_HAS_RANGE_FOR

View File

@@ -0,0 +1,9 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/rotate_normalized_axis.hpp>
int main()
{
int Error(0);
return Error;
}

View File

@@ -0,0 +1,77 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/rotate_vector.hpp>
#include <glm/gtc/constants.hpp>
#include <glm/ext/vector_relational.hpp>
int test_rotate()
{
int Error = 0;
glm::vec2 A = glm::rotate(glm::vec2(1, 0), glm::pi<float>() * 0.5f);
glm::vec3 B = glm::rotate(glm::vec3(1, 0, 0), glm::pi<float>() * 0.5f, glm::vec3(0, 0, 1));
glm::vec4 C = glm::rotate(glm::vec4(1, 0, 0, 1), glm::pi<float>() * 0.5f, glm::vec3(0, 0, 1));
glm::vec3 D = glm::rotateX(glm::vec3(1, 0, 0), glm::pi<float>() * 0.5f);
glm::vec4 E = glm::rotateX(glm::vec4(1, 0, 0, 1), glm::pi<float>() * 0.5f);
glm::vec3 F = glm::rotateY(glm::vec3(1, 0, 0), glm::pi<float>() * 0.5f);
glm::vec4 G = glm::rotateY(glm::vec4(1, 0, 0, 1), glm::pi<float>() * 0.5f);
glm::vec3 H = glm::rotateZ(glm::vec3(1, 0, 0), glm::pi<float>() * 0.5f);
glm::vec4 I = glm::rotateZ(glm::vec4(1, 0, 0,1 ), glm::pi<float>() * 0.5f);
glm::mat4 O = glm::orientation(glm::normalize(glm::vec3(1)), glm::vec3(0, 0, 1));
return Error;
}
int test_rotateX()
{
int Error = 0;
glm::vec3 D = glm::rotateX(glm::vec3(1, 0, 0), glm::pi<float>() * 0.5f);
glm::vec4 E = glm::rotateX(glm::vec4(1, 0, 0, 1), glm::pi<float>() * 0.5f);
return Error;
}
int test_rotateY()
{
int Error = 0;
glm::vec3 F = glm::rotateY(glm::vec3(1, 0, 0), glm::pi<float>() * 0.5f);
glm::vec4 G = glm::rotateY(glm::vec4(1, 0, 0, 1), glm::pi<float>() * 0.5f);
return Error;
}
int test_rotateZ()
{
int Error = 0;
glm::vec3 H = glm::rotateZ(glm::vec3(1, 0, 0), glm::pi<float>() * 0.5f);
glm::vec4 I = glm::rotateZ(glm::vec4(1, 0, 0,1 ), glm::pi<float>() * 0.5f);
return Error;
}
int test_orientation()
{
int Error = 0;
glm::mat4 O = glm::orientation(glm::normalize(glm::vec3(1)), glm::vec3(0, 0, 1));
return Error;
}
int main()
{
int Error = 0;
Error += test_rotate();
Error += test_rotateX();
Error += test_rotateY();
Error += test_rotateZ();
Error += test_orientation();
return Error;
}

View File

@@ -0,0 +1,37 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtc/constants.hpp>
#include <glm/ext/vector_relational.hpp>
#include <glm/glm.hpp>
#if GLM_HAS_TEMPLATE_ALIASES && !(GLM_COMPILER & GLM_COMPILER_GCC)
#include <glm/gtx/scalar_multiplication.hpp>
int main()
{
int Error(0);
glm::vec3 v(0.5, 3.1, -9.1);
Error += glm::all(glm::equal(v, 1.0 * v, glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::equal(v, 1 * v, glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::equal(v, 1u * v, glm::epsilon<float>())) ? 0 : 1;
glm::mat3 m(1, 2, 3, 4, 5, 6, 7, 8, 9);
glm::vec3 w = 0.5f * m * v;
Error += glm::all(glm::equal((m*v)/2, w, glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::equal(m*(v/2), w, glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::equal((m/2)*v, w, glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::equal((0.5*m)*v, w, glm::epsilon<float>())) ? 0 : 1;
Error += glm::all(glm::equal(0.5*(m*v), w, glm::epsilon<float>())) ? 0 : 1;
return Error;
}
#else
int main()
{
return 0;
}
#endif

View File

@@ -0,0 +1,174 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/scalar_relational.hpp>
#include <glm/gtc/constants.hpp>
#include <glm/ext/scalar_relational.hpp>
#include <glm/ext/vector_relational.hpp>
#include <glm/ext/matrix_relational.hpp>
#include <glm/glm.hpp>
static int test_lessThan()
{
int Error = 0;
Error += glm::lessThan(0, 1) ? 0 : 1;
Error += glm::lessThan(1, 0) ? 1 : 0;
Error += glm::lessThan(0, 0) ? 1 : 0;
Error += glm::lessThan(1, 1) ? 1 : 0;
Error += glm::lessThan(0.0f, 1.0f) ? 0 : 1;
Error += glm::lessThan(1.0f, 0.0f) ? 1 : 0;
Error += glm::lessThan(0.0f, 0.0f) ? 1 : 0;
Error += glm::lessThan(1.0f, 1.0f) ? 1 : 0;
Error += glm::lessThan(0.0, 1.0) ? 0 : 1;
Error += glm::lessThan(1.0, 0.0) ? 1 : 0;
Error += glm::lessThan(0.0, 0.0) ? 1 : 0;
Error += glm::lessThan(1.0, 1.0) ? 1 : 0;
return Error;
}
static int test_lessThanEqual()
{
int Error = 0;
Error += glm::lessThanEqual(0, 1) ? 0 : 1;
Error += glm::lessThanEqual(1, 0) ? 1 : 0;
Error += glm::lessThanEqual(0, 0) ? 0 : 1;
Error += glm::lessThanEqual(1, 1) ? 0 : 1;
Error += glm::lessThanEqual(0.0f, 1.0f) ? 0 : 1;
Error += glm::lessThanEqual(1.0f, 0.0f) ? 1 : 0;
Error += glm::lessThanEqual(0.0f, 0.0f) ? 0 : 1;
Error += glm::lessThanEqual(1.0f, 1.0f) ? 0 : 1;
Error += glm::lessThanEqual(0.0, 1.0) ? 0 : 1;
Error += glm::lessThanEqual(1.0, 0.0) ? 1 : 0;
Error += glm::lessThanEqual(0.0, 0.0) ? 0 : 1;
Error += glm::lessThanEqual(1.0, 1.0) ? 0 : 1;
return Error;
}
static int test_greaterThan()
{
int Error = 0;
Error += glm::greaterThan(0, 1) ? 1 : 0;
Error += glm::greaterThan(1, 0) ? 0 : 1;
Error += glm::greaterThan(0, 0) ? 1 : 0;
Error += glm::greaterThan(1, 1) ? 1 : 0;
Error += glm::greaterThan(0.0f, 1.0f) ? 1 : 0;
Error += glm::greaterThan(1.0f, 0.0f) ? 0 : 1;
Error += glm::greaterThan(0.0f, 0.0f) ? 1 : 0;
Error += glm::greaterThan(1.0f, 1.0f) ? 1 : 0;
Error += glm::greaterThan(0.0, 1.0) ? 1 : 0;
Error += glm::greaterThan(1.0, 0.0) ? 0 : 1;
Error += glm::greaterThan(0.0, 0.0) ? 1 : 0;
Error += glm::greaterThan(1.0, 1.0) ? 1 : 0;
return Error;
}
static int test_greaterThanEqual()
{
int Error = 0;
Error += glm::greaterThanEqual(0, 1) ? 1 : 0;
Error += glm::greaterThanEqual(1, 0) ? 0 : 1;
Error += glm::greaterThanEqual(0, 0) ? 0 : 1;
Error += glm::greaterThanEqual(1, 1) ? 0 : 1;
Error += glm::greaterThanEqual(0.0f, 1.0f) ? 1 : 0;
Error += glm::greaterThanEqual(1.0f, 0.0f) ? 0 : 1;
Error += glm::greaterThanEqual(0.0f, 0.0f) ? 0 : 1;
Error += glm::greaterThanEqual(1.0f, 1.0f) ? 0 : 1;
Error += glm::greaterThanEqual(0.0, 1.0) ? 1 : 0;
Error += glm::greaterThanEqual(1.0, 0.0) ? 0 : 1;
Error += glm::greaterThanEqual(0.0, 0.0) ? 0 : 1;
Error += glm::greaterThanEqual(1.0, 1.0) ? 0 : 1;
return Error;
}
static int test_equal()
{
int Error = 0;
Error += glm::equal(0, 1) ? 1 : 0;
Error += glm::equal(1, 0) ? 1 : 0;
Error += glm::equal(0, 0) ? 0 : 1;
Error += glm::equal(1, 1) ? 0 : 1;
Error += glm::equal(0.0f, 1.0f, glm::epsilon<float>()) ? 1 : 0;
Error += glm::equal(1.0f, 0.0f, glm::epsilon<float>()) ? 1 : 0;
Error += glm::equal(0.0f, 0.0f, glm::epsilon<float>()) ? 0 : 1;
Error += glm::equal(1.0f, 1.0f, glm::epsilon<float>()) ? 0 : 1;
Error += glm::equal(0.0, 1.0, glm::epsilon<double>()) ? 1 : 0;
Error += glm::equal(1.0, 0.0, glm::epsilon<double>()) ? 1 : 0;
Error += glm::equal(0.0, 0.0, glm::epsilon<double>()) ? 0 : 1;
Error += glm::equal(1.0, 1.0, glm::epsilon<double>()) ? 0 : 1;
return Error;
}
static int test_notEqual()
{
int Error = 0;
Error += glm::notEqual(0, 1) ? 0 : 1;
Error += glm::notEqual(1, 0) ? 0 : 1;
Error += glm::notEqual(0, 0) ? 1 : 0;
Error += glm::notEqual(1, 1) ? 1 : 0;
Error += glm::notEqual(0.0f, 1.0f, glm::epsilon<float>()) ? 0 : 1;
Error += glm::notEqual(1.0f, 0.0f, glm::epsilon<float>()) ? 0 : 1;
Error += glm::notEqual(0.0f, 0.0f, glm::epsilon<float>()) ? 1 : 0;
Error += glm::notEqual(1.0f, 1.0f, glm::epsilon<float>()) ? 1 : 0;
Error += glm::notEqual(0.0, 1.0, glm::epsilon<double>()) ? 0 : 1;
Error += glm::notEqual(1.0, 0.0, glm::epsilon<double>()) ? 0 : 1;
Error += glm::notEqual(0.0, 0.0, glm::epsilon<double>()) ? 1 : 0;
Error += glm::notEqual(1.0, 1.0, glm::epsilon<double>()) ? 1 : 0;
return Error;
}
static int test_any()
{
int Error = 0;
Error += glm::any(true) ? 0 : 1;
Error += glm::any(false) ? 1 : 0;
return Error;
}
static int test_all()
{
int Error = 0;
Error += glm::all(true) ? 0 : 1;
Error += glm::all(false) ? 1 : 0;
return Error;
}
static int test_not()
{
int Error = 0;
Error += glm::not_(true) ? 1 : 0;
Error += glm::not_(false) ? 0 : 1;
return Error;
}
int main()
{
int Error = 0;
Error += test_lessThan();
Error += test_lessThanEqual();
Error += test_greaterThan();
Error += test_greaterThanEqual();
Error += test_equal();
Error += test_notEqual();
Error += test_any();
Error += test_all();
Error += test_not();
return Error;
}

View File

@@ -0,0 +1,324 @@
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.g-truc.net)
///
/// Copyright (c) 2005 - 2012 G-Truc Creation (www.g-truc.net)
/// Permission is hereby granted, free of charge, to any person obtaining a copy
/// of this software and associated documentation files (the "Software"), to deal
/// in the Software without restriction, including without limitation the rights
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in
/// all copies or substantial portions of the Software.
///
/// Restrictions:
/// By making use of the Software for military purposes, you choose to make
/// a Bunny unhappy.
///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.
///
/// @file test/gtx/gtx_simd_mat4.cpp
/// @date 2010-09-16 / 2014-11-25
/// @author Christophe Riccio
///////////////////////////////////////////////////////////////////////////////////
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/quaternion.hpp>
#include <glm/gtc/random.hpp>
#include <glm/gtx/simd_vec4.hpp>
#include <glm/gtx/simd_mat4.hpp>
#include <cstdio>
#include <ctime>
#include <vector>
#if(GLM_ARCH != GLM_ARCH_PURE)
std::vector<float> test_detA(std::vector<glm::mat4> const & Data)
{
std::vector<float> Test(Data.size());
std::clock_t TimeStart = clock();
for(std::size_t i = 0; i < Test.size() - 1; ++i)
Test[i] = glm::determinant(Data[i]);
std::clock_t TimeEnd = clock();
printf("Det A: %ld\n", TimeEnd - TimeStart);
return Test;
}
std::vector<float> test_detB(std::vector<glm::mat4> const & Data)
{
std::vector<float> Test(Data.size());
std::clock_t TimeStart = clock();
for(std::size_t i = 0; i < Test.size() - 1; ++i)
{
_mm_prefetch((char*)&Data[i + 1], _MM_HINT_T0);
glm::simdMat4 m(Data[i]);
glm::simdVec4 d(glm::detail::sse_slow_det_ps((__m128 const * const)&m));
glm::vec4 v;//(d);
Test[i] = v.x;
}
std::clock_t TimeEnd = clock();
printf("Det B: %ld\n", TimeEnd - TimeStart);
return Test;
}
std::vector<float> test_detC(std::vector<glm::mat4> const & Data)
{
std::vector<float> Test(Data.size());
std::clock_t TimeStart = clock();
for(std::size_t i = 0; i < Test.size() - 1; ++i)
{
_mm_prefetch((char*)&Data[i + 1], _MM_HINT_T0);
glm::simdMat4 m(Data[i]);
glm::simdVec4 d(glm::detail::sse_det_ps((__m128 const * const)&m));
glm::vec4 v;//(d);
Test[i] = v.x;
}
std::clock_t TimeEnd = clock();
printf("Det C: %ld\n", TimeEnd - TimeStart);
return Test;
}
std::vector<float> test_detD(std::vector<glm::mat4> const & Data)
{
std::vector<float> Test(Data.size());
std::clock_t TimeStart = clock();
for(std::size_t i = 0; i < Test.size() - 1; ++i)
{
_mm_prefetch((char*)&Data[i + 1], _MM_HINT_T0);
glm::simdMat4 m(Data[i]);
glm::simdVec4 d(glm::detail::sse_detd_ps((__m128 const * const)&m));
glm::vec4 v;//(d);
Test[i] = v.x;
}
std::clock_t TimeEnd = clock();
printf("Det D: %ld\n", TimeEnd - TimeStart);
return Test;
}
void test_invA(std::vector<glm::mat4> const & Data, std::vector<glm::mat4> & Out)
{
//std::vector<float> Test(Data.size());
Out.resize(Data.size());
std::clock_t TimeStart = clock();
for(std::size_t i = 0; i < Out.size() - 1; ++i)
{
Out[i] = glm::inverse(Data[i]);
}
std::clock_t TimeEnd = clock();
printf("Inv A: %ld\n", TimeEnd - TimeStart);
}
void test_invC(std::vector<glm::mat4> const & Data, std::vector<glm::mat4> & Out)
{
//std::vector<float> Test(Data.size());
Out.resize(Data.size());
std::clock_t TimeStart = clock();
for(std::size_t i = 0; i < Out.size() - 1; ++i)
{
_mm_prefetch((char*)&Data[i + 1], _MM_HINT_T0);
glm::simdMat4 m(Data[i]);
glm::simdMat4 o;
glm::detail::sse_inverse_fast_ps((__m128 const * const)&m, (__m128 *)&o);
Out[i] = *(glm::mat4*)&o;
}
std::clock_t TimeEnd = clock();
printf("Inv C: %ld\n", TimeEnd - TimeStart);
}
void test_invD(std::vector<glm::mat4> const & Data, std::vector<glm::mat4> & Out)
{
//std::vector<float> Test(Data.size());
Out.resize(Data.size());
std::clock_t TimeStart = clock();
for(std::size_t i = 0; i < Out.size() - 1; ++i)
{
_mm_prefetch((char*)&Data[i + 1], _MM_HINT_T0);
glm::simdMat4 m(Data[i]);
glm::simdMat4 o;
glm::detail::sse_inverse_ps((__m128 const * const)&m, (__m128 *)&o);
Out[i] = *(glm::mat4*)&o;
}
std::clock_t TimeEnd = clock();
printf("Inv D: %ld\n", TimeEnd - TimeStart);
}
void test_mulA(std::vector<glm::mat4> const & Data, std::vector<glm::mat4> & Out)
{
//std::vector<float> Test(Data.size());
Out.resize(Data.size());
std::clock_t TimeStart = clock();
for(std::size_t i = 0; i < Out.size() - 1; ++i)
{
Out[i] = Data[i] * Data[i];
}
std::clock_t TimeEnd = clock();
printf("Mul A: %ld\n", TimeEnd - TimeStart);
}
void test_mulD(std::vector<glm::mat4> const & Data, std::vector<glm::mat4> & Out)
{
//std::vector<float> Test(Data.size());
Out.resize(Data.size());
std::clock_t TimeStart = clock();
for(std::size_t i = 0; i < Out.size() - 1; ++i)
{
_mm_prefetch((char*)&Data[i + 1], _MM_HINT_T0);
glm::simdMat4 m(Data[i]);
glm::simdMat4 o;
glm::detail::sse_mul_ps((__m128 const * const)&m, (__m128 const * const)&m, (__m128*)&o);
Out[i] = *(glm::mat4*)&o;
}
std::clock_t TimeEnd = clock();
printf("Mul D: %ld\n", TimeEnd - TimeStart);
}
int test_compute_glm()
{
return 0;
}
int test_compute_gtx()
{
std::vector<glm::vec4> Output(1000000);
std::clock_t TimeStart = clock();
for(std::size_t k = 0; k < Output.size(); ++k)
{
float i = float(k) / 1000.f + 0.001f;
glm::vec3 A = glm::normalize(glm::vec3(i));
glm::vec3 B = glm::cross(A, glm::normalize(glm::vec3(1, 1, 2)));
glm::mat4 C = glm::rotate(glm::mat4(1.0f), i, B);
glm::mat4 D = glm::scale(C, glm::vec3(0.8f, 1.0f, 1.2f));
glm::mat4 E = glm::translate(D, glm::vec3(1.4f, 1.2f, 1.1f));
glm::mat4 F = glm::perspective(i, 1.5f, 0.1f, 1000.f);
glm::mat4 G = glm::inverse(F * E);
glm::vec3 H = glm::unProject(glm::vec3(i), G, F, E[3]);
glm::vec3 I = glm::any(glm::isnan(glm::project(H, G, F, E[3]))) ? glm::vec3(2) : glm::vec3(1);
glm::mat4 J = glm::lookAt(glm::normalize(glm::max(B, glm::vec3(0.001f))), H, I);
glm::mat4 K = glm::transpose(J);
glm::quat L = glm::normalize(glm::quat_cast(K));
glm::vec4 M = L * glm::smoothstep(K[3], J[3], glm::vec4(i));
glm::mat4 N = glm::mat4(glm::normalize(glm::max(M, glm::vec4(0.001f))), K[3], J[3], glm::vec4(i));
glm::mat4 O = N * glm::inverse(N);
glm::vec4 P = O * glm::reflect(N[3], glm::vec4(A, 1.0f));
glm::vec4 Q = glm::vec4(glm::dot(M, P));
glm::vec4 R = glm::quat(Q.w, glm::vec3(Q)) * P;
Output[k] = R;
}
std::clock_t TimeEnd = clock();
printf("test_compute_gtx: %ld\n", TimeEnd - TimeStart);
return 0;
}
int main()
{
int Error = 0;
std::vector<glm::mat4> Data(64 * 64 * 1);
for(std::size_t i = 0; i < Data.size(); ++i)
Data[i] = glm::mat4(
glm::vec4(glm::linearRand(glm::vec4(-2.0f), glm::vec4(2.0f))),
glm::vec4(glm::linearRand(glm::vec4(-2.0f), glm::vec4(2.0f))),
glm::vec4(glm::linearRand(glm::vec4(-2.0f), glm::vec4(2.0f))),
glm::vec4(glm::linearRand(glm::vec4(-2.0f), glm::vec4(2.0f))));
{
std::vector<glm::mat4> TestInvA;
test_invA(Data, TestInvA);
}
{
std::vector<glm::mat4> TestInvC;
test_invC(Data, TestInvC);
}
{
std::vector<glm::mat4> TestInvD;
test_invD(Data, TestInvD);
}
{
std::vector<glm::mat4> TestA;
test_mulA(Data, TestA);
}
{
std::vector<glm::mat4> TestD;
test_mulD(Data, TestD);
}
{
std::vector<float> TestDetA = test_detA(Data);
std::vector<float> TestDetB = test_detB(Data);
std::vector<float> TestDetD = test_detD(Data);
std::vector<float> TestDetC = test_detC(Data);
for(std::size_t i = 0; i < TestDetA.size(); ++i)
if(TestDetA[i] != TestDetB[i] && TestDetC[i] != TestDetB[i] && TestDetC[i] != TestDetD[i])
return 1;
}
// shuffle test
glm::simdVec4 A(1.0f, 2.0f, 3.0f, 4.0f);
glm::simdVec4 B(5.0f, 6.0f, 7.0f, 8.0f);
//__m128 C = _mm_shuffle_ps(A.Data, B.Data, _MM_SHUFFLE(1, 0, 1, 0));
Error += test_compute_glm();
Error += test_compute_gtx();
float Det = glm::determinant(glm::simdMat4(1.0));
Error += Det == 1.0f ? 0 : 1;
glm::simdMat4 D = glm::matrixCompMult(glm::simdMat4(1.0), glm::simdMat4(1.0));
return Error;
}
#else
int main()
{
int Error = 0;
return Error;
}
#endif//(GLM_ARCH != GLM_ARCH_PURE)

View File

@@ -0,0 +1,71 @@
///////////////////////////////////////////////////////////////////////////////////
/// OpenGL Mathematics (glm.g-truc.net)
///
/// Copyright (c) 2005 - 2012 G-Truc Creation (www.g-truc.net)
/// Permission is hereby granted, free of charge, to any person obtaining a copy
/// of this software and associated documentation files (the "Software"), to deal
/// in the Software without restriction, including without limitation the rights
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in
/// all copies or substantial portions of the Software.
///
/// Restrictions:
/// By making use of the Software for military purposes, you choose to make
/// a Bunny unhappy.
///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.
///
/// @file test/gtx/gtx_simd_vec4.cpp
/// @date 2010-09-16 / 2014-11-25
/// @author Christophe Riccio
///////////////////////////////////////////////////////////////////////////////////
#include <glm/glm.hpp>
#include <glm/gtx/simd_vec4.hpp>
#include <cstdio>
#if(GLM_ARCH != GLM_ARCH_PURE)
int main()
{
glm::simdVec4 A1(0.0f, 0.1f, 0.2f, 0.3f);
glm::simdVec4 B1(0.4f, 0.5f, 0.6f, 0.7f);
glm::simdVec4 C1 = A1 + B1;
glm::simdVec4 D1 = A1.swizzle<glm::X, glm::Z, glm::Y, glm::W>();
glm::simdVec4 E1(glm::vec4(1.0f));
glm::vec4 F1 = glm::vec4_cast(E1);
//glm::vec4 G1(E1);
//printf("A1(%2.3f, %2.3f, %2.3f, %2.3f)\n", A1.x, A1.y, A1.z, A1.w);
//printf("B1(%2.3f, %2.3f, %2.3f, %2.3f)\n", B1.x, B1.y, B1.z, B1.w);
//printf("C1(%2.3f, %2.3f, %2.3f, %2.3f)\n", C1.x, C1.y, C1.z, C1.w);
//printf("D1(%2.3f, %2.3f, %2.3f, %2.3f)\n", D1.x, D1.y, D1.z, D1.w);
__m128 value = _mm_set1_ps(0.0f);
__m128 data = _mm_cmpeq_ps(value, value);
__m128 add0 = _mm_add_ps(data, data);
glm::simdVec4 GNI(add0);
return 0;
}
#else
int main()
{
int Error = 0;
return Error;
}
#endif//(GLM_ARCH != GLM_ARCH_PURE)

View File

@@ -0,0 +1,100 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/vec2.hpp>
#include <glm/vec3.hpp>
#include <glm/vec4.hpp>
#include <glm/gtx/spline.hpp>
namespace catmullRom
{
int test()
{
int Error(0);
glm::vec2 Result2 = glm::catmullRom(
glm::vec2(0.0f, 0.0f),
glm::vec2(1.0f, 0.0f),
glm::vec2(1.0f, 1.0f),
glm::vec2(0.0f, 1.0f), 0.5f);
glm::vec3 Result3 = glm::catmullRom(
glm::vec3(0.0f, 0.0f, 0.0f),
glm::vec3(1.0f, 0.0f, 0.0f),
glm::vec3(1.0f, 1.0f, 0.0f),
glm::vec3(0.0f, 1.0f, 0.0f), 0.5f);
glm::vec4 Result4 = glm::catmullRom(
glm::vec4(0.0f, 0.0f, 0.0f, 1.0f),
glm::vec4(1.0f, 0.0f, 0.0f, 1.0f),
glm::vec4(1.0f, 1.0f, 0.0f, 1.0f),
glm::vec4(0.0f, 1.0f, 0.0f, 1.0f), 0.5f);
return Error;
}
}//catmullRom
namespace hermite
{
int test()
{
int Error(0);
glm::vec2 Result2 = glm::hermite(
glm::vec2(0.0f, 0.0f),
glm::vec2(1.0f, 0.0f),
glm::vec2(1.0f, 1.0f),
glm::vec2(0.0f, 1.0f), 0.5f);
glm::vec3 Result3 = glm::hermite(
glm::vec3(0.0f, 0.0f, 0.0f),
glm::vec3(1.0f, 0.0f, 0.0f),
glm::vec3(1.0f, 1.0f, 0.0f),
glm::vec3(0.0f, 1.0f, 0.0f), 0.5f);
glm::vec4 Result4 = glm::hermite(
glm::vec4(0.0f, 0.0f, 0.0f, 1.0f),
glm::vec4(1.0f, 0.0f, 0.0f, 1.0f),
glm::vec4(1.0f, 1.0f, 0.0f, 1.0f),
glm::vec4(0.0f, 1.0f, 0.0f, 1.0f), 0.5f);
return Error;
}
}//catmullRom
namespace cubic
{
int test()
{
int Error(0);
glm::vec2 Result2 = glm::cubic(
glm::vec2(0.0f, 0.0f),
glm::vec2(1.0f, 0.0f),
glm::vec2(1.0f, 1.0f),
glm::vec2(0.0f, 1.0f), 0.5f);
glm::vec3 Result3 = glm::cubic(
glm::vec3(0.0f, 0.0f, 0.0f),
glm::vec3(1.0f, 0.0f, 0.0f),
glm::vec3(1.0f, 1.0f, 0.0f),
glm::vec3(0.0f, 1.0f, 0.0f), 0.5f);
glm::vec4 Result = glm::cubic(
glm::vec4(0.0f, 0.0f, 0.0f, 1.0f),
glm::vec4(1.0f, 0.0f, 0.0f, 1.0f),
glm::vec4(1.0f, 1.0f, 0.0f, 1.0f),
glm::vec4(0.0f, 1.0f, 0.0f, 1.0f), 0.5f);
return Error;
}
}//catmullRom
int main()
{
int Error(0);
Error += catmullRom::test();
Error += hermite::test();
Error += cubic::test();
return Error;
}

View File

@@ -0,0 +1,155 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/glm.hpp>
#include <glm/gtx/string_cast.hpp>
#include <limits>
int test_string_cast_vector()
{
int Error = 0;
{
glm::vec2 A1(1, 2);
std::string A2 = glm::to_string(A1);
Error += A2 != std::string("vec2(1.000000, 2.000000)") ? 1 : 0;
glm::vec3 B1(1, 2, 3);
std::string B2 = glm::to_string(B1);
Error += B2 != std::string("vec3(1.000000, 2.000000, 3.000000)") ? 1 : 0;
glm::vec4 C1(1, 2, 3, 4);
std::string C2 = glm::to_string(C1);
Error += C2 != std::string("vec4(1.000000, 2.000000, 3.000000, 4.000000)") ? 1 : 0;
glm::dvec2 J1(1, 2);
std::string J2 = glm::to_string(J1);
Error += J2 != std::string("dvec2(1.000000, 2.000000)") ? 1 : 0;
glm::dvec3 K1(1, 2, 3);
std::string K2 = glm::to_string(K1);
Error += K2 != std::string("dvec3(1.000000, 2.000000, 3.000000)") ? 1 : 0;
glm::dvec4 L1(1, 2, 3, 4);
std::string L2 = glm::to_string(L1);
Error += L2 != std::string("dvec4(1.000000, 2.000000, 3.000000, 4.000000)") ? 1 : 0;
}
{
glm::bvec2 M1(false, true);
std::string M2 = glm::to_string(M1);
Error += M2 != std::string("bvec2(false, true)") ? 1 : 0;
glm::bvec3 O1(false, true, false);
std::string O2 = glm::to_string(O1);
Error += O2 != std::string("bvec3(false, true, false)") ? 1 : 0;
glm::bvec4 P1(false, true, false, true);
std::string P2 = glm::to_string(P1);
Error += P2 != std::string("bvec4(false, true, false, true)") ? 1 : 0;
}
{
glm::ivec2 D1(1, 2);
std::string D2 = glm::to_string(D1);
Error += D2 != std::string("ivec2(1, 2)") ? 1 : 0;
glm::ivec3 E1(1, 2, 3);
std::string E2 = glm::to_string(E1);
Error += E2 != std::string("ivec3(1, 2, 3)") ? 1 : 0;
glm::ivec4 F1(1, 2, 3, 4);
std::string F2 = glm::to_string(F1);
Error += F2 != std::string("ivec4(1, 2, 3, 4)") ? 1 : 0;
}
{
glm::i8vec2 D1(1, 2);
std::string D2 = glm::to_string(D1);
Error += D2 != std::string("i8vec2(1, 2)") ? 1 : 0;
glm::i8vec3 E1(1, 2, 3);
std::string E2 = glm::to_string(E1);
Error += E2 != std::string("i8vec3(1, 2, 3)") ? 1 : 0;
glm::i8vec4 F1(1, 2, 3, 4);
std::string F2 = glm::to_string(F1);
Error += F2 != std::string("i8vec4(1, 2, 3, 4)") ? 1 : 0;
}
{
glm::i16vec2 D1(1, 2);
std::string D2 = glm::to_string(D1);
Error += D2 != std::string("i16vec2(1, 2)") ? 1 : 0;
glm::i16vec3 E1(1, 2, 3);
std::string E2 = glm::to_string(E1);
Error += E2 != std::string("i16vec3(1, 2, 3)") ? 1 : 0;
glm::i16vec4 F1(1, 2, 3, 4);
std::string F2 = glm::to_string(F1);
Error += F2 != std::string("i16vec4(1, 2, 3, 4)") ? 1 : 0;
}
{
glm::i64vec2 D1(1, 2);
std::string D2 = glm::to_string(D1);
Error += D2 != std::string("i64vec2(1, 2)") ? 1 : 0;
glm::i64vec3 E1(1, 2, 3);
std::string E2 = glm::to_string(E1);
Error += E2 != std::string("i64vec3(1, 2, 3)") ? 1 : 0;
glm::i64vec4 F1(1, 2, 3, 4);
std::string F2 = glm::to_string(F1);
Error += F2 != std::string("i64vec4(1, 2, 3, 4)") ? 1 : 0;
}
return Error;
}
int test_string_cast_matrix()
{
int Error = 0;
glm::mat2x2 A1(1.000000, 2.000000, 3.000000, 4.000000);
std::string A2 = glm::to_string(A1);
Error += A2 != std::string("mat2x2((1.000000, 2.000000), (3.000000, 4.000000))") ? 1 : 0;
return Error;
}
int test_string_cast_quaternion()
{
int Error = 0;
glm::quat Q0 = glm::quat(1.0f, 2.0f, 3.0f, 4.0f);
std::string S0 = glm::to_string(Q0);
Error += S0 != std::string("quat(1.000000, {2.000000, 3.000000, 4.000000})") ? 1 : 0;
return Error;
}
int test_string_cast_dual_quaternion()
{
int Error = 0;
glm::dualquat Q0 = glm::dualquat(glm::quat(1.0f, 2.0f, 3.0f, 4.0f), glm::quat(5.0f, 6.0f, 7.0f, 8.0f));
std::string S0 = glm::to_string(Q0);
Error += S0 != std::string("dualquat((1.000000, {2.000000, 3.000000, 4.000000}), (5.000000, {6.000000, 7.000000, 8.000000}))") ? 1 : 0;
return Error;
}
int main()
{
int Error = 0;
Error += test_string_cast_vector();
Error += test_string_cast_matrix();
Error += test_string_cast_quaternion();
Error += test_string_cast_dual_quaternion();
return Error;
}

View File

@@ -0,0 +1,22 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/vec2.hpp>
#include <glm/gtx/texture.hpp>
int test_levels()
{
int Error = 0;
int const Levels = glm::levels(glm::ivec2(3, 2));
Error += Levels == 2 ? 0 : 1;
return Error;
}
int main()
{
int Error = 0;
Error += test_levels();
return Error;
}

View File

@@ -0,0 +1,114 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/type_aligned.hpp>
#include <cstdio>
int test_decl()
{
int Error(0);
{
struct S1
{
glm::aligned_vec4 B;
};
struct S2
{
glm::vec4 B;
};
std::printf("vec4 - Aligned: %d, unaligned: %d\n", static_cast<int>(sizeof(S1)), static_cast<int>(sizeof(S2)));
Error += sizeof(S1) >= sizeof(S2) ? 0 : 1;
}
{
struct S1
{
bool A;
glm::vec3 B;
};
struct S2
{
bool A;
glm::aligned_vec3 B;
};
std::printf("vec3 - Aligned: %d, unaligned: %d\n", static_cast<int>(sizeof(S1)), static_cast<int>(sizeof(S2)));
Error += sizeof(S1) <= sizeof(S2) ? 0 : 1;
}
{
struct S1
{
bool A;
glm::aligned_vec4 B;
};
struct S2
{
bool A;
glm::vec4 B;
};
std::printf("vec4 - Aligned: %d, unaligned: %d\n", static_cast<int>(sizeof(S1)), static_cast<int>(sizeof(S2)));
Error += sizeof(S1) >= sizeof(S2) ? 0 : 1;
}
{
struct S1
{
bool A;
glm::aligned_dvec4 B;
};
struct S2
{
bool A;
glm::dvec4 B;
};
std::printf("dvec4 - Aligned: %d, unaligned: %d\n", static_cast<int>(sizeof(S1)), static_cast<int>(sizeof(S2)));
Error += sizeof(S1) >= sizeof(S2) ? 0 : 1;
}
return Error;
}
template<typename genType>
void print(genType const& Mat0)
{
std::printf("mat4(\n");
std::printf("\tvec4(%2.9f, %2.9f, %2.9f, %2.9f)\n", static_cast<double>(Mat0[0][0]), static_cast<double>(Mat0[0][1]), static_cast<double>(Mat0[0][2]), static_cast<double>(Mat0[0][3]));
std::printf("\tvec4(%2.9f, %2.9f, %2.9f, %2.9f)\n", static_cast<double>(Mat0[1][0]), static_cast<double>(Mat0[1][1]), static_cast<double>(Mat0[1][2]), static_cast<double>(Mat0[1][3]));
std::printf("\tvec4(%2.9f, %2.9f, %2.9f, %2.9f)\n", static_cast<double>(Mat0[2][0]), static_cast<double>(Mat0[2][1]), static_cast<double>(Mat0[2][2]), static_cast<double>(Mat0[2][3]));
std::printf("\tvec4(%2.9f, %2.9f, %2.9f, %2.9f))\n\n", static_cast<double>(Mat0[3][0]), static_cast<double>(Mat0[3][1]), static_cast<double>(Mat0[3][2]), static_cast<double>(Mat0[3][3]));
}
int perf_mul()
{
int Error = 0;
glm::mat4 A(1.0f);
glm::mat4 B(1.0f);
glm::mat4 C = A * B;
print(C);
return Error;
}
int main()
{
int Error(0);
Error += test_decl();
Error += perf_mul();
return Error;
}

View File

@@ -0,0 +1,13 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/vec4.hpp>
#include <glm/gtx/type_trait.hpp>
int main()
{
int Error = 0;
return Error;
}

View File

@@ -0,0 +1,11 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/vec_swizzle.hpp>
int main()
{
int Error = 0;
return Error;
}

View File

@@ -0,0 +1,59 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtc/constants.hpp>
#include <glm/gtx/vector_angle.hpp>
#include <limits>
int test_angle()
{
int Error = 0;
float AngleA = glm::angle(glm::vec2(1, 0), glm::normalize(glm::vec2(1, 1)));
Error += glm::epsilonEqual(AngleA, glm::pi<float>() * 0.25f, 0.01f) ? 0 : 1;
float AngleB = glm::angle(glm::vec3(1, 0, 0), glm::normalize(glm::vec3(1, 1, 0)));
Error += glm::epsilonEqual(AngleB, glm::pi<float>() * 0.25f, 0.01f) ? 0 : 1;
float AngleC = glm::angle(glm::vec4(1, 0, 0, 0), glm::normalize(glm::vec4(1, 1, 0, 0)));
Error += glm::epsilonEqual(AngleC, glm::pi<float>() * 0.25f, 0.01f) ? 0 : 1;
return Error;
}
int test_orientedAngle_vec2()
{
int Error = 0;
float AngleA = glm::orientedAngle(glm::vec2(1, 0), glm::normalize(glm::vec2(1, 1)));
Error += glm::epsilonEqual(AngleA, glm::pi<float>() * 0.25f, 0.01f) ? 0 : 1;
float AngleB = glm::orientedAngle(glm::vec2(0, 1), glm::normalize(glm::vec2(1, 1)));
Error += glm::epsilonEqual(AngleB, -glm::pi<float>() * 0.25f, 0.01f) ? 0 : 1;
float AngleC = glm::orientedAngle(glm::normalize(glm::vec2(1, 1)), glm::vec2(0, 1));
Error += glm::epsilonEqual(AngleC, glm::pi<float>() * 0.25f, 0.01f) ? 0 : 1;
return Error;
}
int test_orientedAngle_vec3()
{
int Error = 0;
float AngleA = glm::orientedAngle(glm::vec3(1, 0, 0), glm::normalize(glm::vec3(1, 1, 0)), glm::vec3(0, 0, 1));
Error += glm::epsilonEqual(AngleA, glm::pi<float>() * 0.25f, 0.01f) ? 0 : 1;
float AngleB = glm::orientedAngle(glm::vec3(0, 1, 0), glm::normalize(glm::vec3(1, 1, 0)), glm::vec3(0, 0, 1));
Error += glm::epsilonEqual(AngleB, -glm::pi<float>() * 0.25f, 0.01f) ? 0 : 1;
float AngleC = glm::orientedAngle(glm::normalize(glm::vec3(1, 1, 0)), glm::vec3(0, 1, 0), glm::vec3(0, 0, 1));
Error += glm::epsilonEqual(AngleC, glm::pi<float>() * 0.25f, 0.01f) ? 0 : 1;
return Error;
}
int main()
{
int Error(0);
Error += test_angle();
Error += test_orientedAngle_vec2();
Error += test_orientedAngle_vec3();
return Error;
}

View File

@@ -0,0 +1,82 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/vec2.hpp>
#include <glm/vec3.hpp>
#include <glm/vec4.hpp>
#include <glm/gtx/vector_query.hpp>
int test_areCollinear()
{
int Error(0);
{
bool TestA = glm::areCollinear(glm::vec2(-1), glm::vec2(1), 0.00001f);
Error += TestA ? 0 : 1;
}
{
bool TestA = glm::areCollinear(glm::vec3(-1), glm::vec3(1), 0.00001f);
Error += TestA ? 0 : 1;
}
{
bool TestA = glm::areCollinear(glm::vec4(-1), glm::vec4(1), 0.00001f);
Error += TestA ? 0 : 1;
}
return Error;
}
int test_areOrthogonal()
{
int Error(0);
bool TestA = glm::areOrthogonal(glm::vec2(1, 0), glm::vec2(0, 1), 0.00001f);
Error += TestA ? 0 : 1;
return Error;
}
int test_isNormalized()
{
int Error(0);
bool TestA = glm::isNormalized(glm::vec4(1, 0, 0, 0), 0.00001f);
Error += TestA ? 0 : 1;
return Error;
}
int test_isNull()
{
int Error(0);
bool TestA = glm::isNull(glm::vec4(0), 0.00001f);
Error += TestA ? 0 : 1;
return Error;
}
int test_areOrthonormal()
{
int Error(0);
bool TestA = glm::areOrthonormal(glm::vec2(1, 0), glm::vec2(0, 1), 0.00001f);
Error += TestA ? 0 : 1;
return Error;
}
int main()
{
int Error(0);
Error += test_areCollinear();
Error += test_areOrthogonal();
Error += test_isNormalized();
Error += test_isNull();
Error += test_areOrthonormal();
return Error;
}

View File

@@ -0,0 +1,190 @@
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/wrap.hpp>
#include <glm/gtc/epsilon.hpp>
namespace clamp
{
int test()
{
int Error(0);
float A = glm::clamp(0.5f);
Error += glm::epsilonEqual(A, 0.5f, 0.00001f) ? 0 : 1;
float B = glm::clamp(0.0f);
Error += glm::epsilonEqual(B, 0.0f, 0.00001f) ? 0 : 1;
float C = glm::clamp(1.0f);
Error += glm::epsilonEqual(C, 1.0f, 0.00001f) ? 0 : 1;
float D = glm::clamp(-0.5f);
Error += glm::epsilonEqual(D, 0.0f, 0.00001f) ? 0 : 1;
float E = glm::clamp(1.5f);
Error += glm::epsilonEqual(E, 1.0f, 0.00001f) ? 0 : 1;
glm::vec2 K = glm::clamp(glm::vec2(0.5f));
Error += glm::all(glm::epsilonEqual(K, glm::vec2(0.5f), glm::vec2(0.00001f))) ? 0 : 1;
glm::vec3 L = glm::clamp(glm::vec3(0.5f));
Error += glm::all(glm::epsilonEqual(L, glm::vec3(0.5f), glm::vec3(0.00001f))) ? 0 : 1;
glm::vec4 M = glm::clamp(glm::vec4(0.5f));
Error += glm::all(glm::epsilonEqual(M, glm::vec4(0.5f), glm::vec4(0.00001f))) ? 0 : 1;
glm::vec1 N = glm::clamp(glm::vec1(0.5f));
Error += glm::all(glm::epsilonEqual(N, glm::vec1(0.5f), glm::vec1(0.00001f))) ? 0 : 1;
return Error;
}
}//namespace clamp
namespace repeat
{
int test()
{
int Error(0);
float A = glm::repeat(0.5f);
Error += glm::epsilonEqual(A, 0.5f, 0.00001f) ? 0 : 1;
float B = glm::repeat(0.0f);
Error += glm::epsilonEqual(B, 0.0f, 0.00001f) ? 0 : 1;
float C = glm::repeat(1.0f);
Error += glm::epsilonEqual(C, 0.0f, 0.00001f) ? 0 : 1;
float D = glm::repeat(-0.5f);
Error += glm::epsilonEqual(D, 0.5f, 0.00001f) ? 0 : 1;
float E = glm::repeat(1.5f);
Error += glm::epsilonEqual(E, 0.5f, 0.00001f) ? 0 : 1;
float F = glm::repeat(0.9f);
Error += glm::epsilonEqual(F, 0.9f, 0.00001f) ? 0 : 1;
glm::vec2 K = glm::repeat(glm::vec2(0.5f));
Error += glm::all(glm::epsilonEqual(K, glm::vec2(0.5f), glm::vec2(0.00001f))) ? 0 : 1;
glm::vec3 L = glm::repeat(glm::vec3(0.5f));
Error += glm::all(glm::epsilonEqual(L, glm::vec3(0.5f), glm::vec3(0.00001f))) ? 0 : 1;
glm::vec4 M = glm::repeat(glm::vec4(0.5f));
Error += glm::all(glm::epsilonEqual(M, glm::vec4(0.5f), glm::vec4(0.00001f))) ? 0 : 1;
glm::vec1 N = glm::repeat(glm::vec1(0.5f));
Error += glm::all(glm::epsilonEqual(N, glm::vec1(0.5f), glm::vec1(0.00001f))) ? 0 : 1;
return Error;
}
}//namespace repeat
namespace mirrorClamp
{
int test()
{
int Error(0);
float A = glm::mirrorClamp(0.5f);
Error += glm::epsilonEqual(A, 0.5f, 0.00001f) ? 0 : 1;
float B = glm::mirrorClamp(0.0f);
Error += glm::epsilonEqual(B, 0.0f, 0.00001f) ? 0 : 1;
float C = glm::mirrorClamp(1.1f);
Error += glm::epsilonEqual(C, 0.1f, 0.00001f) ? 0 : 1;
float D = glm::mirrorClamp(-0.5f);
Error += glm::epsilonEqual(D, 0.5f, 0.00001f) ? 0 : 1;
float E = glm::mirrorClamp(1.5f);
Error += glm::epsilonEqual(E, 0.5f, 0.00001f) ? 0 : 1;
float F = glm::mirrorClamp(0.9f);
Error += glm::epsilonEqual(F, 0.9f, 0.00001f) ? 0 : 1;
float G = glm::mirrorClamp(3.1f);
Error += glm::epsilonEqual(G, 0.1f, 0.00001f) ? 0 : 1;
float H = glm::mirrorClamp(-3.1f);
Error += glm::epsilonEqual(H, 0.1f, 0.00001f) ? 0 : 1;
float I = glm::mirrorClamp(-0.9f);
Error += glm::epsilonEqual(I, 0.9f, 0.00001f) ? 0 : 1;
glm::vec2 K = glm::mirrorClamp(glm::vec2(0.5f));
Error += glm::all(glm::epsilonEqual(K, glm::vec2(0.5f), glm::vec2(0.00001f))) ? 0 : 1;
glm::vec3 L = glm::mirrorClamp(glm::vec3(0.5f));
Error += glm::all(glm::epsilonEqual(L, glm::vec3(0.5f), glm::vec3(0.00001f))) ? 0 : 1;
glm::vec4 M = glm::mirrorClamp(glm::vec4(0.5f));
Error += glm::all(glm::epsilonEqual(M, glm::vec4(0.5f), glm::vec4(0.00001f))) ? 0 : 1;
glm::vec1 N = glm::mirrorClamp(glm::vec1(0.5f));
Error += glm::all(glm::epsilonEqual(N, glm::vec1(0.5f), glm::vec1(0.00001f))) ? 0 : 1;
return Error;
}
}//namespace mirrorClamp
namespace mirrorRepeat
{
int test()
{
int Error(0);
float A = glm::mirrorRepeat(0.5f);
Error += glm::epsilonEqual(A, 0.5f, 0.00001f) ? 0 : 1;
float B = glm::mirrorRepeat(0.0f);
Error += glm::epsilonEqual(B, 0.0f, 0.00001f) ? 0 : 1;
float C = glm::mirrorRepeat(1.0f);
Error += glm::epsilonEqual(C, 1.0f, 0.00001f) ? 0 : 1;
float D = glm::mirrorRepeat(-0.5f);
Error += glm::epsilonEqual(D, 0.5f, 0.00001f) ? 0 : 1;
float E = glm::mirrorRepeat(1.5f);
Error += glm::epsilonEqual(E, 0.5f, 0.00001f) ? 0 : 1;
float F = glm::mirrorRepeat(0.9f);
Error += glm::epsilonEqual(F, 0.9f, 0.00001f) ? 0 : 1;
float G = glm::mirrorRepeat(3.0f);
Error += glm::epsilonEqual(G, 1.0f, 0.00001f) ? 0 : 1;
float H = glm::mirrorRepeat(-3.0f);
Error += glm::epsilonEqual(H, 1.0f, 0.00001f) ? 0 : 1;
float I = glm::mirrorRepeat(-1.0f);
Error += glm::epsilonEqual(I, 1.0f, 0.00001f) ? 0 : 1;
glm::vec2 K = glm::mirrorRepeat(glm::vec2(0.5f));
Error += glm::all(glm::epsilonEqual(K, glm::vec2(0.5f), glm::vec2(0.00001f))) ? 0 : 1;
glm::vec3 L = glm::mirrorRepeat(glm::vec3(0.5f));
Error += glm::all(glm::epsilonEqual(L, glm::vec3(0.5f), glm::vec3(0.00001f))) ? 0 : 1;
glm::vec4 M = glm::mirrorRepeat(glm::vec4(0.5f));
Error += glm::all(glm::epsilonEqual(M, glm::vec4(0.5f), glm::vec4(0.00001f))) ? 0 : 1;
glm::vec1 N = glm::mirrorRepeat(glm::vec1(0.5f));
Error += glm::all(glm::epsilonEqual(N, glm::vec1(0.5f), glm::vec1(0.00001f))) ? 0 : 1;
return Error;
}
}//namespace mirrorRepeat
int main()
{
int Error(0);
Error += clamp::test();
Error += repeat::test();
Error += mirrorClamp::test();
Error += mirrorRepeat::test();
return Error;
}