aboutsummaryrefslogtreecommitdiffstats
path: root/src/hittable_list.cpp
diff options
context:
space:
mode:
authorladevieq <ladevie.quentin@gmail.com>2020-12-20 21:59:33 +0100
committerladevieq <ladevie.quentin@gmail.com>2020-12-20 21:59:33 +0100
commitc7c4f8f82c66cfe89b72d176ee51dab8bd30dc95 (patch)
treed0c2caeccda953d86806cb7c7b27c8941e0ef845 /src/hittable_list.cpp
parentfc601fd503ec1ebd08e4daffeb9aa0812aff2b71 (diff)
Add hittable interface and hit infos on hit
Diffstat (limited to 'src/hittable_list.cpp')
-rw-r--r--src/hittable_list.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/hittable_list.cpp b/src/hittable_list.cpp
new file mode 100644
index 0000000..9140304
--- /dev/null
+++ b/src/hittable_list.cpp
@@ -0,0 +1,28 @@
+#include "hittable_list.hpp"
+
+hittable_list::hittable_list() {};
+
+void hittable_list::add(std::shared_ptr<hittable> hittable) {
+ hittables.push_back(hittable);
+}
+
+void hittable_list::clear() {
+ hittables.clear();
+}
+
+
+bool hittable_list::hit(const ray& r, double t_min, double t_max, struct hit_info& info) const {
+ struct hit_info temp_info;
+ bool hit_anything = false;
+ double closest_hit = t_max;
+
+ for (auto& hittable: hittables) {
+ if (hittable->hit(r, t_min, closest_hit, temp_info)) {
+ hit_anything = true;
+ closest_hit = temp_info.t;
+ info = temp_info;
+ }
+ }
+
+ return hit_anything;
+}