}
+void IntersectionTest::testAABB() {
+ AABB a{ { -1, -1, -1 }, { 1, 1, 1 } };
+ AABB b(a);
+
+ CPPUNIT_ASSERT_MESSAGE(
+ "coincidental AABBs should intersect",
+ Intersection(a, b)
+ );
+
+ b.Move({ 1, 0, 0 });
+ CPPUNIT_ASSERT_MESSAGE(
+ "AABBs should intersect",
+ Intersection(a, b)
+ );
+
+ b.Move({ 2, 0, 0 });
+ CPPUNIT_ASSERT_MESSAGE(
+ "AABBs should not intersect",
+ !Intersection(a, b)
+ );
+
+ b.Move({ -4, 0, 0 });
+ CPPUNIT_ASSERT_MESSAGE(
+ "AABBs should intersect",
+ Intersection(a, b)
+ );
+
+ b.Move({ -2, 0, 0 });
+ CPPUNIT_ASSERT_MESSAGE(
+ "AABBs should not intersect",
+ !Intersection(a, b)
+ );
+
+ b.Move({ 3, 1, 0 });
+ CPPUNIT_ASSERT_MESSAGE(
+ "AABBs should intersect",
+ Intersection(a, b)
+ );
+
+ b.Move({ 0, 2, 0 });
+ CPPUNIT_ASSERT_MESSAGE(
+ "AABBs should not intersect",
+ !Intersection(a, b)
+ );
+
+ b.Move({ 2, 0, 0 });
+ CPPUNIT_ASSERT_MESSAGE(
+ "AABBs should not intersect",
+ !Intersection(a, b)
+ );
+
+ b.Move({ 0, 0, 2 });
+ CPPUNIT_ASSERT_MESSAGE(
+ "AABBs should not intersect",
+ !Intersection(a, b)
+ );
+}
+
void IntersectionTest::testSimpleRayBox() {
Ray ray{ { 0, 0, 0 }, { 1, 0, 0 }, { } }; // at origin, pointing right
ray.Update();
);
}
+void IntersectionTest::testSphereSphere() {
+ const float delta = std::numeric_limits<float>::epsilon();
+
+ Sphere a{{ 0.0f, 0.0f, 0.0f }, 1.0f};
+ Sphere b{{ 0.0f, 0.0f, 0.0f }, 1.0f};
+ float depth;
+ glm::vec3 normal;
+
+ CPPUNIT_ASSERT_MESSAGE(
+ "coincidental spheres should intersect",
+ Intersection(a, b, depth, normal)
+ );
+ CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
+ "bad intersection distance",
+ 2.0f, depth, delta
+ );
+ // normal can be just about anything
+
+ b.Move({ 1, 0, 0 });
+ CPPUNIT_ASSERT_MESSAGE(
+ "spheres should intersect",
+ Intersection(a, b, depth, normal)
+ );
+ CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
+ "bad intersection distance",
+ 1.0f, depth, delta
+ );
+ CPPUNIT_ASSERT_EQUAL_MESSAGE(
+ "bad intersection normal",
+ glm::vec3(1, 0, 0), normal
+ );
+
+ b.Position({ -1.5, 0, 0 });
+ CPPUNIT_ASSERT_MESSAGE(
+ "spheres should intersect",
+ Intersection(a, b, depth, normal)
+ );
+ CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
+ "bad intersection distance",
+ 0.5f, depth, delta
+ );
+ CPPUNIT_ASSERT_EQUAL_MESSAGE(
+ "bad intersection normal",
+ glm::vec3(-1, 0, 0), normal
+ );
+
+ b.Move({ -1, 0, 0 });
+ CPPUNIT_ASSERT_MESSAGE(
+ "spheres should not intersect",
+ !Intersection(a, b, depth, normal)
+ );
+}
+
void IntersectionTest::testSpherePlane() {
const float delta = std::numeric_limits<float>::epsilon();