use ecs::Component; use crate::color::Color; use crate::vector::Vec3; #[derive(Debug, Clone, Component)] pub struct LightSource { position: Vec3, ambient: Color, diffuse: Color, specular: Color, } impl LightSource { #[must_use] pub fn position(&self) -> &Vec3 { &self.position } #[must_use] pub fn ambient(&self) -> &Color { &self.ambient } #[must_use] pub fn diffuse(&self) -> &Color { &self.diffuse } #[must_use] pub fn specular(&self) -> &Color { &self.specular } pub fn translate(&mut self, translation: Vec3) { self.position += translation; } } #[derive(Debug, Clone, Default)] pub struct LightSourceBuilder { position: Vec3, ambient: Color, diffuse: Color, specular: Color, } impl LightSourceBuilder { #[must_use] pub fn new() -> Self { Self { position: Vec3::default(), ambient: Color { red: 0.2, green: 0.2, blue: 0.2 }, diffuse: Color { red: 0.5, green: 0.5, blue: 0.5 }, specular: Color { red: 1.0, green: 1.0, blue: 1.0 }, } } #[must_use] pub fn position(mut self, position: Vec3) -> Self { self.position = position; self } #[must_use] pub fn ambient(mut self, ambient: Color) -> Self { self.ambient = ambient; self } #[must_use] pub fn diffuse(mut self, diffuse: Color) -> Self { self.diffuse = diffuse; self } #[must_use] pub fn specular(mut self, specular: Color) -> Self { self.specular = specular; self } #[must_use] pub fn build(&self) -> LightSource { LightSource { position: self.position.clone(), ambient: self.ambient.clone(), diffuse: self.diffuse.clone(), specular: self.specular.clone(), } } }