2013-10-27 18:25:03 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2014-01-04 21:32:28 +00:00
|
|
|
// OpenGL Mathematics Copyright (c) 2005 - 2014 G-Truc Creation (www.g-truc.net)
|
2013-10-27 18:25:03 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Created : 2013-10-25
|
|
|
|
// Updated : 2013-10-25
|
|
|
|
// Licence : This source is under MIT licence
|
2013-10-27 22:38:22 +00:00
|
|
|
// File : test/gtx/intersect.cpp
|
2013-10-27 18:25:03 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2014-01-11 20:12:53 +00:00
|
|
|
#define GLM_FORCE_RADIANS
|
2013-10-27 18:25:03 +00:00
|
|
|
#include <glm/gtc/type_precision.hpp>
|
2013-10-27 22:38:22 +00:00
|
|
|
#include <glm/gtx/intersect.hpp>
|
2014-04-27 08:29:56 +00:00
|
|
|
#include <cstdio>
|
|
|
|
|
|
|
|
int test_conformity()
|
|
|
|
{
|
|
|
|
int Error = 0;
|
|
|
|
srand(time(NULL));
|
|
|
|
|
|
|
|
const int vertexCount = 100000;
|
|
|
|
|
2014-04-27 08:34:32 +00:00
|
|
|
glm::vec3 vertices[vertexCount][6];
|
2014-04-27 08:29:56 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < vertexCount; ++i)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Error;
|
|
|
|
}
|
2013-10-27 18:25:03 +00:00
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
int Error(0);
|
2014-04-27 08:29:56 +00:00
|
|
|
Error += test_conformity();
|
2013-10-27 18:25:03 +00:00
|
|
|
return Error;
|
|
|
|
}
|