summaryrefslogtreecommitdiff
path: root/engine
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2024-04-20 14:30:57 +0200
committerHampusM <hampus@hampusmat.com>2024-04-20 14:30:57 +0200
commit8efb76ed360796b614cec5d7eaa28b159832dbdd (patch)
treee0e14f7630cc9e8336fb88c30e2ceb26341754b6 /engine
parent7da31da573f6bbc044d28bd961f67d0db90f8d0e (diff)
refactor(engine): make LightSource fields public
Diffstat (limited to 'engine')
-rw-r--r--engine/src/lighting.rs97
-rw-r--r--engine/src/renderer/mod.rs10
2 files changed, 10 insertions, 97 deletions
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<f32>,
- ambient: Color<f32>,
- diffuse: Color<f32>,
- specular: Color<f32>,
+ pub position: Vec3<f32>,
+ pub ambient: Color<f32>,
+ pub diffuse: Color<f32>,
+ pub specular: Color<f32>,
}
-impl LightSource
+impl Default for LightSource
{
- #[must_use]
- pub fn position(&self) -> &Vec3<f32>
- {
- &self.position
- }
-
- #[must_use]
- pub fn ambient(&self) -> &Color<f32>
- {
- &self.ambient
- }
-
- #[must_use]
- pub fn diffuse(&self) -> &Color<f32>
- {
- &self.diffuse
- }
-
- #[must_use]
- pub fn specular(&self) -> &Color<f32>
- {
- &self.specular
- }
-
- pub fn translate(&mut self, translation: Vec3<f32>)
- {
- self.position += translation;
- }
-}
-
-#[derive(Debug, Clone, Default)]
-pub struct LightSourceBuilder
-{
- position: Vec3<f32>,
- ambient: Color<f32>,
- diffuse: Color<f32>,
- specular: Color<f32>,
-}
-
-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<f32>) -> Self
- {
- self.position = position;
-
- self
- }
-
- #[must_use]
- pub fn ambient(mut self, ambient: Color<f32>) -> Self
- {
- self.ambient = ambient;
-
- self
- }
-
- #[must_use]
- pub fn diffuse(mut self, diffuse: Color<f32>) -> Self
- {
- self.diffuse = diffuse;
-
- self
- }
-
- #[must_use]
- pub fn specular(mut self, specular: Color<f32>) -> 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(),
);