From 4193adbbff4a5b633f59f88367fe1b74aec7789b Mon Sep 17 00:00:00 2001 From: Keuin Date: Fri, 15 Apr 2022 12:32:42 +0800 Subject: Code Refactor: - Add material class. - Move diffuse routine into separate material classes. --- sphere.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'sphere.h') diff --git a/sphere.h b/sphere.h index f604b74..fa181e7 100644 --- a/sphere.h +++ b/sphere.h @@ -10,6 +10,7 @@ #include "viewport.h" #include "timer.h" #include "bitmap.h" +#include "material.h" #include "ray.h" #include "vec.h" #include @@ -19,14 +20,17 @@ #include #include +class material; + class sphere : public object { vec3d center; double radius; + class material &materi; public: sphere() = delete; - sphere(const vec3d ¢er, double radius) : center(center), radius(radius) {} + sphere(const vec3d ¢er, double radius, class material &materi) : center(center), radius(radius), materi(materi) {} ~sphere() override = default; @@ -35,6 +39,10 @@ public: return (where - center) / radius; } + class material &material() const override { + return materi; + } + bool hit(const ray3d &r, double &t, double t1, double t2) const override { // Ray: {Source, Direction, time} // Sphere: {Center, radius} -- cgit v1.2.3