diff --git a/rtchallenge/src/materials.rs b/rtchallenge/src/materials.rs index a18e80f..cbcbfb3 100644 --- a/rtchallenge/src/materials.rs +++ b/rtchallenge/src/materials.rs @@ -1,5 +1,5 @@ use crate::tuples::Color; -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, Clone)] pub struct Material { pub color: Color, pub ambient: f32, diff --git a/rtchallenge/src/spheres.rs b/rtchallenge/src/spheres.rs index ca3e0db..0888a89 100644 --- a/rtchallenge/src/spheres.rs +++ b/rtchallenge/src/spheres.rs @@ -1,9 +1,9 @@ use crate::{ intersections::{Intersection, Intersections}, + materials::Material, matrices::Matrix4x4, rays::Ray, tuples::{dot, Tuple}, - EPSILON, }; #[derive(Debug, PartialEq)] @@ -11,12 +11,13 @@ use crate::{ pub struct Sphere { // TODO(wathiede): cache inverse to speed up intersect. pub transform: Matrix4x4, + pub material: Material, } impl Default for Sphere { /// # Examples /// ``` - /// use rtchallenge::{matrices::Matrix4x4, spheres::Sphere}; + /// use rtchallenge::{materials::Material, matrices::Matrix4x4, spheres::Sphere}; /// /// // A sphere's default transform is the identity matrix. /// let s = Sphere::default(); @@ -27,10 +28,21 @@ impl Default for Sphere { /// let t = Matrix4x4::translation(2., 3., 4.); /// s.transform = t.clone(); /// assert_eq!(s.transform, t); + /// + /// // Default Sphere has the default material. + /// assert_eq!(s.material, Material::default()); + /// // It can be overridden. + /// let mut s = Sphere::default(); + /// let mut m = Material::default(); + /// m.ambient = 1.; + /// s.material = m.clone(); + /// assert_eq!(s.material, m); + /// ``` fn default() -> Sphere { Sphere { transform: Matrix4x4::identity(), + material: Material::default(), } } }