diff options
author | Keuin <[email protected]> | 2022-04-21 21:01:01 +0800 |
---|---|---|
committer | Keuin <[email protected]> | 2022-04-21 21:01:01 +0800 |
commit | 563c65c4ac6abf4522c9673d708a568f2acde2d4 (patch) | |
tree | b080a622208b2f77df30adf1a121168c865aa7c0 | |
parent | 5f92f7182311b111a1bb9ac2f3bccb9eb5754c2c (diff) |
Make object holds a constant reference to its material.
-rw-r--r-- | object.h | 2 | ||||
-rw-r--r-- | sphere.h | 9 |
2 files changed, 6 insertions, 5 deletions
@@ -41,7 +41,7 @@ public: virtual ~object() = default; // Get this object's material. - virtual material &get_material() const = 0; + virtual const material & get_material() const = 0; }; @@ -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 { |