From a6302805d19273c95278c8d792ffbd9b2633fe20 Mon Sep 17 00:00:00 2001 From: Sakarias Johansson Date: Thu, 12 Jan 2023 21:09:43 +0100 Subject: =?UTF-8?q?=F0=9F=96=8C=EF=B8=8F=20Add=20materials?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- racer-tracer/src/geometry/sphere.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'racer-tracer/src/geometry') diff --git a/racer-tracer/src/geometry/sphere.rs b/racer-tracer/src/geometry/sphere.rs index e974c44..256abec 100644 --- a/racer-tracer/src/geometry/sphere.rs +++ b/racer-tracer/src/geometry/sphere.rs @@ -1,17 +1,19 @@ use std::option::Option; +use std::sync::Arc; use crate::geometry::{HitRecord, Hittable}; +use crate::material::Material; use crate::ray::Ray; use crate::vec3::Vec3; pub struct Sphere { pos: Vec3, radius: f64, - material: Vec3, // Just a color for now. + material: Arc>, // Just a color for now. } impl Sphere { - pub fn new(pos: Vec3, radius: f64, material: Vec3) -> Self { + pub fn new(pos: Vec3, radius: f64, material: Arc>) -> Self { Self { pos, radius, @@ -47,7 +49,7 @@ impl Hittable for Sphere { let point = ray.at(root); let outward_normal = (point - self.pos) / self.radius; - let mut hit_record = HitRecord::new(point, root, self.material); + let mut hit_record = HitRecord::new(point, root, Arc::clone(&self.material)); hit_record.set_face_normal(ray, outward_normal); Some(hit_record) } -- cgit v1.2.3