diff options
author | HampusM <hampus@hampusmat.com> | 2023-10-26 20:34:52 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2023-10-26 20:34:52 +0200 |
commit | 25ea58edff537bd06e7e771850d8ec84ff9df65b (patch) | |
tree | 93bccb51472ba9d42e071cabdcd1a9c3f750d70a | |
parent | 4596f8b28a37260fea0510a521a6523950e5a0c2 (diff) |
feat(engine): add direction functions to Camera
-rw-r--r-- | engine/src/camera.rs | 43 |
1 files changed, 43 insertions, 0 deletions
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<f32> + { + -(&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<f32> + { + 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<f32> + { + -self.right() + } + + /// Returns the up direction (normalized) relative from where the camera is currently + /// looking. + #[must_use] + pub fn up(&self) -> Vec3<f32> + { + 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<f32> + { + -self.up() + } + pub(crate) fn new() -> Self { let position = Vec3 { |