summaryrefslogtreecommitdiff
path: root/engine
diff options
context:
space:
mode:
Diffstat (limited to 'engine')
-rw-r--r--engine/src/camera.rs43
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 {