]> git.localhorst.tv Git - blank.git/blob - tst/model/GeometryTest.cpp
3776da14fd0172eac29a59a7bd8e9a7d6d8d8095
[blank.git] / tst / model / GeometryTest.cpp
1 #include "GeometryTest.hpp"
2
3 #include "model/geometry.hpp"
4
5 #include <limits>
6
7 CPPUNIT_TEST_SUITE_REGISTRATION(blank::test::GeometryTest);
8
9
10 namespace blank {
11 namespace test {
12
13 void GeometryTest::setUp() {
14 }
15
16 void GeometryTest::tearDown() {
17 }
18
19
20 void GeometryTest::testRayAABBIntersection() {
21         Ray ray{ { 0, 0, 0 }, { 1, 0, 0 } }; // at origin, pointing right
22         AABB box{ { -1, -1, -1 }, { 1, 1, 1 } }; // 2x2x2 cube centered around origin
23         glm::mat4 M(1); // no transformation
24
25         const float delta = std::numeric_limits<float>::epsilon();
26
27         float distance = 0;
28         glm::vec3 normal(0);
29
30         CPPUNIT_ASSERT_MESSAGE(
31                 "ray at origin not intersecting box at origin",
32                 Intersection(ray, box, M, &distance, &normal)
33         );
34         CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
35                 "intersection distance way off",
36                 0.0f, distance, delta
37         );
38 }
39
40 }
41 }