import { __assign, __read, __spread } from "tslib";
export var createMatrix4 = function () { return ({
    //prettier-ignore
    elements: [
        1, 0, 0, 0,
        0, 1, 0, 0,
        0, 0, 1, 0,
        0, 0, 0, 1
    ]
}); };
export var cloneMatrix4 = function (matrix) { return (__assign(__assign({}, matrix), { elements: __spread(matrix.elements) })); };
export var createMatrix4FromQuaternion = function (quaternion) {
    var matrix = createMatrix4();
    return makeRotationFromQuaternion(matrix, quaternion);
};
export var makeRotationFromQuaternion = function (matrix, quaternion) {
    var x = quaternion.x, y = quaternion.y, z = quaternion.z, w = quaternion.w;
    var x2 = x + x, y2 = y + y, z2 = z + z;
    var xx = x * x2, xy = x * y2, xz = x * z2;
    var yy = y * y2, yz = y * z2, zz = z * z2;
    var wx = w * x2, wy = w * y2, wz = w * z2;
    matrix.elements[0] = 1 - (yy + zz);
    matrix.elements[4] = xy - wz;
    matrix.elements[8] = xz + wy;
    matrix.elements[1] = xy + wz;
    matrix.elements[5] = 1 - (xx + zz);
    matrix.elements[9] = yz - wx;
    matrix.elements[2] = xz - wy;
    matrix.elements[6] = yz + wx;
    matrix.elements[10] = 1 - (xx + yy);
    // last column
    matrix.elements[3] = 0;
    matrix.elements[7] = 0;
    matrix.elements[11] = 0;
    // bottom row
    matrix.elements[12] = 0;
    matrix.elements[13] = 0;
    matrix.elements[14] = 0;
    matrix.elements[15] = 1;
    return matrix;
};
