From 730a4fb5d3e780f1c59176342f2b4223b5c3078a Mon Sep 17 00:00:00 2001 From: Tormod Haugland Date: Sun, 27 Apr 2014 10:29:56 +0200 Subject: [PATCH] Added necessary import to intersect and added conformity-test to test/gtx/gtx_intersect --- glm/gtx/intersect.inl | 3 +- test/gtx/gtx_intersect.cpp | 68 +++++++++++++++++++++++++++++++++++++- 2 files changed, 69 insertions(+), 2 deletions(-) diff --git a/glm/gtx/intersect.inl b/glm/gtx/intersect.inl index e585c372..979b5d50 100644 --- a/glm/gtx/intersect.inl +++ b/glm/gtx/intersect.inl @@ -8,6 +8,7 @@ /////////////////////////////////////////////////////////////////////////////////////////////////// #include "../geometric.hpp" +#include "fast_square_root.hpp" #include #include @@ -837,7 +838,7 @@ namespace glm return t >= typename genType::value_type(0.0f); } - + template GLM_FUNC_QUALIFIER bool intersectLineDegenerateQuad ( diff --git a/test/gtx/gtx_intersect.cpp b/test/gtx/gtx_intersect.cpp index 04b26cdb..82d2aca8 100644 --- a/test/gtx/gtx_intersect.cpp +++ b/test/gtx/gtx_intersect.cpp @@ -10,10 +10,76 @@ #define GLM_FORCE_RADIANS #include #include +#include + +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 Error(0); - + Error += test_conformity(); return Error; }