diff options
| author | Sakarias Johansson <sakarias.johansson@goodbyekansas.com> | 2023-01-12 21:09:43 +0100 |
|---|---|---|
| committer | Sakarias Johansson <sakarias.johansson@goodbyekansas.com> | 2023-01-12 21:09:43 +0100 |
| commit | a6302805d19273c95278c8d792ffbd9b2633fe20 (patch) | |
| tree | 9e539215cce7ba2eed4f873c711282f9d40a2591 /racer-tracer/src/geometry | |
| parent | bbecf67545c2bd6822b0680673aa850c5ddef9f3 (diff) | |
| download | racer-tracer-a6302805d19273c95278c8d792ffbd9b2633fe20.tar.gz racer-tracer-a6302805d19273c95278c8d792ffbd9b2633fe20.tar.xz racer-tracer-a6302805d19273c95278c8d792ffbd9b2633fe20.zip | |
🖌️ Add materials
Diffstat (limited to 'racer-tracer/src/geometry')
| -rw-r--r-- | racer-tracer/src/geometry/sphere.rs | 8 |
1 files changed, 5 insertions, 3 deletions
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<Box<dyn Material + Sync + Send>>, // 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<Box<dyn Material + Sync + Send>>) -> 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) } |
