summaryrefslogtreecommitdiff
path: root/engine/src/projection.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2023-10-23 22:23:25 +0200
committerHampusM <hampus@hampusmat.com>2023-10-23 22:23:25 +0200
commit386aad9dac7c22cabb0f1bbba33d248c40bb0310 (patch)
tree1f4379ab50ffc85e9ad511b9fe9e9dd8a7f8c321 /engine/src/projection.rs
parentfee2320189d6e758748a939c56d539043cbffde6 (diff)
feat(engine): add perspective
Diffstat (limited to 'engine/src/projection.rs')
-rw-r--r--engine/src/projection.rs21
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
+}