diff options
author | HampusM <hampus@hampusmat.com> | 2023-11-28 20:50:39 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2023-11-28 20:50:39 +0100 |
commit | 6e452b58c2a8655a451edf137f376fe7dea5cb1c (patch) | |
tree | 00d77b238dbb50aba91e8de9b12a38c16215aa12 /engine | |
parent | b536154f912b1f35a548acebc2f6d7fff171e806 (diff) |
feat(engine): add Camera direction methods
Diffstat (limited to 'engine')
-rw-r--r-- | engine/src/camera.rs | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/engine/src/camera.rs b/engine/src/camera.rs index 7abb9af..362e0d6 100644 --- a/engine/src/camera.rs +++ b/engine/src/camera.rs @@ -2,12 +2,44 @@ use crate::vector::Vec3; pub trait Camera { - /// Returns the current camera position. + /// Returns the camera position. fn position(&self) -> Vec3<f32>; /// Returns the position of the camera target. fn target(&self) -> Vec3<f32>; + /// Returns the direction the camera is looking. + fn direction(&self) -> Vec3<f32> + { + self.target() - self.position() + } + + /// Returns the right direction relative from where the camera is looking. + fn right(&self) -> Vec3<f32> + { + self.direction().cross(&self.global_up()).normalize() + } + + /// Returns the left direction relative from where the camera is looking. + fn left(&self) -> Vec3<f32> + { + -self.right() + } + + /// Returns the upwards direction relative from where the camera is looking. + fn up(&self) -> Vec3<f32> + { + let rev_direction = -self.direction(); + + rev_direction.cross(&self.right()) + } + + /// Returns the downwards direction relative from where the camera is looking. + fn down(&self) -> Vec3<f32> + { + -self.up() + } + /// Returns the global direction upwards. /// /// The default implementation which returns [`Vec3::UP`] should be fine in most |