summaryrefslogtreecommitdiff
path: root/engine
diff options
context:
space:
mode:
Diffstat (limited to 'engine')
-rw-r--r--engine/src/projection.rs55
1 files changed, 38 insertions, 17 deletions
diff --git a/engine/src/projection.rs b/engine/src/projection.rs
index 2191a93..b3bfa00 100644
--- a/engine/src/projection.rs
+++ b/engine/src/projection.rs
@@ -119,8 +119,6 @@ impl Orthographic
clip_volume: ClipVolume,
) -> Matrix<f32, 4, 4>
{
- let mut result = Matrix::<f32, 4, 4>::new();
-
let size = match self.size {
OrthographicSize::FixedSize(fixed_size) => fixed_size,
OrthographicSize::WindowSize => Dimens {
@@ -141,21 +139,10 @@ impl Orthographic
let near = self.near;
let far = self.far;
- match clip_volume {
- ClipVolume::NegOneToOne => {
- 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;
- }
- }
-
- result
+ orthographic_rh(
+ OrthographicParams { left, right, bottom, top, near, far },
+ clip_volume,
+ )
}
}
@@ -187,3 +174,37 @@ pub enum ClipVolume
/// -1 to +1. This is the OpenGL clip volume definition.
NegOneToOne,
}
+
+#[derive(Debug, Clone)]
+pub struct OrthographicParams
+{
+ pub left: f32,
+ pub right: f32,
+ pub bottom: f32,
+ pub top: f32,
+ pub near: f32,
+ pub far: f32,
+}
+
+/// Creates a orthographic projection matrix using right-handed coordinates.
+pub fn orthographic_rh(
+ OrthographicParams { left, right, bottom, top, near, far }: OrthographicParams,
+ clip_volume: ClipVolume,
+) -> Matrix<f32, 4, 4>
+{
+ let mut result = Matrix::<f32, 4, 4>::new();
+
+ match clip_volume {
+ ClipVolume::NegOneToOne => {
+ 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;
+ }
+ }
+
+ result
+}