summaryrefslogtreecommitdiff
path: root/engine
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2023-11-28 20:17:50 +0100
committerHampusM <hampus@hampusmat.com>2023-11-28 20:17:50 +0100
commit52c9ca106895f3e69000636fc6ef1ba18a486f69 (patch)
tree703cf855028e04727ff39adacd4c5d2cf021696d /engine
parenta924aaf2b0dee84835dfe5f6f5381076017fb18a (diff)
feat(engine): add Vec3 direction from angle function
Diffstat (limited to 'engine')
-rw-r--r--engine/src/vector.rs11
1 files changed, 11 insertions, 0 deletions
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<f32>
{
(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<Value> Vec3<Value>