#ifndef HITTABLE_LIST_H #define HITTABLE_LIST_H #include "hittable.hpp" #include "sphere.hpp" #include #include using std::shared_ptr; using std::make_shared; template struct hittable_list { /* Attributes */ std::vector objects; /* Constructors */ hittable_list () {} hittable_list(T object) { add(object); } /* Methods */ void clear() { objects.clear(); } void add (T h) { objects.push_back(h); } bool hit(const ray& r, float t_min, float t_max, hit_record& rec); }; template bool hittable_list::hit(const ray& r, float t_min, float t_max, hit_record& rec) { rmt_ScopedCPUSample(HittableList_Hit, RMTSF_Aggregate); hit_record temp_rec; bool hit_anything = false; float closest_so_far = t_max; uint32_t s = objects.size(); for (uint32_t i = 0; i < s; ++i) { T *object = &objects[i]; if (object->hit(r, t_min, closest_so_far, temp_rec)) { hit_anything = true; closest_so_far = temp_rec.t; rec = temp_rec; } } return hit_anything; } #endif