mirror of
https://github.com/g-truc/glm.git
synced 2024-11-26 18:24:35 +00:00
Added more geometric function tests
This commit is contained in:
parent
393c1dae41
commit
1a4bc0d8a5
@ -37,7 +37,7 @@ More informations in GLM manual:
|
||||
http://glm.g-truc.net/glm.pdf
|
||||
|
||||
================================================================================
|
||||
GLM 0.9.6.0: 2014-XX-XX
|
||||
GLM 0.9.6.0: 2014-11-XX
|
||||
--------------------------------------------------------------------------------
|
||||
Features:
|
||||
- Added transparent use of SIMD instructions for vec4 and mat4 types
|
||||
|
@ -2,15 +2,120 @@
|
||||
// OpenGL Mathematics Copyright (c) 2005 - 2014 G-Truc Creation (www.g-truc.net)
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Created : 2011-01-15
|
||||
// Updated : 2011-11-14
|
||||
// Updated : 2014-11-16
|
||||
// Licence : This source is under MIT licence
|
||||
// File : test/core/func_geometric.cpp
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <glm/geometric.hpp>
|
||||
#include <glm/vector_relational.hpp>
|
||||
#include <glm/gtc/epsilon.hpp>
|
||||
#include <glm/gtc/vec1.hpp>
|
||||
#include <limits>
|
||||
|
||||
int test_reflect()
|
||||
namespace length
|
||||
{
|
||||
int test()
|
||||
{
|
||||
float Length1 = glm::length(glm::vec1(1));
|
||||
float Length2 = glm::length(glm::vec2(1, 0));
|
||||
float Length3 = glm::length(glm::vec3(1, 0, 0));
|
||||
float Length4 = glm::length(glm::vec4(1, 0, 0, 0));
|
||||
|
||||
int Error = 0;
|
||||
|
||||
Error += glm::abs(Length1 - 1.0f) < std::numeric_limits<float>::epsilon() ? 0 : 1;
|
||||
Error += glm::abs(Length2 - 1.0f) < std::numeric_limits<float>::epsilon() ? 0 : 1;
|
||||
Error += glm::abs(Length3 - 1.0f) < std::numeric_limits<float>::epsilon() ? 0 : 1;
|
||||
Error += glm::abs(Length4 - 1.0f) < std::numeric_limits<float>::epsilon() ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
}//namespace length
|
||||
|
||||
namespace distance
|
||||
{
|
||||
int test()
|
||||
{
|
||||
float Distance1 = glm::distance(glm::vec1(1), glm::vec1(1));
|
||||
float Distance2 = glm::distance(glm::vec2(1, 0), glm::vec2(1, 0));
|
||||
float Distance3 = glm::distance(glm::vec3(1, 0, 0), glm::vec3(1, 0, 0));
|
||||
float Distance4 = glm::distance(glm::vec4(1, 0, 0, 0), glm::vec4(1, 0, 0, 0));
|
||||
|
||||
int Error = 0;
|
||||
|
||||
Error += glm::abs(Distance1) < std::numeric_limits<float>::epsilon() ? 0 : 1;
|
||||
Error += glm::abs(Distance2) < std::numeric_limits<float>::epsilon() ? 0 : 1;
|
||||
Error += glm::abs(Distance3) < std::numeric_limits<float>::epsilon() ? 0 : 1;
|
||||
Error += glm::abs(Distance4) < std::numeric_limits<float>::epsilon() ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
}//namespace distance
|
||||
|
||||
namespace dot
|
||||
{
|
||||
int test()
|
||||
{
|
||||
float Dot1 = glm::dot(glm::vec1(1), glm::vec1(1));
|
||||
float Dot2 = glm::dot(glm::vec2(1), glm::vec2(1));
|
||||
float Dot3 = glm::dot(glm::vec3(1), glm::vec3(1));
|
||||
float Dot4 = glm::dot(glm::vec4(1), glm::vec4(1));
|
||||
|
||||
int Error = 0;
|
||||
|
||||
Error += glm::abs(Dot1 - 1.0f) < std::numeric_limits<float>::epsilon() ? 0 : 1;
|
||||
Error += glm::abs(Dot2 - 2.0f) < std::numeric_limits<float>::epsilon() ? 0 : 1;
|
||||
Error += glm::abs(Dot3 - 3.0f) < std::numeric_limits<float>::epsilon() ? 0 : 1;
|
||||
Error += glm::abs(Dot4 - 4.0f) < std::numeric_limits<float>::epsilon() ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
}//namespace dot
|
||||
|
||||
namespace cross
|
||||
{
|
||||
int test()
|
||||
{
|
||||
glm::vec3 Cross1 = glm::cross(glm::vec3(1, 0, 0), glm::vec3(0, 1, 0));
|
||||
glm::vec3 Cross2 = glm::cross(glm::vec3(0, 1, 0), glm::vec3(1, 0, 0));
|
||||
|
||||
int Error = 0;
|
||||
|
||||
Error += glm::all(glm::lessThan(glm::abs(Cross1 - glm::vec3(0, 0, 1)), glm::vec3(std::numeric_limits<float>::epsilon()))) ? 0 : 1;
|
||||
Error += glm::all(glm::lessThan(glm::abs(Cross2 - glm::vec3(0, 0,-1)), glm::vec3(std::numeric_limits<float>::epsilon()))) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
}//namespace cross
|
||||
|
||||
namespace normalize
|
||||
{
|
||||
int test()
|
||||
{
|
||||
glm::vec3 Normalize1 = glm::normalize(glm::vec3(1, 0, 0));
|
||||
glm::vec3 Normalize2 = glm::normalize(glm::vec3(2, 0, 0));
|
||||
|
||||
int Error = 0;
|
||||
|
||||
Error += glm::all(glm::lessThan(glm::abs(Normalize1 - glm::vec3(1, 0, 0)), glm::vec3(std::numeric_limits<float>::epsilon()))) ? 0 : 1;
|
||||
Error += glm::all(glm::lessThan(glm::abs(Normalize2 - glm::vec3(1, 0, 0)), glm::vec3(std::numeric_limits<float>::epsilon()))) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
}//namespace normalize
|
||||
|
||||
namespace faceforward
|
||||
{
|
||||
int test()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}//namespace faceforward
|
||||
|
||||
namespace reflect
|
||||
{
|
||||
int test()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
@ -30,8 +135,11 @@ int test_reflect()
|
||||
|
||||
return Error;
|
||||
}
|
||||
}//namespace reflect
|
||||
|
||||
int test_refract()
|
||||
namespace refract
|
||||
{
|
||||
int test()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
@ -58,13 +166,20 @@ int test_refract()
|
||||
|
||||
return Error;
|
||||
}
|
||||
}//namespace refract
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error(0);
|
||||
|
||||
Error += test_reflect();
|
||||
Error += test_refract();
|
||||
Error += length::test();
|
||||
Error += distance::test();
|
||||
Error += dot::test();
|
||||
Error += cross::test();
|
||||
Error += normalize::test();
|
||||
Error += faceforward::test();
|
||||
Error += reflect::test();
|
||||
Error += refract::test();
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user