X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=tst%2Fgeometry%2FIntersectionTest.cpp;h=550c0f257c65fc2bf33325d59b4aa7c939215031;hb=48d34439f3d5bc8bebabe9f0ee35970359e61bfa;hp=36cacdfa8bd309293c8224a0da636f9dd544e34d;hpb=bda41b98427c8d34f954dae0dcaf261c5ad6cb43;p=gong.git diff --git a/tst/geometry/IntersectionTest.cpp b/tst/geometry/IntersectionTest.cpp index 36cacdf..550c0f2 100644 --- a/tst/geometry/IntersectionTest.cpp +++ b/tst/geometry/IntersectionTest.cpp @@ -325,6 +325,59 @@ void IntersectionTest::testBoxBox() { ); } +void IntersectionTest::testSphereSphere() { + const float delta = std::numeric_limits::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::epsilon();