library: light: add AmbientLight implementation
This commit is contained in:
parent
d759c16f5d
commit
3a487d956e
41
src/light/ambient_light.rs
Normal file
41
src/light/ambient_light.rs
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
use super::super::core::LinearColor;
|
||||||
|
use super::super::Point;
|
||||||
|
use super::Light;
|
||||||
|
|
||||||
|
/// Represent an ambient lighting which is equal in all points of the scene.
|
||||||
|
#[derive(Debug, PartialEq)]
|
||||||
|
pub struct AmbientLight {
|
||||||
|
color: LinearColor,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AmbientLight {
|
||||||
|
pub fn new(color: LinearColor) -> Self {
|
||||||
|
AmbientLight { color }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Light for AmbientLight {
|
||||||
|
fn illumination(&self, _: &Point) -> LinearColor {
|
||||||
|
self.color.clone()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn new_works() {
|
||||||
|
let color = LinearColor::new(1., 1., 1.);
|
||||||
|
let light = AmbientLight::new(color.clone());
|
||||||
|
let res = AmbientLight { color };
|
||||||
|
assert_eq!(light, res)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn illumination_is_correct() {
|
||||||
|
let light = AmbientLight::new(LinearColor::new(1., 1., 1.));
|
||||||
|
let lum = light.illumination(&Point::new(1., 1., 1.));
|
||||||
|
assert_eq!(lum, LinearColor::new(1., 1., 1.))
|
||||||
|
}
|
||||||
|
}
|
|
@ -13,6 +13,9 @@ pub trait SpatialLight: Light {
|
||||||
fn to_source(&self, origin: &Point) -> (Vector, f32);
|
fn to_source(&self, origin: &Point) -> (Vector, f32);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub mod ambient_light;
|
||||||
|
pub use ambient_light::*;
|
||||||
|
|
||||||
pub mod directional_light;
|
pub mod directional_light;
|
||||||
pub use directional_light::*;
|
pub use directional_light::*;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue