diff options
author | Matthew Kosarek <mattkae@protonmail.com> | 2021-02-06 18:39:48 -0500 |
---|---|---|
committer | Matthew Kosarek <mattkae@protonmail.com> | 2021-02-06 18:39:48 -0500 |
commit | 376e1a7f9207fffb1ec3027ac1e7f32db5de4922 (patch) | |
tree | 8bc6c381a10d8b62ff33cdcff6daa1d17cee0f9a /frontend/_rigidbody/mat4.js |
Initial commit
Diffstat (limited to 'frontend/_rigidbody/mat4.js')
-rw-r--r-- | frontend/_rigidbody/mat4.js | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/frontend/_rigidbody/mat4.js b/frontend/_rigidbody/mat4.js new file mode 100644 index 0000000..6ab29e2 --- /dev/null +++ b/frontend/_rigidbody/mat4.js @@ -0,0 +1,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; +}
\ No newline at end of file |