Added necessary import to intersect and added conformity-test to test/gtx/gtx_intersect

This commit is contained in:
Tormod Haugland 2014-04-27 10:29:56 +02:00
parent 26f32e6ed6
commit 730a4fb5d3
2 changed files with 69 additions and 2 deletions

View File

@ -8,6 +8,7 @@
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
#include "../geometric.hpp" #include "../geometric.hpp"
#include "fast_square_root.hpp"
#include <cfloat> #include <cfloat>
#include <limits> #include <limits>
@ -837,7 +838,7 @@ namespace glm
return t >= typename genType::value_type(0.0f); return t >= typename genType::value_type(0.0f);
} }
template<typename genType> template<typename genType>
GLM_FUNC_QUALIFIER bool intersectLineDegenerateQuad GLM_FUNC_QUALIFIER bool intersectLineDegenerateQuad
( (

View File

@ -10,10 +10,76 @@
#define GLM_FORCE_RADIANS #define GLM_FORCE_RADIANS
#include <glm/gtc/type_precision.hpp> #include <glm/gtc/type_precision.hpp>
#include <glm/gtx/intersect.hpp> #include <glm/gtx/intersect.hpp>
#include <cstdio>
int test_conformity()
{
int Error = 0;
srand(time(NULL));
const int vertexCount = 100000;
glm::vec3** vertices = new glm::vec3*[vertexCount];
for (int i = 0; i < vertexCount; ++i)
{
vertices[i] = new glm::vec3[6];
vertices[i][0] = glm::vec3((float)(rand() % 1000)/100, (float)(rand() % 1000)/100,(float)(rand() % 1000)/100);
vertices[i][1] = glm::vec3((float)(rand() % 1000)/100, (float)(rand() % 1000)/100,(float)(rand() % 1000)/100);
vertices[i][2] = glm::vec3((float)(rand() % 1000)/100, (float)(rand() % 1000)/100,(float)(rand() % 1000)/100);
vertices[i][3] = glm::vec3((float)(rand() % 1000)/100, (float)(rand() % 1000)/100,(float)(rand() % 1000)/100);
vertices[i][4] = glm::vec3(5 - rand() % 10, 5 - rand() % 10, 5 - rand() % 10);
vertices[i][5] = glm::vec3(5 - rand() % 10, 5 - rand() % 10, 5 - rand() % 10);
}
for (int i = 0; i < vertexCount; ++i)
{
glm::vec3 a = vertices[i][0];
glm::vec3 b = vertices[i][1];
glm::vec3 c = vertices[i][2];
glm::vec3 d = vertices[i][3];
glm::vec3 orig = vertices[i][4];
glm::vec3 dir = vertices[i][5];
glm::vec3 bilinearCoordinates;
glm::vec3 barycentricCoordinates;
bool intersects = glm::intersectRayDegenerateQuad(orig, dir, a, b, c, d, bilinearCoordinates);
bool intersects_fast = glm::fastIntersectRayDegenerateQuad(orig, dir, a, b, c, d);
bool intersects_tri = glm::intersectRayTriangle(orig, dir, a, b, d, barycentricCoordinates);
bool intersects_line = glm::intersectLineDegenerateQuad(orig, dir, a, b, c, d, bilinearCoordinates);
bool intersects_line_fast = glm::fastIntersectLineDegenerateQuad(orig, dir, a, b, c, d);
bool intersects_line_tri = glm::intersectLineTriangle(orig, dir, a, b, d, barycentricCoordinates);
if(!intersects_tri){
intersects_tri = glm::intersectRayTriangle(orig, dir, c, d, b, barycentricCoordinates);
}
if(!intersects_line_tri){
intersects_line_tri = glm::intersectLineTriangle(orig, dir, c, d, b, barycentricCoordinates);
}
Error += intersects != intersects_fast;
Error += intersects != intersects_tri;
Error += intersects_line != intersects_line_fast;
Error += intersects_line != intersects_line_tri;
assert(intersects == intersects_fast);
assert(intersects == intersects_tri);
assert(intersects_line == intersects_line_fast);
assert(intersects_line == intersects_line_tri);
}
delete vertices;
return Error;
}
int main() int main()
{ {
int Error(0); int Error(0);
Error += test_conformity();
return Error; return Error;
} }