use crate::matrix::Matrix; #[derive(Debug)] #[non_exhaustive] pub enum Projection { Perspective(Perspective), } /// Perspective projection parameters. #[derive(Debug)] pub struct Perspective { pub fov_radians: f32, pub far: f32, pub near: f32, } impl Default for Perspective { fn default() -> Self { Self { fov_radians: 80.0f32.to_radians(), far: 100.0, near: 0.1, } } } pub(crate) fn new_perspective_matrix( perspective: &Perspective, aspect: f32, ) -> Matrix { let mut out = Matrix::new(); out.set_cell(0, 0, (1.0 / (perspective.fov_radians / 2.0).tan()) / aspect); out.set_cell(1, 1, 1.0 / (perspective.fov_radians / 2.0).tan()); out.set_cell( 2, 2, (perspective.near + perspective.far) / (perspective.near - perspective.far), ); out.set_cell( 2, 3, (2.0 * perspective.near * perspective.far) / (perspective.near - perspective.far), ); out.set_cell(3, 2, -1.0); out }