diff options
author | HampusM <hampus@hampusmat.com> | 2024-04-14 12:34:52 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2024-04-14 12:35:28 +0200 |
commit | 101b455e51f9b702da5517cabe2c3b1086fcb2e7 (patch) | |
tree | 470e28acd7a3777dbb4be0208f9cd3177bba52a9 /engine/src/camera.rs | |
parent | ef7b76ff39d501028852835649f618fcbe17a003 (diff) |
feat(engine): use ECS architecture
Diffstat (limited to 'engine/src/camera.rs')
-rw-r--r-- | engine/src/camera.rs | 62 |
1 files changed, 18 insertions, 44 deletions
diff --git a/engine/src/camera.rs b/engine/src/camera.rs index 362e0d6..5347e83 100644 --- a/engine/src/camera.rs +++ b/engine/src/camera.rs @@ -1,51 +1,25 @@ +use ecs::Component; + use crate::vector::Vec3; -pub trait Camera +#[derive(Debug, Component)] +pub struct Camera { - /// 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() - } + pub position: Vec3<f32>, + pub target: Vec3<f32>, + pub global_up: Vec3<f32>, + pub current: bool, +} - /// Returns the global direction upwards. - /// - /// The default implementation which returns [`Vec3::UP`] should be fine in most - /// cases. - fn global_up(&self) -> Vec3<f32> +impl Default for Camera +{ + fn default() -> Self { - Vec3::UP + Self { + position: Vec3 { x: 0.0, y: 0.0, z: 3.0 }, + target: Vec3::default(), + global_up: Vec3::UP, + current: false, + } } } |