summaryrefslogtreecommitdiff
path: root/engine/src/projection.rs
blob: d5186ba580e32748aa0f97ec9e4795651155c282 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
}