diff options
author | HampusM <hampus@hampusmat.com> | 2023-11-12 22:38:52 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2023-11-12 22:57:19 +0100 |
commit | 8d821588cd4f51d4ae9c4ef52d45c0af0e1ce9e5 (patch) | |
tree | ed1b0dd30e801b9a70537b9806a445e4212978b3 /engine/src/math.rs | |
parent | 67023d6a095f457a2579367d59d13c6c804e7108 (diff) |
feat(engine): add basic flat lighting
Diffstat (limited to 'engine/src/math.rs')
-rw-r--r-- | engine/src/math.rs | 17 |
1 files changed, 17 insertions, 0 deletions
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<f32>, + edge_b: &Vec3<f32>, + edge_c: &Vec3<f32>, +) -> Vec3<f32> +{ + let v1 = edge_b.clone() - egde_a.clone(); + let v2 = edge_c.clone() - egde_a.clone(); + + v1.cross(&v2) +} |