diff options
Diffstat (limited to 'client/src/camera.rs')
-rw-r--r-- | client/src/camera.rs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/client/src/camera.rs b/client/src/camera.rs new file mode 100644 index 0000000..289e773 --- /dev/null +++ b/client/src/camera.rs @@ -0,0 +1,37 @@ +use glam::{EulerRot, Mat3, Mat4, Vec2, Vec3}; + +pub struct Camera { + pos: Vec3, + rot: Vec3, + fov: f32, + aspect: f32, +} + +impl Camera { + pub fn new() -> Self { + Self { + aspect: 1., + fov: 0.5, + pos: Vec3::Z * 3., + rot: Vec3::ZERO, + } + } + pub fn update(&mut self, input_move: Vec3, input_rot: Vec2, dt: f32) { + self.pos += input_move * dt; + self.rot.x += input_rot.x * 0.002; + self.rot.y += input_rot.y * 0.002; + } + pub fn to_matrix(&self) -> Mat4 { + // let tdir = + // Mat3::from_euler(EulerRot::ZXY, self.rot.x, self.rot.y, self.rot.z) * Vec3::NEG_Z; + // * Mat4::look_at_rh(self.pos, self.pos + tdir, Vec3::Y) + + Mat4::perspective_infinite_reverse_rh(self.fov, self.aspect, 0.1) + * Mat4::from_mat3(Mat3::from_euler( + EulerRot::ZXY, + self.rot.x, + self.rot.y, + self.rot.z, + )) + } +} |