diff --git a/rtchallenge/src/lib.rs b/rtchallenge/src/lib.rs index 5f57a92..f3df8d7 100644 --- a/rtchallenge/src/lib.rs +++ b/rtchallenge/src/lib.rs @@ -1,5 +1,7 @@ pub mod canvas; pub mod intersections; +pub mod lights; +pub mod materials; pub mod matrices; pub mod rays; pub mod spheres; diff --git a/rtchallenge/src/lights.rs b/rtchallenge/src/lights.rs new file mode 100644 index 0000000..456dca1 --- /dev/null +++ b/rtchallenge/src/lights.rs @@ -0,0 +1,31 @@ +use crate::tuples::{Color, Tuple}; + +pub struct PointLight { + pub position: Tuple, + pub intensity: Color, +} + +impl PointLight { + /// Creates a new `PositionLight` at the given `position` and with the given + /// `intensity`. + /// + /// # Examples + /// ``` + /// use rtchallenge::{ + /// lights::PointLight, + /// tuples::{Color, Tuple}, + /// }; + /// + /// let intensity = Color::new(1., 1., 1.); + /// let position = Tuple::point(0., 0., 0.); + /// let light = PointLight::new(position, intensity); + /// assert_eq!(light.position, position); + /// assert_eq!(light.intensity, intensity); + /// ``` + pub fn new(position: Tuple, intensity: Color) -> PointLight { + PointLight { + position, + intensity, + } + } +} diff --git a/rtchallenge/src/materials.rs b/rtchallenge/src/materials.rs new file mode 100644 index 0000000..a18e80f --- /dev/null +++ b/rtchallenge/src/materials.rs @@ -0,0 +1,39 @@ +use crate::tuples::Color; +#[derive(Debug, PartialEq)] +pub struct Material { + pub color: Color, + pub ambient: f32, + pub diffuse: f32, + pub specular: f32, + pub shininess: f32, +} + +impl Default for Material { + /// Creates the default material. + /// + /// # Examples + /// ``` + /// use rtchallenge::{materials::Material, tuples::Color}; + /// + /// let m = Material::default(); + /// assert_eq!( + /// m, + /// Material { + /// color: Color::new(1., 1., 1.), + /// ambient: 0.1, + /// diffuse: 0.9, + /// specular: 0.9, + /// shininess: 200., + /// } + /// ); + /// ``` + fn default() -> Material { + Material { + color: Color::new(1., 1., 1.), + ambient: 0.1, + diffuse: 0.9, + specular: 0.9, + shininess: 200., + } + } +}