UNPKG

@omnimedia/omnitool

Version:

open source video processing tools

36 lines 1.17 kB
import { Matrix } from "pixi.js"; export const transformToMat6 = (t) => { const [pos, scl, rotDeg] = t; const [x, y] = pos; const [sx, sy] = scl; const r = rotDeg * Math.PI / 180; const cos = Math.cos(r); const sin = Math.sin(r); return [cos * sx, sin * sx, -sin * sy, cos * sy, x, y]; }; export const mat6ToMatrix = ([a, b, c, d, tx, ty]) => new Matrix(a, b, c, d, tx, ty); export const transformToMatrix = (t) => mat6ToMatrix(transformToMat6(t)); export const mul6 = (local, parent) => { const [a1, b1, c1, d1, tx1, ty1] = local; const [a2, b2, c2, d2, tx2, ty2] = parent; return [ a1 * a2 + c1 * b2, b1 * a2 + d1 * b2, a1 * c2 + c1 * d2, b1 * c2 + d1 * d2, a1 * tx2 + c1 * ty2 + tx1, b1 * tx2 + d1 * ty2 + ty1 ]; }; export const mat6ToTransform = (mat) => { const scaleX = Math.hypot(mat.a, mat.b); const scaleY = Math.hypot(mat.c, mat.d); const rotation = Math.atan2(mat.b, mat.a) * (180 / Math.PI); return [ [mat.tx, mat.ty], [scaleX, scaleY], rotation, ]; }; export const I6 = [1, 0, 0, 1, 0, 0]; //# sourceMappingURL=matrix.js.map