From 29166c3b95cb353e13346f07c01c525c71ce964f Mon Sep 17 00:00:00 2001 From: griffi-gh Date: Wed, 25 Jan 2023 04:11:55 +0100 Subject: [PATCH] upd camera --- src/camera.rs | 13 ++++++++----- src/events.rs | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/camera.rs b/src/camera.rs index 97efee5..f05935b 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -1,7 +1,7 @@ use glam::{Mat4, Vec3}; use shipyard::{Component, ViewMut, View, IntoIter, Workload, IntoWorkload}; use std::f32::consts::PI; -use crate::transform::Transform; +use crate::{transform::Transform, events::WindowResizedEvent}; #[derive(Component)] pub struct Camera { @@ -46,14 +46,17 @@ fn update_view_matrix( } fn update_perspective_matrix( - mut vm_camera: ViewMut + mut vm_camera: ViewMut, + resize: View, ) { - //todo compute this on win resize! - const ASPECT_RATIO: f32 = 16. / 9.; + //TODO update on launch + let Some(&size) = resize.iter().next() else { + return + }; for camera in (&mut vm_camera).iter() { camera.perspective_matrix = Mat4::perspective_rh_gl( camera.fov, - ASPECT_RATIO, + size.0.x as f32 / size.0.y as f32, camera.z_near, camera.z_far, ) diff --git a/src/events.rs b/src/events.rs index bab5db7..3a37298 100644 --- a/src/events.rs +++ b/src/events.rs @@ -15,7 +15,7 @@ pub struct InputDeviceEvent{ } #[derive(Component, Clone, Copy, Debug, Default)] -pub struct WindowResizedEvent(UVec2); +pub struct WindowResizedEvent(pub UVec2); pub fn process_glutin_events(world: &mut World, event: &Event<'_, ()>) { #[allow(clippy::collapsible_match, clippy::single_match)]