From c10f3e758f7d98750cfffef336a124d6d65c636f Mon Sep 17 00:00:00 2001 From: HampusM Date: Wed, 22 Jan 2025 18:12:21 +0100 Subject: refactor(engine): clarify & add docs to Perspective::to_matrix --- engine/src/projection.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'engine/src/projection.rs') diff --git a/engine/src/projection.rs b/engine/src/projection.rs index ecbe297..faa741f 100644 --- a/engine/src/projection.rs +++ b/engine/src/projection.rs @@ -22,15 +22,22 @@ pub struct Perspective impl Perspective { - pub fn to_matrix(&self, aspect: f32) -> Matrix + /// Creates a perspective projection matrix using right-handed coordinates. + #[inline] + pub fn to_matrix_rh(&self, aspect: f32, clip_volume: ClipVolume) + -> Matrix { let mut out = Matrix::new(); - 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); + 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 } -- cgit v1.2.3-18-g5258