From 52c9ca106895f3e69000636fc6ef1ba18a486f69 Mon Sep 17 00:00:00 2001 From: HampusM Date: Tue, 28 Nov 2023 20:17:50 +0100 Subject: feat(engine): add Vec3 direction from angle function --- engine/src/vector.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/engine/src/vector.rs b/engine/src/vector.rs index 1d2ea93..5b7779c 100644 --- a/engine/src/vector.rs +++ b/engine/src/vector.rs @@ -124,6 +124,17 @@ impl Vec3 { (self.x * rhs.x) + (self.y * rhs.y) + (self.z * rhs.z) } + + /// Returns a direction vector from the specified angle (in degrees). + #[must_use] + pub fn direction_from_angle(pitch_degs: f32, yaw_degs: f32) -> Self + { + Self { + x: yaw_degs.to_radians().cos() * pitch_degs.to_radians().cos(), + y: pitch_degs.to_radians().sin(), + z: yaw_degs.to_radians().sin() * pitch_degs.to_radians().cos(), + } + } } impl Vec3 -- cgit v1.2.3-18-g5258