camera: Change camera to Camera3D
Some checks failed
Build legacy Nix package on Ubuntu / build (push) Failing after 9m38s

This commit is contained in:
Florian RICHER 2025-05-29 16:46:11 +02:00
parent 3a562fb6eb
commit f8b81f3269
Signed by: florian.richer
GPG key ID: C73D37CBED7BFC77
2 changed files with 25 additions and 9 deletions

View file

@ -20,19 +20,27 @@ const OPENGL_TO_VULKAN_Y_AXIS_FLIP: Mat4 = Mat4 {
};
#[derive(Default)]
pub struct Camera {
pub struct Camera3D {
projection: Mat4,
position: Vec3,
rotation: Vec3,
aspect_ratio: f32,
fov: f32,
near: f32,
far: f32,
}
impl Camera {
pub fn new(projection: Mat4) -> Self {
impl Camera3D {
pub fn new(aspect_ratio: f32, fov: f32, near: f32, far: f32) -> Self {
Self {
projection,
projection: Mat4::perspective_rh(fov, aspect_ratio, near, far),
position: Vec3::ZERO,
rotation: Vec3::ZERO,
aspect_ratio,
fov,
near,
far,
}
}
@ -42,6 +50,7 @@ impl Camera {
timer: &Timer,
movement_speed: f32,
camera_sensitivity: f32,
window_aspect_ratio: f32,
) {
// Process camera rotation
let camera_delta = camera_sensitivity * timer.delta_time();
@ -70,6 +79,12 @@ impl Camera {
let tz = input_manager.get_virtual_input_state("move_forward") * movement_delta;
self.position += tz * forward;
if self.aspect_ratio != window_aspect_ratio {
self.aspect_ratio = window_aspect_ratio;
self.projection =
Mat4::perspective_rh(self.fov, self.aspect_ratio, self.near, self.far);
}
}
pub fn set_projection(&mut self, projection: Mat4) {