1 #include "GeometryTest.hpp"
3 #include "model/geometry.hpp"
6 #include <glm/gtx/io.hpp>
8 CPPUNIT_TEST_SUITE_REGISTRATION(blank::test::GeometryTest);
14 void GeometryTest::setUp() {
17 void GeometryTest::tearDown() {
21 void GeometryTest::testRayAABBIntersection() {
22 Ray ray{ { 0, 0, 0 }, { 1, 0, 0 } }; // at origin, pointing right
23 AABB box{ { -1, -1, -1 }, { 1, 1, 1 } }; // 2x2x2 cube centered around origin
24 glm::mat4 M(1); // no transformation
26 const float delta = std::numeric_limits<float>::epsilon();
31 CPPUNIT_ASSERT_MESSAGE(
32 "ray at origin not intersecting box at origin",
33 Intersection(ray, box, M, &distance)
35 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
36 "intersection distance way off",
39 // normal undefined, so can't test
41 // move ray outside the box, but have it still point at it
42 // should be 4 units to the left now
44 CPPUNIT_ASSERT_MESSAGE(
45 "ray pointing at box doesn't intersect",
46 Intersection(ray, box, M, &distance, &normal)
48 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
49 "intersection distance way off",
52 CPPUNIT_ASSERT_EQUAL_MESSAGE(
53 "wrong surface normal at intersection point",
54 glm::vec3(-1, 0, 0), normal
57 // move ray to the other side, so it's pointing away now
59 CPPUNIT_ASSERT_MESSAGE(
60 "ray pointing away from box still intersects",
61 !Intersection(ray, box, M)