aboutsummaryrefslogtreecommitdiff
path: root/test/object.cpp
diff options
context:
space:
mode:
authorJulian T <julian@jtle.dk>2020-07-26 12:56:27 +0200
committerJulian T <julian@jtle.dk>2020-07-26 12:56:27 +0200
commit893176a0b18a2281abe09def716ccc3db5583c3f (patch)
treea34da79b7dc0fcdbdd39e2a3f4000cc6a1c0a896 /test/object.cpp
parent18960c4b88ce912e08b12182b835a7de75388b78 (diff)
Implemented object intersection and startet work on render gui
Diffstat (limited to 'test/object.cpp')
-rw-r--r--test/object.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/test/object.cpp b/test/object.cpp
new file mode 100644
index 0000000..bbce055
--- /dev/null
+++ b/test/object.cpp
@@ -0,0 +1,36 @@
+#include <object.hpp>
+#include <ray.hpp>
+#include <common.hpp>
+#include <vector.hpp>
+
+#include <catch2/catch.hpp>
+#include <math.h>
+
+TEST_CASE("Sphere normal at", "[sphere]") {
+ auto sph = Sphere(Vec3d(2, 3, 4), 2);
+
+ auto norm = sph.norm_at(Vec3d(2, 3, 2), Vec3d());
+ REQUIRE(norm.m_x == 0);
+ REQUIRE(norm.m_y == 0);
+ REQUIRE(norm.m_z == -1);
+}
+
+TEST_CASE("Sphere intersect", "[sphere]") {
+ auto sph = Sphere(Vec3d(2, 3, 4), 2);
+ auto ray = Ray(Vec3d(1, 0, 0), Vec3d(0, 1, 1.5), true);
+
+ auto dist = sph.intersect(ray, false);
+ REQUIRE(abs(dist - 3.28) < 0.01);
+}
+
+TEST_CASE("Plane intersect", "[plane]") {
+ auto pln = Plane(Vec3d(3, 4, 2), Vec3d(-6, -3, -2));
+ auto ray = Ray(Vec3d(0, 0, 0), Vec3d(-2, -1, 5));
+
+ auto dist = pln.intersect(ray, false);
+ REQUIRE(dist == -1);
+
+ ray = Ray(Vec3d(-2, -2, 0), Vec3d(-2, -1, 5));
+ dist = pln.intersect(ray, false);
+ REQUIRE(abs(dist - 20.4) < 0.1);
+}