lights & materials: implement the default light and material types.
This commit is contained in:
parent
bcf847660a
commit
b4428f924c
@ -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
31
rtchallenge/src/lights.rs
Normal 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,
|
||||
}
|
||||
}
|
||||
}
|
||||
39
rtchallenge/src/materials.rs
Normal file
39
rtchallenge/src/materials.rs
Normal 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.,
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user