diff options
author | HampusM <hampus@hampusmat.com> | 2023-11-20 22:00:34 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2023-11-20 22:00:34 +0100 |
commit | b0315b7ebc16fcbae6c3098db6c824f9057d2a71 (patch) | |
tree | c7473fbdbcc59aff933790892ee015a6f05d8565 /engine/src/material.rs | |
parent | a65c8abcae46b382b2e1bb7cc5d13768325083b4 (diff) |
feat(engine): add materials
Diffstat (limited to 'engine/src/material.rs')
-rw-r--r-- | engine/src/material.rs | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/engine/src/material.rs b/engine/src/material.rs new file mode 100644 index 0000000..240d7e2 --- /dev/null +++ b/engine/src/material.rs @@ -0,0 +1,113 @@ +use crate::color::Color; + +#[derive(Debug, Clone)] +pub struct Material +{ + ambient: Color<f32>, + diffuse: Color<f32>, + specular: Color<f32>, + shininess: f32, +} + +impl Material +{ + #[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 + } + + #[must_use] + pub fn shininess(&self) -> f32 + { + self.shininess + } +} + +/// [`Material`] builder. +#[derive(Debug, Clone)] +pub struct Builder +{ + ambient: Color<f32>, + diffuse: Color<f32>, + specular: Color<f32>, + shininess: f32, +} + +impl Builder +{ + #[must_use] + pub fn new() -> Self + { + Self { + ambient: 0.2.into(), + diffuse: 0.5.into(), + specular: 1.0.into(), + shininess: 32.0, + } + } + + #[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 shininess(mut self, shininess: f32) -> Self + { + self.shininess = shininess; + + self + } + + /// Builds a new [`Material`]. + #[must_use] + pub fn build(&self) -> Material + { + Material { + ambient: self.ambient.clone(), + diffuse: self.diffuse.clone(), + specular: self.specular.clone(), + shininess: self.shininess, + } + } +} + +impl Default for Builder +{ + fn default() -> Self + { + Self::new() + } +} |