]> git.localhorst.tv Git - blank.git/commitdiff
fix ray/obb intersection test
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Thu, 11 Jun 2015 13:29:35 +0000 (15:29 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Thu, 11 Jun 2015 13:29:35 +0000 (15:29 +0200)
again, unit tests \o/

also: careful with the signs ;)

src/model/geometry.cpp
tst/model/GeometryTest.cpp [new file with mode: 0644]
tst/model/GeometryTest.hpp [new file with mode: 0644]

index 416d930c4f68d0c24a0f690851264b98556b855b..ed9b4b7ed5339d5805fb33287b491c6ef2e5eb6d 100644 (file)
@@ -35,7 +35,7 @@ bool Intersection(
                                return false;
                        }
                } else {
-                       if (aabb.min[i] - e < 0.0f || -aabb.max[i] - e > 0.0f) {
+                       if (aabb.min[i] - e > 0.0f || aabb.max[i] - e < 0.0f) {
                                return false;
                        }
                }
diff --git a/tst/model/GeometryTest.cpp b/tst/model/GeometryTest.cpp
new file mode 100644 (file)
index 0000000..3776da1
--- /dev/null
@@ -0,0 +1,41 @@
+#include "GeometryTest.hpp"
+
+#include "model/geometry.hpp"
+
+#include <limits>
+
+CPPUNIT_TEST_SUITE_REGISTRATION(blank::test::GeometryTest);
+
+
+namespace blank {
+namespace test {
+
+void GeometryTest::setUp() {
+}
+
+void GeometryTest::tearDown() {
+}
+
+
+void GeometryTest::testRayAABBIntersection() {
+       Ray ray{ { 0, 0, 0 }, { 1, 0, 0 } }; // at origin, pointing right
+       AABB box{ { -1, -1, -1 }, { 1, 1, 1 } }; // 2x2x2 cube centered around origin
+       glm::mat4 M(1); // no transformation
+
+       const float delta = std::numeric_limits<float>::epsilon();
+
+       float distance = 0;
+       glm::vec3 normal(0);
+
+       CPPUNIT_ASSERT_MESSAGE(
+               "ray at origin not intersecting box at origin",
+               Intersection(ray, box, M, &distance, &normal)
+       );
+       CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
+               "intersection distance way off",
+               0.0f, distance, delta
+       );
+}
+
+}
+}
diff --git a/tst/model/GeometryTest.hpp b/tst/model/GeometryTest.hpp
new file mode 100644 (file)
index 0000000..2ee85b1
--- /dev/null
@@ -0,0 +1,30 @@
+#ifndef BLANK_TEST_MODEL_GEOMETRYTEST_H_
+#define BLANK_TEST_MODEL_GEOMETRYTEST_H_
+
+#include <cppunit/extensions/HelperMacros.h>
+
+
+namespace blank {
+namespace test {
+
+class GeometryTest
+: public CppUnit::TestFixture {
+
+CPPUNIT_TEST_SUITE(GeometryTest);
+
+CPPUNIT_TEST(testRayAABBIntersection);
+
+CPPUNIT_TEST_SUITE_END();
+
+public:
+       void setUp();
+       void tearDown();
+
+       void testRayAABBIntersection();
+
+};
+
+}
+}
+
+#endif