X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=tst%2Fmodel%2FGeometryTest.cpp;h=71830c6176930f31421e31af7afb052dff937292;hb=0580ff3941fe5f5ea25c96e737edba1541d9271f;hp=51985aef7a70e38df8df09051d44911adf02cd72;hpb=c592d2d6e230851bd7ed74d98f9046469f4086fd;p=blank.git diff --git a/tst/model/GeometryTest.cpp b/tst/model/GeometryTest.cpp index 51985ae..71830c6 100644 --- a/tst/model/GeometryTest.cpp +++ b/tst/model/GeometryTest.cpp @@ -4,6 +4,7 @@ #include #include +#include CPPUNIT_TEST_SUITE_REGISTRATION(blank::test::GeometryTest); @@ -18,7 +19,7 @@ void GeometryTest::tearDown() { } -void GeometryTest::testRayAABBIntersection() { +void GeometryTest::testRayBoxIntersection() { Ray ray{ { 0, 0, 0 }, { 1, 0, 0 } }; // at origin, pointing right AABB box{ { -1, -1, -1 }, { 1, 1, 1 } }; // 2x2x2 cube centered around origin glm::mat4 M(1); // no transformation @@ -62,5 +63,38 @@ void GeometryTest::testRayAABBIntersection() { ); } +void GeometryTest::testBoxBoxIntersection() { + AABB box{ { -1, -1, -1 }, { 1, 1, 1 } }; // 2x2x2 cube centered around origin + glm::mat4 Ma(1); // identity + glm::mat4 Mb(1); // identity + // they're identical, so should probably intersect ^^ + + CPPUNIT_ASSERT_MESSAGE( + "identical OBBs don't intersect", + Intersection(box, Ma, box, Mb) + ); + + Ma = glm::translate(glm::vec3(-2, 0, 0)); // 2 to the left + Mb = glm::translate(glm::vec3(2, 0, 0)); // 2 to the right + CPPUNIT_ASSERT_MESSAGE( + "distant OBBs intersect (2 apart, no rotation)", + !Intersection(box, Ma, box, Mb) + ); + + Ma = glm::rotate(PI_0p25, glm::vec3(0, 0, 1)); // rotated 45° around Z + Mb = glm::translate(glm::vec3(2.4, 0, 0)); // 2.4 to the right + // they should barely touch. intersect by about 0.01 if my head works + CPPUNIT_ASSERT_MESSAGE( + "OBBs don't intersect (one rotated by 45°)", + Intersection(box, Ma, box, Mb) + ); + + Mb = glm::translate(glm::vec3(3, 0, 0)); // 3 to the right + CPPUNIT_ASSERT_MESSAGE( + "OBBs intersect (one rotated by 45°)", + !Intersection(box, Ma, box, Mb) + ); +} + } }