diff options
Diffstat (limited to 'engine/src/projection.rs')
-rw-r--r-- | engine/src/projection.rs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/engine/src/projection.rs b/engine/src/projection.rs new file mode 100644 index 0000000..d5186ba --- /dev/null +++ b/engine/src/projection.rs @@ -0,0 +1,21 @@ +use crate::matrix::Matrix; + +/// Creates a new perspective projection matrix. +#[must_use] +pub fn new_perspective( + fov_radians: f32, + aspect: f32, + far: f32, + near: f32, +) -> Matrix<f32, 4, 4> +{ + let mut out = Matrix::new(); + + out.set_cell(0, 0, (1.0 / (fov_radians / 2.0).tan()) / aspect); + out.set_cell(1, 1, 1.0 / (fov_radians / 2.0).tan()); + out.set_cell(2, 2, (near + far) / (near - far)); + out.set_cell(2, 3, (2.0 * near * far) / (near - far)); + out.set_cell(3, 2, -1.0); + + out +} |