summaryrefslogtreecommitdiff
path: root/frontend/_rigidbody/mat4.js
blob: 6ab29e24c97485999aed8b2ac1948fb7adb0ae6a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
function mat4() {
    return [
        1, 0, 0, 0,
        0, 1, 0, 0,
        0, 0, 1, 0,
        0, 0, 0, 1
    ]
}

function orthographic(pLeft, pRight, pBottom, pTop) {
    const lResult = mat4();
    lResult[0] = 2.0 / (pRight - pLeft);
    lResult[5] = 2.0 / (pTop - pBottom);
    lResult[10] = 1.0;
    lResult[12] = -(pRight + pLeft) / (pRight - pLeft);
    lResult[13] = -(pTop + pBottom) / (pTop - pBottom);
    return lResult;
}

function translateMatrix(m, x, y, z) {
    m = [...m];
    m[12] += x;
    m[13] += y;
    m[14] += z;
    return m;
}

function rotateMatrix2d(m, angle) {
    m = [...m];
    m[0] = Math.cos(angle);
    m[1] = -Math.sin(angle);
    m[4] = Math.sin(angle);
    m[5] = Math.cos(angle);
    return m;
}

function scaleMatrix(m, x, y, z) {
    m = [...m];
    m[0] = m[0] * x;
    m[5] = m[5] * y;
    m[10] = m[10] * z;
    return m;
}