From 8d821588cd4f51d4ae9c4ef52d45c0af0e1ce9e5 Mon Sep 17 00:00:00 2001 From: HampusM Date: Sun, 12 Nov 2023 22:38:52 +0100 Subject: feat(engine): add basic flat lighting --- engine/src/math.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 engine/src/math.rs (limited to 'engine/src/math.rs') diff --git a/engine/src/math.rs b/engine/src/math.rs new file mode 100644 index 0000000..bda3b59 --- /dev/null +++ b/engine/src/math.rs @@ -0,0 +1,17 @@ +//! Miscellaneous math functions. + +use crate::vector::Vec3; + +/// Calculates the surface normal of a triangle. +#[must_use] +pub fn calc_triangle_surface_normal( + egde_a: &Vec3, + edge_b: &Vec3, + edge_c: &Vec3, +) -> Vec3 +{ + let v1 = edge_b.clone() - egde_a.clone(); + let v2 = edge_c.clone() - egde_a.clone(); + + v1.cross(&v2) +} -- cgit v1.2.3-18-g5258