clean up ortho2d to do less things

This commit is contained in:
Mitchell Hashimoto
2022-08-18 11:37:29 -07:00
parent e5c583ccf5
commit 4dd8924427

View File

@ -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;
}