Permalink
Browse files

Add a test for a new (unimplemented) kmAABBIntersectsTriangle function

  • Loading branch information...
1 parent 7ab658b commit 48a1a185e166aaba56ff120c7a89d1f561d5c7e2 @Kazade committed Aug 28, 2011
Showing with 62 additions and 0 deletions.
  1. +1 −0 include/kazmath/aabb.h
  2. +3 −0 src/aabb.c
  3. +2 −0 tests/CMakeLists.txt
  4. +56 −0 tests/test_aabb.cpp
View
@@ -45,6 +45,7 @@ typedef struct kmAABB {
const int kmAABBContainsPoint(const kmVec3* pPoint, const kmAABB* pBox);
kmAABB* const kmAABBAssign(kmAABB* pOut, const kmAABB* pIn);
kmAABB* const kmAABBScale(kmAABB* pOut, const kmAABB* pIn, kmScalar s);
+kmBool kmAABBIntersectsTriangle(kmAABB* box, const kmVec3* p1, const kmVec3* p2, const kmVec3* p3);
#ifdef __cplusplus
}
View
@@ -58,5 +58,8 @@ kmAABB* const kmAABBScale(kmAABB* pOut, const kmAABB* pIn, kmScalar s)
assert(0 && "Not implemented");
}
+kmBool kmAABBIntersectsTriangle(kmAABB* box, const kmVec3* p1, const kmVec3* p2, const kmVec3* p3) {
+ return KM_TRUE;
+}
View
@@ -14,4 +14,6 @@ ADD_TEST(test_ray2 test_ray2)
ADD_EXECUTABLE(test_vec2 ${KAZMATH_SOURCES} test_vec2.cpp)
ADD_TEST(test_vec2 test_vec2)
+ADD_EXECUTABLE(test_aabb ${KAZMATH_SOURCES} test_aabb.cpp)
+ADD_TEST(test_aabb test_aabb)
View
@@ -0,0 +1,56 @@
+#include <unittest++/UnitTest++.h>
+#include <limits>
+
+#include "kazmath/aabb.h"
+
+TEST(test_aabb_triangle_intersection) {
+
+ kmAABB box;
+ box.min.x = -5.0f;
+ box.min.y = -5.0f;
+ box.min.z = std::numeric_limits<kmScalar>::min();
+
+ box.max.x = 5.0f;
+ box.max.y = 5.0f;
+ box.max.z = std::numeric_limits<kmScalar>::max();
+
+ //Triangle that is entirely within the bounds of the box
+ kmVec3 tri1 [] = {
+ { -1.0f, 0.0f, 0.0f },
+ { 1.0f, 0.0f, 0.0f },
+ { 1.0f, 1.0f, 0.0f },
+ };
+
+ //Should intersect
+ CHECK(kmAABBIntersectsTriangle(&box, &tri1[0], &tri1[1], &tri1[2]));
+
+ //Triangle that entirely surrounds the box (should still return true)
+ kmVec3 tri2 [] = {
+ { -100.0f, 0.0f, 0.0f },
+ { 100.0f, 0.0f, 0.0f },
+ { 100.0f, 100.0f, 0.0f },
+ };
+ CHECK(kmAABBIntersectsTriangle(&box, &tri2[0], &tri2[1], &tri2[2]));
+
+ //Triangle that is entirely outside of the box (should return false)
+ kmVec3 tri3 [] = {
+ { 10.0f, 0.0f, 0.0f },
+ { 20.0f, 0.0f, 0.0f },
+ { 20.0f, 10.0f, 0.0f },
+ };
+
+ CHECK(!kmAABBIntersectsTriangle(&box, &tri3[0], &tri3[1], &tri3[2]));
+
+ //Triangle that intersects the box (should return true)
+ kmVec3 tri4 [] = {
+ { 0.0f, 0.0f, 0.0f },
+ { 10.0f, 0.0f, 0.0f },
+ { 10.0f, 10.0f, 0.0f },
+ };
+
+ CHECK(kmAABBIntersectsTriangle(&box, &tri4[0], &tri4[1], &tri4[2]));
+}
+
+int main() {
+ return UnitTest::RunAllTests();
+}

0 comments on commit 48a1a18

Please sign in to comment.