]> git.localhorst.tv Git - blank.git/blobdiff - tst/model/GeometryTest.cpp
some tests for Chunk
[blank.git] / tst / model / GeometryTest.cpp
index 3776da14fd0172eac29a59a7bd8e9a7d6d8d8095..51985aef7a70e38df8df09051d44911adf02cd72 100644 (file)
@@ -3,6 +3,7 @@
 #include "model/geometry.hpp"
 
 #include <limits>
+#include <glm/gtx/io.hpp>
 
 CPPUNIT_TEST_SUITE_REGISTRATION(blank::test::GeometryTest);
 
@@ -29,12 +30,36 @@ void GeometryTest::testRayAABBIntersection() {
 
        CPPUNIT_ASSERT_MESSAGE(
                "ray at origin not intersecting box at origin",
-               Intersection(ray, box, M, &distance, &normal)
+               Intersection(ray, box, M, &distance)
        );
        CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
                "intersection distance way off",
                0.0f, distance, delta
        );
+       // normal undefined, so can't test
+
+       // move ray outside the box, but have it still point at it
+       // should be 4 units to the left now
+       ray.orig.x = -5;
+       CPPUNIT_ASSERT_MESSAGE(
+               "ray pointing at box doesn't intersect",
+               Intersection(ray, box, M, &distance, &normal)
+       );
+       CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
+               "intersection distance way off",
+               4.0f, distance, delta
+       );
+       CPPUNIT_ASSERT_EQUAL_MESSAGE(
+               "wrong surface normal at intersection point",
+               glm::vec3(-1, 0, 0), normal
+       );
+
+       // move ray to the other side, so it's pointing away now
+       ray.orig.x = 5;
+       CPPUNIT_ASSERT_MESSAGE(
+               "ray pointing away from box still intersects",
+               !Intersection(ray, box, M)
+       );
 }
 
 }