summaryrefslogtreecommitdiff
path: root/src/object.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/object.rs')
-rw-r--r--src/object.rs14
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
}