summaryrefslogtreecommitdiff
path: root/frontend/_shared/math/mat4.js
diff options
context:
space:
mode:
authorMatthew Kosarek <matthew.kosarek@vention.cc>2021-02-23 19:39:16 -0500
committerMatthew Kosarek <matthew.kosarek@vention.cc>2021-02-23 19:39:16 -0500
commitf0d1398b0d1b1a7c5bd1d4e0b3488b7f1aa74364 (patch)
tree4279b063052fb71ef5ff34a2f2f93d5c7b870b98 /frontend/_shared/math/mat4.js
parentece2b67aa689aee0b881bac17a62c16e0469bc56 (diff)
Big rework of the directory structure to make it more orderly for my brain
Diffstat (limited to 'frontend/_shared/math/mat4.js')
-rw-r--r--frontend/_shared/math/mat4.js43
1 files changed, 43 insertions, 0 deletions
diff --git a/frontend/_shared/math/mat4.js b/frontend/_shared/math/mat4.js
new file mode 100644
index 0000000..6ab29e2
--- /dev/null
+++ b/frontend/_shared/math/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