diff options
| author | HampusM <hampus@hampusmat.com> | 2026-08-02 16:11:30 +0200 |
|---|---|---|
| committer | HampusM <hampus@hampusmat.com> | 2026-08-02 17:52:03 +0200 |
| commit | 7b0edcfc6a07ff4d64e602f2b68d93fedc8b826d (patch) | |
| tree | 6077257d6a920c13ef62c22564343ae952ad81d7 /engine/src/projection.rs | |
| parent | 3f9750edecad1615348d9ec0995a2fbde468c8a3 (diff) | |
fix(engine): improve portability by making matrices row-major
Diffstat (limited to 'engine/src/projection.rs')
| -rw-r--r-- | engine/src/projection.rs | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/engine/src/projection.rs b/engine/src/projection.rs index ea3d7ed..747b8a8 100644 --- a/engine/src/projection.rs +++ b/engine/src/projection.rs @@ -1,6 +1,6 @@ use crate::builder; use crate::data_types::dimens::Dimens; -use crate::matrix::Matrix; +use crate::matrix::{CellPos as MatrixCellPos, Matrix}; use crate::reflection::Reflection; use crate::vector::Vec2; @@ -32,11 +32,15 @@ impl Perspective match clip_volume { ClipVolume::NegOneToOne => { - out.set_cell(0, 0, (1.0 / (self.fov_radians / 2.0).tan()) / aspect); - out.set_cell(1, 1, 1.0 / (self.fov_radians / 2.0).tan()); - out.set_cell(2, 2, (self.near + self.far) / (self.near - self.far)); - out.set_cell(2, 3, (2.0 * self.near * self.far) / (self.near - self.far)); - out.set_cell(3, 2, -1.0); + out[MatrixCellPos { row: 0, col: 0 }] = + (1.0 / (self.fov_radians / 2.0).tan()) / aspect; + out[MatrixCellPos { row: 1, col: 1 }] = + 1.0 / (self.fov_radians / 2.0).tan(); + out[MatrixCellPos { row: 2, col: 2 }] = + (self.near + self.far) / (self.near - self.far); + out[MatrixCellPos { row: 2, col: 3 }] = + (2.0 * self.near * self.far) / (self.near - self.far); + out[MatrixCellPos { row: 3, col: 2 }] = -1.0; } } @@ -113,13 +117,15 @@ impl Orthographic match clip_volume { ClipVolume::NegOneToOne => { - result.set_cell(0, 0, 2.0 / (right - left)); - result.set_cell(1, 1, 2.0 / (top - bottom)); - result.set_cell(2, 2, -2.0 / (far - near)); - result.set_cell(0, 3, -(right + left) / (right - left)); - result.set_cell(1, 3, -(top + bottom) / (top - bottom)); - result.set_cell(2, 3, -(far + near) / (far - near)); - result.set_cell(3, 3, 1.0); + result[MatrixCellPos { row: 0, col: 0 }] = 2.0 / (right - left); + result[MatrixCellPos { row: 1, col: 1 }] = 2.0 / (top - bottom); + result[MatrixCellPos { row: 2, col: 2 }] = -2.0 / (far - near); + result[MatrixCellPos { row: 0, col: 3 }] = + -(right + left) / (right - left); + result[MatrixCellPos { row: 1, col: 3 }] = + -(top + bottom) / (top - bottom); + result[MatrixCellPos { row: 2, col: 3 }] = -(far + near) / (far - near); + result[MatrixCellPos { row: 3, col: 3 }] = 1.0; } } |
