From b0315b7ebc16fcbae6c3098db6c824f9057d2a71 Mon Sep 17 00:00:00 2001 From: HampusM Date: Mon, 20 Nov 2023 22:00:34 +0100 Subject: feat(engine): add materials --- engine/src/material.rs | 113 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 engine/src/material.rs (limited to 'engine/src/material.rs') 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, + diffuse: Color, + specular: Color, + shininess: f32, +} + +impl Material +{ + #[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 + } + + #[must_use] + pub fn shininess(&self) -> f32 + { + self.shininess + } +} + +/// [`Material`] builder. +#[derive(Debug, Clone)] +pub struct Builder +{ + ambient: Color, + diffuse: Color, + specular: Color, + 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) -> 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 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() + } +} -- cgit v1.2.3-18-g5258