mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-21 19:26:09 +03:00
clean up ortho2d to do less things
This commit is contained in:
23
src/math.zig
23
src/math.zig
@ -3,22 +3,13 @@ pub const F32x4 = @Vector(4, f32);
|
|||||||
/// Matrix type
|
/// Matrix type
|
||||||
pub const Mat = [4]F32x4;
|
pub const Mat = [4]F32x4;
|
||||||
|
|
||||||
/// Identity matrix
|
pub fn ortho2d(left: f32, right: f32, bottom: f32, top: f32) Mat {
|
||||||
pub fn identity() Mat {
|
const w = right - left;
|
||||||
|
const h = top - bottom;
|
||||||
return .{
|
return .{
|
||||||
.{ 1.0, 0.0, 0.0, 0.0 },
|
.{ 2 / w, 0, 0, 0 },
|
||||||
.{ 0.0, 1.0, 0.0, 0.0 },
|
.{ 0, 2 / h, 0, 0 },
|
||||||
.{ 0.0, 0.0, 1.0, 0.0 },
|
.{ 0.0, 0.0, -1.0, 0.0 },
|
||||||
.{ 0.0, 0.0, 0.0, 1.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;
|
|
||||||
}
|
|
||||||
|
Reference in New Issue
Block a user