#ifndef WORLD_H #define WORLD_H #include "sphere.h" #include #include #include #include #include struct World { std::vector> objects; template void add(auto&&... args) { objects.emplace_back(new T(args...)); } std::optional> hit(const ray& r) const { double closest = std::numeric_limits::infinity(); Object *sphere; for (const auto& o : objects) { if (auto t = o->hit(r, 0.001, closest); t) { closest = *t; sphere = o.get(); } } if (closest != std::numeric_limits::infinity()) return std::pair {closest, sphere}; else return {}; } }; #endif // WORLD_H