From 25ea58edff537bd06e7e771850d8ec84ff9df65b Mon Sep 17 00:00:00 2001 From: HampusM Date: Thu, 26 Oct 2023 20:34:52 +0200 Subject: feat(engine): add direction functions to Camera --- engine/src/camera.rs | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'engine/src/camera.rs') diff --git a/engine/src/camera.rs b/engine/src/camera.rs index 929f1a3..9ab95e7 100644 --- a/engine/src/camera.rs +++ b/engine/src/camera.rs @@ -38,6 +38,49 @@ impl Camera &self.target } + /// Returns the normalized direction to the current target. + #[must_use] + pub fn target_direction(&self) -> Vec3 + { + -(&self.position - &self.target).normalize() + } + + /// Returns the right direction (normalized) relative from where the camera is + /// currently looking. + #[must_use] + pub fn right(&self) -> Vec3 + { + let rev_target_direction = (&self.position - &self.target).normalize(); + + Vec3::UP.cross(&rev_target_direction).normalize() + } + + /// Returns the left direction (normalized) relative from where the camera is + /// currently looking. + #[must_use] + pub fn left(&self) -> Vec3 + { + -self.right() + } + + /// Returns the up direction (normalized) relative from where the camera is currently + /// looking. + #[must_use] + pub fn up(&self) -> Vec3 + { + let rev_target_direction = (&self.position - &self.target).normalize(); + + rev_target_direction.cross(&self.right()) + } + + /// Returns the down direction (normalized) relative from where the camera is + /// currently looking. + #[must_use] + pub fn down(&self) -> Vec3 + { + -self.up() + } + pub(crate) fn new() -> Self { let position = Vec3 { -- cgit v1.2.3-18-g5258