diff options
author | HampusM <hampus@hampusmat.com> | 2023-10-25 21:15:41 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2023-10-25 21:16:10 +0200 |
commit | fd535654369b31e1283a609ba8e8fcf0df42100b (patch) | |
tree | 2509bd71d835a4389ff7578dc6314d6019e31d01 /engine/src/camera.rs | |
parent | 0c0dc186b542bf6bdd7645ba091dc2a47a03fa97 (diff) |
feat(engine): make camera look at a target position
Diffstat (limited to 'engine/src/camera.rs')
-rw-r--r-- | engine/src/camera.rs | 47 |
1 files changed, 35 insertions, 12 deletions
diff --git a/engine/src/camera.rs b/engine/src/camera.rs index b98f3f4..1546960 100644 --- a/engine/src/camera.rs +++ b/engine/src/camera.rs @@ -1,34 +1,57 @@ -use crate::transform::Transform; +use crate::matrix::Matrix; use crate::vector::Vec3; #[derive(Debug)] pub struct Camera { - transform: Transform, + position: Vec3<f32>, + target: Vec3<f32>, } impl Camera { - pub fn translate(&mut self, translation: Vec3<f32>) + pub fn set_position(&mut self, position: Vec3<f32>) { - self.transform.set_translation(translation); + self.position = position; } - pub(crate) fn new() -> Self + #[must_use] + pub fn position(&self) -> &Vec3<f32> + { + &self.position + } + + pub fn set_target(&mut self, target: Vec3<f32>) + { + self.target = target; + } + + #[must_use] + pub fn target(&self) -> &Vec3<f32> { - let mut transform = Transform::new(); + &self.target + } - transform.set_translation(Vec3 { + pub(crate) fn new() -> Self + { + let position = Vec3 { x: 0.0, y: 0.0, - z: -3.0, - }); + z: 3.0, + }; - Self { transform } + Self { + position, + target: Vec3::default(), + } } - pub(crate) fn transform(&self) -> &Transform + pub(crate) fn as_matrix(&self) -> Matrix<f32, 4, 4> { - &self.transform + let mut matrix = Matrix::new(); + + matrix.look_at(&self.position, &self.target, &Vec3::UP); + + matrix } } |