diff options
| author | HampusM <hampus@hampusmat.com> | 2026-08-11 09:53:25 +0200 |
|---|---|---|
| committer | HampusM <hampus@hampusmat.com> | 2026-08-11 09:53:25 +0200 |
| commit | 37496a6db6b73b987b881ddd568d4a609389670c (patch) | |
| tree | 85c54e5920893d958a751c78fa3dd30f06115c30 /engine/src/projection.rs | |
| parent | b732fa6378964ab9ca23fd71d7a82f39f6ae0009 (diff) | |
refactor(engine): move matrix creation fns to appropriate places
Diffstat (limited to 'engine/src/projection.rs')
| -rw-r--r-- | engine/src/projection.rs | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/engine/src/projection.rs b/engine/src/projection.rs index 747b8a8..e2d5cc1 100644 --- a/engine/src/projection.rs +++ b/engine/src/projection.rs @@ -3,6 +3,7 @@ use crate::data_types::dimens::Dimens; use crate::matrix::{CellPos as MatrixCellPos, Matrix}; use crate::reflection::Reflection; use crate::vector::Vec2; +use crate::windowing::dpi::PhysicalSize; #[derive(Debug, Clone, Reflection)] #[non_exhaustive] @@ -12,6 +13,26 @@ pub enum Projection Orthographic(Orthographic), } +impl Projection +{ + pub fn to_matrix_rh( + &self, + window_size: PhysicalSize<u32>, + clip_volume: ClipVolume, + ) -> Matrix<f32, 4, 4> + { + match self { + Projection::Perspective(perspective_proj) => perspective_proj.to_matrix_rh( + window_size.width as f32 / window_size.height as f32, + clip_volume, + ), + Projection::Orthographic(orthographic_proj) => { + orthographic_proj.to_matrix_rh(window_size, clip_volume) + } + } + } +} + /// Perspective projection parameters. #[derive(Debug, Clone, Reflection)] pub struct Perspective @@ -92,7 +113,7 @@ impl Orthographic /// Creates a orthographic projection matrix using right-handed coordinates. pub fn to_matrix_rh( &self, - window_size: Dimens<f32>, + window_size: PhysicalSize<u32>, clip_volume: ClipVolume, ) -> Matrix<f32, 4, 4> { @@ -100,7 +121,10 @@ impl Orthographic let size = match self.size { OrthographicSize::FixedSize(fixed_size) => fixed_size, - OrthographicSize::WindowSize => window_size, + OrthographicSize::WindowSize => Dimens { + width: window_size.width as f32, + height: window_size.height as f32, + }, }; let origin_x = size.width * self.viewport_origin.x; |
