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