diff options
author | Rosyid Haryadi <rosyid_haryadi@protonmail.com> | 2025-03-02 16:56:59 +0700 |
---|---|---|
committer | Rosyid Haryadi <rosyid_haryadi@protonmail.com> | 2025-03-02 16:56:59 +0700 |
commit | 93b24b9d01f806cf69ecee86fada9e5b9bf06182 (patch) | |
tree | c4c941acdeced6cb5b9cc51eedabc994ceda0b38 /src/object.rs | |
parent | d618968b9577cbaf6306f42157be19bd2a6a6aa0 (diff) |
material
Diffstat (limited to 'src/object.rs')
-rw-r--r-- | src/object.rs | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/object.rs b/src/object.rs index c1bce61..d9e2cc4 100644 --- a/src/object.rs +++ b/src/object.rs @@ -1,5 +1,7 @@ use crate::calculus::calculus::{Point3, Ray, Vec3}; +use crate::common::Color; use crate::interval::Interval; +use crate::material::MaterialType; #[derive(Clone)] pub struct HitRecord { @@ -7,6 +9,8 @@ pub struct HitRecord { pub normal: Vec3, pub t: f32, pub front_face: bool, + pub material: MaterialType, + pub color: Color, } impl Default for HitRecord { @@ -16,6 +20,8 @@ impl Default for HitRecord { normal: Vec3 {x:0.0, y:0.0, z:0.0}, t: 0.0, front_face: false, + material: MaterialType::Diffuse, + color:Color::new(0.0, 0.0, 0.0), } } } @@ -34,12 +40,14 @@ pub trait Hittable { pub struct Sphere { center: Point3, radius: f32, + material: MaterialType, + color: Color } impl Sphere { - pub fn new(center: Vec3, radius: f32) -> Self { + pub fn new(center: Vec3, radius: f32, material: MaterialType, color: Color) -> Self { let radius = f32::max(0.0, radius); - Self { center, radius } + Self { center, radius, material, color } } } @@ -70,6 +78,8 @@ impl Hittable for Sphere { .sub(&self.center) .scalar_mul(1.0 / self.radius); rec.set_face_normal(r, outward_normal); + rec.material = self.material.clone(); + rec.color = self.color.clone(); true } |