You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
100 lines
2.3 KiB
100 lines
2.3 KiB
1 month ago
|
export function create() {
|
||
|
return [1, 0, 0, 1, 0, 0];
|
||
|
}
|
||
|
export function identity(out) {
|
||
|
out[0] = 1;
|
||
|
out[1] = 0;
|
||
|
out[2] = 0;
|
||
|
out[3] = 1;
|
||
|
out[4] = 0;
|
||
|
out[5] = 0;
|
||
|
return out;
|
||
|
}
|
||
|
export function copy(out, m) {
|
||
|
out[0] = m[0];
|
||
|
out[1] = m[1];
|
||
|
out[2] = m[2];
|
||
|
out[3] = m[3];
|
||
|
out[4] = m[4];
|
||
|
out[5] = m[5];
|
||
|
return out;
|
||
|
}
|
||
|
export function mul(out, m1, m2) {
|
||
|
var out0 = m1[0] * m2[0] + m1[2] * m2[1];
|
||
|
var out1 = m1[1] * m2[0] + m1[3] * m2[1];
|
||
|
var out2 = m1[0] * m2[2] + m1[2] * m2[3];
|
||
|
var out3 = m1[1] * m2[2] + m1[3] * m2[3];
|
||
|
var out4 = m1[0] * m2[4] + m1[2] * m2[5] + m1[4];
|
||
|
var out5 = m1[1] * m2[4] + m1[3] * m2[5] + m1[5];
|
||
|
out[0] = out0;
|
||
|
out[1] = out1;
|
||
|
out[2] = out2;
|
||
|
out[3] = out3;
|
||
|
out[4] = out4;
|
||
|
out[5] = out5;
|
||
|
return out;
|
||
|
}
|
||
|
export function translate(out, a, v) {
|
||
|
out[0] = a[0];
|
||
|
out[1] = a[1];
|
||
|
out[2] = a[2];
|
||
|
out[3] = a[3];
|
||
|
out[4] = a[4] + v[0];
|
||
|
out[5] = a[5] + v[1];
|
||
|
return out;
|
||
|
}
|
||
|
export function rotate(out, a, rad, pivot) {
|
||
|
if (pivot === void 0) { pivot = [0, 0]; }
|
||
|
var aa = a[0];
|
||
|
var ac = a[2];
|
||
|
var atx = a[4];
|
||
|
var ab = a[1];
|
||
|
var ad = a[3];
|
||
|
var aty = a[5];
|
||
|
var st = Math.sin(rad);
|
||
|
var ct = Math.cos(rad);
|
||
|
out[0] = aa * ct + ab * st;
|
||
|
out[1] = -aa * st + ab * ct;
|
||
|
out[2] = ac * ct + ad * st;
|
||
|
out[3] = -ac * st + ct * ad;
|
||
|
out[4] = ct * (atx - pivot[0]) + st * (aty - pivot[1]) + pivot[0];
|
||
|
out[5] = ct * (aty - pivot[1]) - st * (atx - pivot[0]) + pivot[1];
|
||
|
return out;
|
||
|
}
|
||
|
export function scale(out, a, v) {
|
||
|
var vx = v[0];
|
||
|
var vy = v[1];
|
||
|
out[0] = a[0] * vx;
|
||
|
out[1] = a[1] * vy;
|
||
|
out[2] = a[2] * vx;
|
||
|
out[3] = a[3] * vy;
|
||
|
out[4] = a[4] * vx;
|
||
|
out[5] = a[5] * vy;
|
||
|
return out;
|
||
|
}
|
||
|
export function invert(out, a) {
|
||
|
var aa = a[0];
|
||
|
var ac = a[2];
|
||
|
var atx = a[4];
|
||
|
var ab = a[1];
|
||
|
var ad = a[3];
|
||
|
var aty = a[5];
|
||
|
var det = aa * ad - ab * ac;
|
||
|
if (!det) {
|
||
|
return null;
|
||
|
}
|
||
|
det = 1.0 / det;
|
||
|
out[0] = ad * det;
|
||
|
out[1] = -ab * det;
|
||
|
out[2] = -ac * det;
|
||
|
out[3] = aa * det;
|
||
|
out[4] = (ac * aty - ad * atx) * det;
|
||
|
out[5] = (ab * atx - aa * aty) * det;
|
||
|
return out;
|
||
|
}
|
||
|
export function clone(a) {
|
||
|
var b = create();
|
||
|
copy(b, a);
|
||
|
return b;
|
||
|
}
|