1 #include "FloorTest.hpp"
3 #include "../vector_assert.hpp"
5 #include <world/Floor.hpp>
7 #include <glm/gtx/io.hpp>
9 CPPUNIT_TEST_SUITE_REGISTRATION(tacos::test::FloorTest);
14 void FloorTest::setUp() {
17 void FloorTest::tearDown() {
21 void FloorTest::testIntersection() {
26 // default floor has all heights at 0, so a ray within the grid at height 1 pointing
27 // straight down should intersect it
28 // this ray hits the triangle somewhere near the middle
29 ray.origin = glm::vec3(0.5f, 1.0f, 0.75f);
30 ray.direction = glm::vec3(0.0f, -1.0f, 0.0f);
31 CPPUNIT_ASSERT_MESSAGE(
32 "ray pointing down at a triangle does not intersect floor when it should",
33 floor.Intersection(ray, point)
36 "unexpected intersection point",
37 glm::vec3(0.5f, 0.0f, 0.75f), point
39 // this ray should hit on the low X edge of the triangle
40 ray.origin = glm::vec3(0.0f, 1.0f, 0.5f);
41 ray.direction = glm::vec3(0.0f, -1.0f, 0.0f);
42 CPPUNIT_ASSERT_MESSAGE(
43 "ray pointing down at a low X triangle edge does not intersect floor when it should",
44 floor.Intersection(ray, point)
47 "unexpected intersection point",
48 glm::vec3(0.0f, 0.0f, 0.5f), point
50 // this ray should hit on the low Z edge of the triangle
51 ray.origin = glm::vec3(0.5f, 1.0f, 0.0f);
52 ray.direction = glm::vec3(0.0f, -1.0f, 0.0f);
53 CPPUNIT_ASSERT_MESSAGE(
54 "ray pointing down at a low Z triangle edgedoes not intersect floor when it should",
55 floor.Intersection(ray, point)
58 "unexpected intersection point",
59 glm::vec3(0.5f, 0.0f, 0.0f), point
61 // this ray should hit on the diagonal edge of the triangle
62 ray.origin = glm::vec3(0.5f, 1.0f, 0.5f);
63 ray.direction = glm::vec3(0.0f, -1.0f, 0.0f);
64 CPPUNIT_ASSERT_MESSAGE(
65 "ray pointing down at a diagonal triangle edgedoes not intersect floor when it should",
66 floor.Intersection(ray, point)
69 "unexpected intersection point",
70 glm::vec3(0.5f, 0.0f, 0.5f), point
72 // this ray points straight away from the floor, so should not intersect
73 ray.origin = glm::vec3(0.5f, 1.0f, 0.5f);
74 ray.direction = glm::vec3(0.0f, 1.0f, 0.0f);
75 CPPUNIT_ASSERT_MESSAGE(
76 "ray pointing up intersects floor when it shouldn't",
77 !floor.Intersection(ray, point)
79 // this ray start below the floor and points down, so stays "underground" the whole time
80 ray.origin = glm::vec3(0.5f, -1.0f, 0.5f);
81 ray.direction = glm::vec3(0.0f, -1.0f, 0.0f);
82 CPPUNIT_ASSERT_MESSAGE(
83 "ray pointing down intersects floor when it shouldn't",
84 !floor.Intersection(ray, point)
86 // this ray start below the floor and points up, that means it intersects, although from the unexpected side
87 ray.origin = glm::vec3(0.5f, -1.0f, 0.5f);
88 ray.direction = glm::vec3(0.0f, 1.0f, 0.0f);
89 CPPUNIT_ASSERT_MESSAGE(
90 "ray below the floor pointing up does not intersect floor when it should",
91 floor.Intersection(ray, point)
94 "unexpected intersection point",
95 glm::vec3(0.5f, 0.0f, 0.5f), point
98 ray.origin = glm::vec3(0.0f, 1.0f, 1.0f);
99 ray.direction = glm::normalize(glm::vec3(1.0f, -1.0f, 0.0f));
100 CPPUNIT_ASSERT_MESSAGE(
101 "diagonal ray, starts 1 unit above the floor and points down and to the right does not intersect floor when it should",
102 floor.Intersection(ray, point)
105 "unexpected intersection point",
106 glm::vec3(1.0f, 0.0f, 1.0f), point
108 // the same ray, but with origin outside the XZ grid
109 ray.origin = glm::vec3(-1.0f, 2.0f, 1.0f);
110 ray.direction = glm::normalize(glm::vec3(1.0f, -1.0f, 0.0f));
111 CPPUNIT_ASSERT_MESSAGE(
112 "ray entering from the left does not intersect floor when it should",
113 floor.Intersection(ray, point)
116 "unexpected intersection point",
117 glm::vec3(1.0f, 0.0f, 1.0f), point
119 ray.origin = glm::vec3(3.0f, 2.0f, 1.0f);
120 ray.direction = glm::normalize(glm::vec3(-1.0f, -1.0f, 0.0f));
121 CPPUNIT_ASSERT_MESSAGE(
122 "ray entering from the right does not intersect floor when it should",
123 floor.Intersection(ray, point)
126 "unexpected intersection point",
127 glm::vec3(1.0f, 0.0f, 1.0f), point
129 ray.origin = glm::vec3(1.0f, 1.0f, 1.0f);
130 ray.direction = glm::normalize(glm::vec3(1.0f, 0.0f, 1.0f));
131 CPPUNIT_ASSERT_MESSAGE(
132 "ray parallel to the floor intersects floor when it shouldn't",
133 !floor.Intersection(ray, point)
136 ray.origin = glm::vec3(19.993f, 49.947f, 106.518f);
137 ray.direction = glm::normalize(glm::vec3(-0.07f, -0.528f, -0.846f));
138 CPPUNIT_ASSERT_MESSAGE(
139 "weird ray from interactive testing doesn't intersect :(",
140 floor.Intersection(ray, point)
143 "unexpected intersection point",
144 glm::vec3(13.37123870f, 0.0f, 26.48928486f), point,
145 0.00001f // using custom delta since values above are somewhat rounded/truncated
147 ray.origin = glm::vec3(19.995f, 49.952f, 106.515f);
148 ray.direction = glm::normalize(glm::vec3(-0.046f, -0.477f, -0.878f));
149 CPPUNIT_ASSERT_MESSAGE(
150 "weird ray from interactive testing doesn't intersect :(",
151 floor.Intersection(ray, point)
154 "unexpected intersection point",
155 glm::vec3(15.17783f, 0.0f, 14.5698f), point,