From 8efb76ed360796b614cec5d7eaa28b159832dbdd Mon Sep 17 00:00:00 2001 From: HampusM Date: Sat, 20 Apr 2024 14:30:57 +0200 Subject: refactor(engine): make LightSource fields public --- engine/src/lighting.rs | 97 +++------------------------------------------- engine/src/renderer/mod.rs | 10 ++--- 2 files changed, 10 insertions(+), 97 deletions(-) (limited to 'engine') diff --git a/engine/src/lighting.rs b/engine/src/lighting.rs index e285739..c5369db 100644 --- a/engine/src/lighting.rs +++ b/engine/src/lighting.rs @@ -6,57 +6,15 @@ use crate::vector::Vec3; #[derive(Debug, Clone, Component)] pub struct LightSource { - position: Vec3, - ambient: Color, - diffuse: Color, - specular: Color, + pub position: Vec3, + pub ambient: Color, + pub diffuse: Color, + pub specular: Color, } -impl LightSource +impl Default for 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 + fn default() -> Self { Self { position: Vec3::default(), @@ -65,47 +23,4 @@ impl LightSourceBuilder 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(), - } - } } diff --git a/engine/src/renderer/mod.rs b/engine/src/renderer/mod.rs index 3052969..afed816 100644 --- a/engine/src/renderer/mod.rs +++ b/engine/src/renderer/mod.rs @@ -340,16 +340,14 @@ fn apply_light( { gl_shader_program.set_uniform_vec_3fv( cstr!("light.position"), - &light_source.map_or_else(Vec3::default, |light_source| { - light_source.position().clone() - }), + &light_source.map_or_else(Vec3::default, |light_source| light_source.position), ); gl_shader_program.set_uniform_vec_3fv( cstr!("light.ambient"), &light_source .map_or(Color::WHITE_F32, |light_source| { - light_source.ambient().clone() + light_source.ambient.clone() }) .into(), ); @@ -358,7 +356,7 @@ fn apply_light( cstr!("light.diffuse"), &light_source .map_or(Color::WHITE_F32, |light_source| { - light_source.diffuse().clone() + light_source.diffuse.clone() }) .into(), ); @@ -367,7 +365,7 @@ fn apply_light( cstr!("light.specular"), &light_source .map_or(Color::WHITE_F32, |light_source| { - light_source.specular().clone() + light_source.specular.clone() }) .into(), ); -- cgit v1.2.3-18-g5258