From 3a562fb6ebf3ecfc0bfd9583444cac89d9ca9cfe Mon Sep 17 00:00:00 2001 From: Florian RICHER Date: Thu, 29 May 2025 16:38:45 +0200 Subject: [PATCH] camera: Fix Y inverted --- src/core/render/primitives/camera.rs | 10 +++++++++- src/game/main_scene.rs | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/core/render/primitives/camera.rs b/src/core/render/primitives/camera.rs index 34950ce..f1f48d7 100644 --- a/src/core/render/primitives/camera.rs +++ b/src/core/render/primitives/camera.rs @@ -11,6 +11,14 @@ use crate::core::{input::InputManager, timer::Timer}; use super::mvp::MVP; +// See docs/OPENGL_VULKAN_DIFF.md +const OPENGL_TO_VULKAN_Y_AXIS_FLIP: Mat4 = Mat4 { + x_axis: Vec4::new(1.0, 0.0, 0.0, 0.0), + y_axis: Vec4::new(0.0, -1.0, 0.0, 0.0), + z_axis: Vec4::new(0.0, 0.0, 1.0, 0.0), + w_axis: Vec4::new(0.0, 0.0, 0.0, 1.0), +}; + #[derive(Default)] pub struct Camera { projection: Mat4, @@ -90,7 +98,7 @@ impl Camera { ); MVP { - model: Mat4::IDENTITY.to_cols_array_2d(), + model: OPENGL_TO_VULKAN_Y_AXIS_FLIP.to_cols_array_2d(), view: view_matrix.to_cols_array_2d(), projection: self.projection.to_cols_array_2d(), } diff --git a/src/game/main_scene.rs b/src/game/main_scene.rs index 0aa18ac..03f54ea 100644 --- a/src/game/main_scene.rs +++ b/src/game/main_scene.rs @@ -43,7 +43,7 @@ impl Scene for MainScene { scene_context.swapchain_format, )?; - let camera = Camera::new(Mat4::perspective_rh_gl( + let camera = Camera::new(Mat4::perspective_rh( std::f32::consts::FRAC_PI_2, scene_context.aspect_ratio, 0.01,