From 4dd892442742254e2bbf0f8b081548218460ca1b Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 18 Aug 2022 11:37:29 -0700 Subject: [PATCH] clean up ortho2d to do less things --- src/math.zig | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/src/math.zig b/src/math.zig index 81c1f15b1..a5d526578 100644 --- a/src/math.zig +++ b/src/math.zig @@ -3,22 +3,13 @@ pub const F32x4 = @Vector(4, f32); /// Matrix type pub const Mat = [4]F32x4; -/// Identity matrix -pub fn identity() Mat { +pub fn ortho2d(left: f32, right: f32, bottom: f32, top: f32) Mat { + const w = right - left; + const h = top - bottom; return .{ - .{ 1.0, 0.0, 0.0, 0.0 }, - .{ 0.0, 1.0, 0.0, 0.0 }, - .{ 0.0, 0.0, 1.0, 0.0 }, - .{ 0.0, 0.0, 0.0, 1.0 }, + .{ 2 / w, 0, 0, 0 }, + .{ 0, 2 / h, 0, 0 }, + .{ 0.0, 0.0, -1.0, 0.0 }, + .{ -(right + left) / w, -(top + bottom) / h, 0.0, 1.0 }, }; } - -pub fn ortho2d(left: f32, right: f32, bottom: f32, top: f32) Mat { - var mat = identity(); - mat[0][0] = 2 / (right - left); - mat[1][1] = 2 / (top - bottom); - mat[2][2] = -1.0; - mat[3][0] = -(right + left) / (right - left); - mat[3][1] = -(top + bottom) / (top - bottom); - return mat; -}