radarmp/mp_elements/src/renderer/projection.rs
2024-11-15 17:10:18 +08:00

27 lines
598 B
Rust

use glam::*;
pub struct Projection {
aspect: f32,
fovy: f32,
znear: f32,
zfar: f32,
}
impl Projection {
pub fn new(width: u32, height: u32, fovy: f32, z_near: f32, z_far: f32) -> Self {
Self {
aspect: width as f32 / height as f32,
fovy,
znear: z_near,
zfar: z_far,
}
}
pub fn resize(&mut self, width: u32, height: u32) {
self.aspect = width as f32 / height as f32;
}
pub fn calc_matrix(&self) -> Mat4 {
Mat4::perspective_rh(self.fovy, self.aspect, self.znear, self.zfar)
}
}