get rid of gb_math and create matrices from scratch

This commit is contained in:
Mitchell Hashimoto
2022-08-18 11:33:28 -07:00
parent b562eec83c
commit e5c583ccf5
7 changed files with 37 additions and 2259 deletions

24
src/math.zig Normal file
View File

@@ -0,0 +1,24 @@
pub const F32x4 = @Vector(4, f32);
/// Matrix type
pub const Mat = [4]F32x4;
/// Identity matrix
pub fn identity() Mat {
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 },
};
}
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;
}