lights & materials: implement the default light and material types.

This commit is contained in:
Bill Thiede 2021-07-17 08:59:02 -07:00
parent bcf847660a
commit b4428f924c
3 changed files with 72 additions and 0 deletions

View File

@ -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;

31
rtchallenge/src/lights.rs Normal file
View File

@ -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,
}
}
}

View File

@ -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.,
}
}
}