From fdc2d91285cd9548a3c95f1bdfb75c70ccfffff6 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Thu, 16 May 2024 08:03:42 -0400 Subject: abstract objects --- world.h | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'world.h') diff --git a/world.h b/world.h index 4e01bcf..9723b78 100644 --- a/world.h +++ b/world.h @@ -4,26 +4,28 @@ #include "sphere.h" #include +#include #include #include #include struct World { - std::vector objects; + std::vector> objects; + template void add(auto&&... args) { - objects.emplace_back(args...); + objects.emplace_back(new T(args...)); } - std::optional> hit(const ray& r) const { + std::optional> hit(const ray& r) const { double closest = std::numeric_limits::infinity(); - Sphere sphere; + Object *sphere; for (const auto& o : objects) { - if (auto t = o.hit(r, 0.001, closest); t) { + if (auto t = o->hit(r, 0.001, closest); t) { closest = *t; - sphere = o; + sphere = o.get(); } } -- cgit v1.2.3