From 7b0edcfc6a07ff4d64e602f2b68d93fedc8b826d Mon Sep 17 00:00:00 2001 From: HampusM Date: Sun, 2 Aug 2026 16:11:30 +0200 Subject: fix(engine): improve portability by making matrices row-major --- engine/src/projection.rs | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) (limited to 'engine/src/projection.rs') 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; } } -- cgit v1.2.3-18-g5258