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