From 563c65c4ac6abf4522c9673d708a568f2acde2d4 Mon Sep 17 00:00:00 2001 From: Keuin Date: Thu, 21 Apr 2022 21:01:01 +0800 Subject: Make object holds a constant reference to its material. --- sphere.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'sphere.h') diff --git a/sphere.h b/sphere.h index 8cc1caf..57e59c4 100644 --- a/sphere.h +++ b/sphere.h @@ -25,12 +25,13 @@ class material; class sphere : public object { vec3d center; double radius; - class material &materi; + const class material *materi; public: sphere() = delete; - sphere(const vec3d ¢er, double radius, class material &materi) : center(center), radius(radius), materi(materi) {} + sphere(const vec3d center, double radius, const class material &materi) + : center(center), radius(radius), materi(&materi) {} ~sphere() override = default; @@ -39,8 +40,8 @@ public: return (where - center) / radius; } - class material &get_material() const override { - return materi; + const class material &get_material() const override { + return *materi; } bool hit(const ray3d &r, double &t, double t1, double t2) const override { -- cgit v1.2.3