@math.gl/core 4.0.0 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/dist/classes/base/math-array.d.ts +1 -2
  2. package/dist/classes/base/math-array.js +220 -266
  3. package/dist/classes/base/matrix.d.ts +1 -2
  4. package/dist/classes/base/matrix.js +52 -53
  5. package/dist/classes/base/vector.d.ts +1 -2
  6. package/dist/classes/base/vector.js +121 -135
  7. package/dist/classes/euler.d.ts +2 -3
  8. package/dist/classes/euler.js +462 -533
  9. package/dist/classes/matrix3.d.ts +2 -3
  10. package/dist/classes/matrix3.js +185 -190
  11. package/dist/classes/matrix4.d.ts +1 -2
  12. package/dist/classes/matrix4.js +516 -452
  13. package/dist/classes/pose.d.ts +4 -5
  14. package/dist/classes/pose.js +104 -119
  15. package/dist/classes/quaternion.d.ts +1 -2
  16. package/dist/classes/quaternion.js +257 -233
  17. package/dist/classes/spherical-coordinates.d.ts +3 -4
  18. package/dist/classes/spherical-coordinates.js +138 -147
  19. package/dist/classes/vector2.d.ts +1 -2
  20. package/dist/classes/vector2.js +101 -85
  21. package/dist/classes/vector3.d.ts +1 -2
  22. package/dist/classes/vector3.js +125 -136
  23. package/dist/classes/vector4.d.ts +2 -3
  24. package/dist/classes/vector4.js +106 -114
  25. package/dist/gl-matrix/common.d.ts +0 -1
  26. package/dist/gl-matrix/common.js +38 -6
  27. package/dist/gl-matrix/mat3.d.ts +0 -1
  28. package/dist/gl-matrix/mat3.js +699 -425
  29. package/dist/gl-matrix/mat4.d.ts +0 -1
  30. package/dist/gl-matrix/mat4.js +1879 -1339
  31. package/dist/gl-matrix/quat.d.ts +0 -1
  32. package/dist/gl-matrix/quat.js +655 -257
  33. package/dist/gl-matrix/vec2.d.ts +0 -1
  34. package/dist/gl-matrix/vec2.js +529 -212
  35. package/dist/gl-matrix/vec3.d.ts +0 -1
  36. package/dist/gl-matrix/vec3.js +703 -335
  37. package/dist/gl-matrix/vec4.d.ts +0 -1
  38. package/dist/gl-matrix/vec4.js +579 -293
  39. package/dist/gl-matrix/wip/index.d.ts +3 -4
  40. package/dist/gl-matrix/wip/index.js +2 -1
  41. package/dist/gl-matrix/wip/mat2.d.ts +0 -1
  42. package/dist/gl-matrix/wip/mat2.js +333 -157
  43. package/dist/gl-matrix/wip/mat2d.d.ts +0 -1
  44. package/dist/gl-matrix/wip/mat2d.js +377 -202
  45. package/dist/gl-matrix/wip/quat2.d.ts +0 -1
  46. package/dist/gl-matrix/wip/quat2.js +647 -409
  47. package/dist/index.cjs +60 -100
  48. package/dist/index.cjs.map +7 -0
  49. package/dist/index.d.ts +21 -22
  50. package/dist/index.js +23 -16
  51. package/dist/lib/assert.d.ts +0 -1
  52. package/dist/lib/assert.js +3 -4
  53. package/dist/lib/common.d.ts +2 -3
  54. package/dist/lib/common.js +163 -134
  55. package/dist/lib/gl-matrix-extras.d.ts +0 -1
  56. package/dist/lib/gl-matrix-extras.js +39 -36
  57. package/dist/lib/math-utils.d.ts +0 -1
  58. package/dist/lib/math-utils.js +2 -1
  59. package/dist/lib/validators.d.ts +0 -1
  60. package/dist/lib/validators.js +22 -25
  61. package/package.json +5 -6
  62. package/src/classes/matrix3.ts +1 -1
  63. package/dist/classes/base/math-array.d.ts.map +0 -1
  64. package/dist/classes/base/math-array.js.map +0 -1
  65. package/dist/classes/base/matrix.d.ts.map +0 -1
  66. package/dist/classes/base/matrix.js.map +0 -1
  67. package/dist/classes/base/vector.d.ts.map +0 -1
  68. package/dist/classes/base/vector.js.map +0 -1
  69. package/dist/classes/euler.d.ts.map +0 -1
  70. package/dist/classes/euler.js.map +0 -1
  71. package/dist/classes/matrix3.d.ts.map +0 -1
  72. package/dist/classes/matrix3.js.map +0 -1
  73. package/dist/classes/matrix4.d.ts.map +0 -1
  74. package/dist/classes/matrix4.js.map +0 -1
  75. package/dist/classes/pose.d.ts.map +0 -1
  76. package/dist/classes/pose.js.map +0 -1
  77. package/dist/classes/quaternion.d.ts.map +0 -1
  78. package/dist/classes/quaternion.js.map +0 -1
  79. package/dist/classes/spherical-coordinates.d.ts.map +0 -1
  80. package/dist/classes/spherical-coordinates.js.map +0 -1
  81. package/dist/classes/vector2.d.ts.map +0 -1
  82. package/dist/classes/vector2.js.map +0 -1
  83. package/dist/classes/vector3.d.ts.map +0 -1
  84. package/dist/classes/vector3.js.map +0 -1
  85. package/dist/classes/vector4.d.ts.map +0 -1
  86. package/dist/classes/vector4.js.map +0 -1
  87. package/dist/gl-matrix/common.d.ts.map +0 -1
  88. package/dist/gl-matrix/common.js.map +0 -1
  89. package/dist/gl-matrix/mat3.d.ts.map +0 -1
  90. package/dist/gl-matrix/mat3.js.map +0 -1
  91. package/dist/gl-matrix/mat4.d.ts.map +0 -1
  92. package/dist/gl-matrix/mat4.js.map +0 -1
  93. package/dist/gl-matrix/quat.d.ts.map +0 -1
  94. package/dist/gl-matrix/quat.js.map +0 -1
  95. package/dist/gl-matrix/vec2.d.ts.map +0 -1
  96. package/dist/gl-matrix/vec2.js.map +0 -1
  97. package/dist/gl-matrix/vec3.d.ts.map +0 -1
  98. package/dist/gl-matrix/vec3.js.map +0 -1
  99. package/dist/gl-matrix/vec4.d.ts.map +0 -1
  100. package/dist/gl-matrix/vec4.js.map +0 -1
  101. package/dist/gl-matrix/wip/index.d.ts.map +0 -1
  102. package/dist/gl-matrix/wip/index.js.map +0 -1
  103. package/dist/gl-matrix/wip/mat2.d.ts.map +0 -1
  104. package/dist/gl-matrix/wip/mat2.js.map +0 -1
  105. package/dist/gl-matrix/wip/mat2d.d.ts.map +0 -1
  106. package/dist/gl-matrix/wip/mat2d.js.map +0 -1
  107. package/dist/gl-matrix/wip/quat2.d.ts.map +0 -1
  108. package/dist/gl-matrix/wip/quat2.js.map +0 -1
  109. package/dist/gl-matrix/wip/types.d.js +0 -2
  110. package/dist/gl-matrix/wip/types.d.js.map +0 -1
  111. package/dist/index.d.ts.map +0 -1
  112. package/dist/index.js.map +0 -1
  113. package/dist/lib/assert.d.ts.map +0 -1
  114. package/dist/lib/assert.js.map +0 -1
  115. package/dist/lib/common.d.ts.map +0 -1
  116. package/dist/lib/common.js.map +0 -1
  117. package/dist/lib/gl-matrix-extras.d.ts.map +0 -1
  118. package/dist/lib/gl-matrix-extras.js.map +0 -1
  119. package/dist/lib/gl-matrix.d.js +0 -2
  120. package/dist/lib/gl-matrix.d.js.map +0 -1
  121. package/dist/lib/math-utils.d.ts.map +0 -1
  122. package/dist/lib/math-utils.js.map +0 -1
  123. package/dist/lib/validators.d.ts.map +0 -1
  124. package/dist/lib/validators.js.map +0 -1
@@ -1,370 +1,595 @@
1
+ // @eslint-disable
2
+ // @ts-nocheck
1
3
  import * as glMatrix from './common.js';
4
+ /**
5
+ * 4x4 Matrix<br>Format: column-major, when typed out it looks like row-major<br>The matrices are being post multiplied.
6
+ * @module mat4
7
+ */
8
+ /**
9
+ * Creates a new identity mat4
10
+ *
11
+ * @returns a new 4x4 matrix
12
+ */
2
13
  export function create() {
3
- const out = new glMatrix.ARRAY_TYPE(16);
4
-
5
- if (glMatrix.ARRAY_TYPE != Float32Array) {
14
+ const out = new glMatrix.ARRAY_TYPE(16);
15
+ if (glMatrix.ARRAY_TYPE != Float32Array) {
16
+ out[1] = 0;
17
+ out[2] = 0;
18
+ out[3] = 0;
19
+ out[4] = 0;
20
+ out[6] = 0;
21
+ out[7] = 0;
22
+ out[8] = 0;
23
+ out[9] = 0;
24
+ out[11] = 0;
25
+ out[12] = 0;
26
+ out[13] = 0;
27
+ out[14] = 0;
28
+ }
29
+ out[0] = 1;
30
+ out[5] = 1;
31
+ out[10] = 1;
32
+ out[15] = 1;
33
+ return out;
34
+ }
35
+ /**
36
+ * Creates a new mat4 initialized with values from an existing matrix
37
+ *
38
+ * @param {ReadonlyMat4} a matrix to clone
39
+ * @returns {mat4} a new 4x4 matrix
40
+ */
41
+ export function clone(a) {
42
+ const out = new glMatrix.ARRAY_TYPE(16);
43
+ out[0] = a[0];
44
+ out[1] = a[1];
45
+ out[2] = a[2];
46
+ out[3] = a[3];
47
+ out[4] = a[4];
48
+ out[5] = a[5];
49
+ out[6] = a[6];
50
+ out[7] = a[7];
51
+ out[8] = a[8];
52
+ out[9] = a[9];
53
+ out[10] = a[10];
54
+ out[11] = a[11];
55
+ out[12] = a[12];
56
+ out[13] = a[13];
57
+ out[14] = a[14];
58
+ out[15] = a[15];
59
+ return out;
60
+ }
61
+ /**
62
+ * Copy the values from one mat4 to another
63
+ *
64
+ * @param {mat4} out the receiving matrix
65
+ * @param {ReadonlyMat4} a the source matrix
66
+ * @returns {mat4} out
67
+ */
68
+ export function copy(out, a) {
69
+ out[0] = a[0];
70
+ out[1] = a[1];
71
+ out[2] = a[2];
72
+ out[3] = a[3];
73
+ out[4] = a[4];
74
+ out[5] = a[5];
75
+ out[6] = a[6];
76
+ out[7] = a[7];
77
+ out[8] = a[8];
78
+ out[9] = a[9];
79
+ out[10] = a[10];
80
+ out[11] = a[11];
81
+ out[12] = a[12];
82
+ out[13] = a[13];
83
+ out[14] = a[14];
84
+ out[15] = a[15];
85
+ return out;
86
+ }
87
+ /**
88
+ * Create a new mat4 with the given values
89
+ *
90
+ * @param {Number} m00 Component in column 0, row 0 position (index 0)
91
+ * @param {Number} m01 Component in column 0, row 1 position (index 1)
92
+ * @param {Number} m02 Component in column 0, row 2 position (index 2)
93
+ * @param {Number} m03 Component in column 0, row 3 position (index 3)
94
+ * @param {Number} m10 Component in column 1, row 0 position (index 4)
95
+ * @param {Number} m11 Component in column 1, row 1 position (index 5)
96
+ * @param {Number} m12 Component in column 1, row 2 position (index 6)
97
+ * @param {Number} m13 Component in column 1, row 3 position (index 7)
98
+ * @param {Number} m20 Component in column 2, row 0 position (index 8)
99
+ * @param {Number} m21 Component in column 2, row 1 position (index 9)
100
+ * @param {Number} m22 Component in column 2, row 2 position (index 10)
101
+ * @param {Number} m23 Component in column 2, row 3 position (index 11)
102
+ * @param {Number} m30 Component in column 3, row 0 position (index 12)
103
+ * @param {Number} m31 Component in column 3, row 1 position (index 13)
104
+ * @param {Number} m32 Component in column 3, row 2 position (index 14)
105
+ * @param {Number} m33 Component in column 3, row 3 position (index 15)
106
+ * @returns {mat4} A new mat4
107
+ */
108
+ export function fromValues(m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33) {
109
+ const out = new glMatrix.ARRAY_TYPE(16);
110
+ out[0] = m00;
111
+ out[1] = m01;
112
+ out[2] = m02;
113
+ out[3] = m03;
114
+ out[4] = m10;
115
+ out[5] = m11;
116
+ out[6] = m12;
117
+ out[7] = m13;
118
+ out[8] = m20;
119
+ out[9] = m21;
120
+ out[10] = m22;
121
+ out[11] = m23;
122
+ out[12] = m30;
123
+ out[13] = m31;
124
+ out[14] = m32;
125
+ out[15] = m33;
126
+ return out;
127
+ }
128
+ /**
129
+ * Set the components of a mat4 to the given values
130
+ *
131
+ * @param {mat4} out the receiving matrix
132
+ * @param {Number} m00 Component in column 0, row 0 position (index 0)
133
+ * @param {Number} m01 Component in column 0, row 1 position (index 1)
134
+ * @param {Number} m02 Component in column 0, row 2 position (index 2)
135
+ * @param {Number} m03 Component in column 0, row 3 position (index 3)
136
+ * @param {Number} m10 Component in column 1, row 0 position (index 4)
137
+ * @param {Number} m11 Component in column 1, row 1 position (index 5)
138
+ * @param {Number} m12 Component in column 1, row 2 position (index 6)
139
+ * @param {Number} m13 Component in column 1, row 3 position (index 7)
140
+ * @param {Number} m20 Component in column 2, row 0 position (index 8)
141
+ * @param {Number} m21 Component in column 2, row 1 position (index 9)
142
+ * @param {Number} m22 Component in column 2, row 2 position (index 10)
143
+ * @param {Number} m23 Component in column 2, row 3 position (index 11)
144
+ * @param {Number} m30 Component in column 3, row 0 position (index 12)
145
+ * @param {Number} m31 Component in column 3, row 1 position (index 13)
146
+ * @param {Number} m32 Component in column 3, row 2 position (index 14)
147
+ * @param {Number} m33 Component in column 3, row 3 position (index 15)
148
+ * @returns {mat4} out
149
+ */
150
+ export function set(out, m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33) {
151
+ out[0] = m00;
152
+ out[1] = m01;
153
+ out[2] = m02;
154
+ out[3] = m03;
155
+ out[4] = m10;
156
+ out[5] = m11;
157
+ out[6] = m12;
158
+ out[7] = m13;
159
+ out[8] = m20;
160
+ out[9] = m21;
161
+ out[10] = m22;
162
+ out[11] = m23;
163
+ out[12] = m30;
164
+ out[13] = m31;
165
+ out[14] = m32;
166
+ out[15] = m33;
167
+ return out;
168
+ }
169
+ /**
170
+ * Set a mat4 to the identity matrix
171
+ *
172
+ * @param {mat4} out the receiving matrix
173
+ * @returns {mat4} out
174
+ */
175
+ export function identity(out) {
176
+ out[0] = 1;
6
177
  out[1] = 0;
7
178
  out[2] = 0;
8
179
  out[3] = 0;
9
180
  out[4] = 0;
181
+ out[5] = 1;
10
182
  out[6] = 0;
11
183
  out[7] = 0;
12
184
  out[8] = 0;
13
185
  out[9] = 0;
186
+ out[10] = 1;
14
187
  out[11] = 0;
15
188
  out[12] = 0;
16
189
  out[13] = 0;
17
190
  out[14] = 0;
18
- }
19
-
20
- out[0] = 1;
21
- out[5] = 1;
22
- out[10] = 1;
23
- out[15] = 1;
24
- return out;
25
- }
26
- export function clone(a) {
27
- const out = new glMatrix.ARRAY_TYPE(16);
28
- out[0] = a[0];
29
- out[1] = a[1];
30
- out[2] = a[2];
31
- out[3] = a[3];
32
- out[4] = a[4];
33
- out[5] = a[5];
34
- out[6] = a[6];
35
- out[7] = a[7];
36
- out[8] = a[8];
37
- out[9] = a[9];
38
- out[10] = a[10];
39
- out[11] = a[11];
40
- out[12] = a[12];
41
- out[13] = a[13];
42
- out[14] = a[14];
43
- out[15] = a[15];
44
- return out;
45
- }
46
- export function copy(out, a) {
47
- out[0] = a[0];
48
- out[1] = a[1];
49
- out[2] = a[2];
50
- out[3] = a[3];
51
- out[4] = a[4];
52
- out[5] = a[5];
53
- out[6] = a[6];
54
- out[7] = a[7];
55
- out[8] = a[8];
56
- out[9] = a[9];
57
- out[10] = a[10];
58
- out[11] = a[11];
59
- out[12] = a[12];
60
- out[13] = a[13];
61
- out[14] = a[14];
62
- out[15] = a[15];
63
- return out;
64
- }
65
- export function fromValues(m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33) {
66
- const out = new glMatrix.ARRAY_TYPE(16);
67
- out[0] = m00;
68
- out[1] = m01;
69
- out[2] = m02;
70
- out[3] = m03;
71
- out[4] = m10;
72
- out[5] = m11;
73
- out[6] = m12;
74
- out[7] = m13;
75
- out[8] = m20;
76
- out[9] = m21;
77
- out[10] = m22;
78
- out[11] = m23;
79
- out[12] = m30;
80
- out[13] = m31;
81
- out[14] = m32;
82
- out[15] = m33;
83
- return out;
84
- }
85
- export function set(out, m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33) {
86
- out[0] = m00;
87
- out[1] = m01;
88
- out[2] = m02;
89
- out[3] = m03;
90
- out[4] = m10;
91
- out[5] = m11;
92
- out[6] = m12;
93
- out[7] = m13;
94
- out[8] = m20;
95
- out[9] = m21;
96
- out[10] = m22;
97
- out[11] = m23;
98
- out[12] = m30;
99
- out[13] = m31;
100
- out[14] = m32;
101
- out[15] = m33;
102
- return out;
103
- }
104
- export function identity(out) {
105
- out[0] = 1;
106
- out[1] = 0;
107
- out[2] = 0;
108
- out[3] = 0;
109
- out[4] = 0;
110
- out[5] = 1;
111
- out[6] = 0;
112
- out[7] = 0;
113
- out[8] = 0;
114
- out[9] = 0;
115
- out[10] = 1;
116
- out[11] = 0;
117
- out[12] = 0;
118
- out[13] = 0;
119
- out[14] = 0;
120
- out[15] = 1;
121
- return out;
191
+ out[15] = 1;
192
+ return out;
122
193
  }
194
+ /**
195
+ * Transpose the values of a mat4
196
+ *
197
+ * @param {mat4} out the receiving matrix
198
+ * @param {ReadonlyMat4} a the source matrix
199
+ * @returns {mat4} out
200
+ */
123
201
  export function transpose(out, a) {
124
- if (out === a) {
202
+ // If we are transposing ourselves we can skip a few steps but have to cache some values
203
+ if (out === a) {
204
+ const a01 = a[1];
205
+ const a02 = a[2];
206
+ const a03 = a[3];
207
+ const a12 = a[6];
208
+ const a13 = a[7];
209
+ const a23 = a[11];
210
+ out[1] = a[4];
211
+ out[2] = a[8];
212
+ out[3] = a[12];
213
+ out[4] = a01;
214
+ out[6] = a[9];
215
+ out[7] = a[13];
216
+ out[8] = a02;
217
+ out[9] = a12;
218
+ out[11] = a[14];
219
+ out[12] = a03;
220
+ out[13] = a13;
221
+ out[14] = a23;
222
+ }
223
+ else {
224
+ out[0] = a[0];
225
+ out[1] = a[4];
226
+ out[2] = a[8];
227
+ out[3] = a[12];
228
+ out[4] = a[1];
229
+ out[5] = a[5];
230
+ out[6] = a[9];
231
+ out[7] = a[13];
232
+ out[8] = a[2];
233
+ out[9] = a[6];
234
+ out[10] = a[10];
235
+ out[11] = a[14];
236
+ out[12] = a[3];
237
+ out[13] = a[7];
238
+ out[14] = a[11];
239
+ out[15] = a[15];
240
+ }
241
+ return out;
242
+ }
243
+ /**
244
+ * Inverts a mat4
245
+ *
246
+ * @param {mat4} out the receiving matrix
247
+ * @param {ReadonlyMat4} a the source matrix
248
+ * @returns {mat4} out
249
+ */
250
+ export function invert(out, a) {
251
+ const a00 = a[0];
125
252
  const a01 = a[1];
126
253
  const a02 = a[2];
127
254
  const a03 = a[3];
255
+ const a10 = a[4];
256
+ const a11 = a[5];
128
257
  const a12 = a[6];
129
258
  const a13 = a[7];
259
+ const a20 = a[8];
260
+ const a21 = a[9];
261
+ const a22 = a[10];
130
262
  const a23 = a[11];
131
- out[1] = a[4];
132
- out[2] = a[8];
133
- out[3] = a[12];
134
- out[4] = a01;
135
- out[6] = a[9];
136
- out[7] = a[13];
137
- out[8] = a02;
138
- out[9] = a12;
139
- out[11] = a[14];
140
- out[12] = a03;
141
- out[13] = a13;
142
- out[14] = a23;
143
- } else {
144
- out[0] = a[0];
145
- out[1] = a[4];
146
- out[2] = a[8];
147
- out[3] = a[12];
148
- out[4] = a[1];
149
- out[5] = a[5];
150
- out[6] = a[9];
151
- out[7] = a[13];
152
- out[8] = a[2];
153
- out[9] = a[6];
154
- out[10] = a[10];
155
- out[11] = a[14];
156
- out[12] = a[3];
157
- out[13] = a[7];
158
- out[14] = a[11];
159
- out[15] = a[15];
160
- }
161
-
162
- return out;
163
- }
164
- export function invert(out, a) {
165
- const a00 = a[0];
166
- const a01 = a[1];
167
- const a02 = a[2];
168
- const a03 = a[3];
169
- const a10 = a[4];
170
- const a11 = a[5];
171
- const a12 = a[6];
172
- const a13 = a[7];
173
- const a20 = a[8];
174
- const a21 = a[9];
175
- const a22 = a[10];
176
- const a23 = a[11];
177
- const a30 = a[12];
178
- const a31 = a[13];
179
- const a32 = a[14];
180
- const a33 = a[15];
181
- const b00 = a00 * a11 - a01 * a10;
182
- const b01 = a00 * a12 - a02 * a10;
183
- const b02 = a00 * a13 - a03 * a10;
184
- const b03 = a01 * a12 - a02 * a11;
185
- const b04 = a01 * a13 - a03 * a11;
186
- const b05 = a02 * a13 - a03 * a12;
187
- const b06 = a20 * a31 - a21 * a30;
188
- const b07 = a20 * a32 - a22 * a30;
189
- const b08 = a20 * a33 - a23 * a30;
190
- const b09 = a21 * a32 - a22 * a31;
191
- const b10 = a21 * a33 - a23 * a31;
192
- const b11 = a22 * a33 - a23 * a32;
193
- let det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
194
-
195
- if (!det) {
196
- return null;
197
- }
198
-
199
- det = 1.0 / det;
200
- out[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det;
201
- out[1] = (a02 * b10 - a01 * b11 - a03 * b09) * det;
202
- out[2] = (a31 * b05 - a32 * b04 + a33 * b03) * det;
203
- out[3] = (a22 * b04 - a21 * b05 - a23 * b03) * det;
204
- out[4] = (a12 * b08 - a10 * b11 - a13 * b07) * det;
205
- out[5] = (a00 * b11 - a02 * b08 + a03 * b07) * det;
206
- out[6] = (a32 * b02 - a30 * b05 - a33 * b01) * det;
207
- out[7] = (a20 * b05 - a22 * b02 + a23 * b01) * det;
208
- out[8] = (a10 * b10 - a11 * b08 + a13 * b06) * det;
209
- out[9] = (a01 * b08 - a00 * b10 - a03 * b06) * det;
210
- out[10] = (a30 * b04 - a31 * b02 + a33 * b00) * det;
211
- out[11] = (a21 * b02 - a20 * b04 - a23 * b00) * det;
212
- out[12] = (a11 * b07 - a10 * b09 - a12 * b06) * det;
213
- out[13] = (a00 * b09 - a01 * b07 + a02 * b06) * det;
214
- out[14] = (a31 * b01 - a30 * b03 - a32 * b00) * det;
215
- out[15] = (a20 * b03 - a21 * b01 + a22 * b00) * det;
216
- return out;
263
+ const a30 = a[12];
264
+ const a31 = a[13];
265
+ const a32 = a[14];
266
+ const a33 = a[15];
267
+ const b00 = a00 * a11 - a01 * a10;
268
+ const b01 = a00 * a12 - a02 * a10;
269
+ const b02 = a00 * a13 - a03 * a10;
270
+ const b03 = a01 * a12 - a02 * a11;
271
+ const b04 = a01 * a13 - a03 * a11;
272
+ const b05 = a02 * a13 - a03 * a12;
273
+ const b06 = a20 * a31 - a21 * a30;
274
+ const b07 = a20 * a32 - a22 * a30;
275
+ const b08 = a20 * a33 - a23 * a30;
276
+ const b09 = a21 * a32 - a22 * a31;
277
+ const b10 = a21 * a33 - a23 * a31;
278
+ const b11 = a22 * a33 - a23 * a32;
279
+ // Calculate the determinant
280
+ let det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
281
+ if (!det) {
282
+ return null;
283
+ }
284
+ det = 1.0 / det;
285
+ out[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det;
286
+ out[1] = (a02 * b10 - a01 * b11 - a03 * b09) * det;
287
+ out[2] = (a31 * b05 - a32 * b04 + a33 * b03) * det;
288
+ out[3] = (a22 * b04 - a21 * b05 - a23 * b03) * det;
289
+ out[4] = (a12 * b08 - a10 * b11 - a13 * b07) * det;
290
+ out[5] = (a00 * b11 - a02 * b08 + a03 * b07) * det;
291
+ out[6] = (a32 * b02 - a30 * b05 - a33 * b01) * det;
292
+ out[7] = (a20 * b05 - a22 * b02 + a23 * b01) * det;
293
+ out[8] = (a10 * b10 - a11 * b08 + a13 * b06) * det;
294
+ out[9] = (a01 * b08 - a00 * b10 - a03 * b06) * det;
295
+ out[10] = (a30 * b04 - a31 * b02 + a33 * b00) * det;
296
+ out[11] = (a21 * b02 - a20 * b04 - a23 * b00) * det;
297
+ out[12] = (a11 * b07 - a10 * b09 - a12 * b06) * det;
298
+ out[13] = (a00 * b09 - a01 * b07 + a02 * b06) * det;
299
+ out[14] = (a31 * b01 - a30 * b03 - a32 * b00) * det;
300
+ out[15] = (a20 * b03 - a21 * b01 + a22 * b00) * det;
301
+ return out;
217
302
  }
303
+ /**
304
+ * Calculates the adjugate of a mat4
305
+ *
306
+ * @param {mat4} out the receiving matrix
307
+ * @param {ReadonlyMat4} a the source matrix
308
+ * @returns {mat4} out
309
+ */
218
310
  export function adjoint(out, a) {
219
- const a00 = a[0];
220
- const a01 = a[1];
221
- const a02 = a[2];
222
- const a03 = a[3];
223
- const a10 = a[4];
224
- const a11 = a[5];
225
- const a12 = a[6];
226
- const a13 = a[7];
227
- const a20 = a[8];
228
- const a21 = a[9];
229
- const a22 = a[10];
230
- const a23 = a[11];
231
- const a30 = a[12];
232
- const a31 = a[13];
233
- const a32 = a[14];
234
- const a33 = a[15];
235
- const b00 = a00 * a11 - a01 * a10;
236
- const b01 = a00 * a12 - a02 * a10;
237
- const b02 = a00 * a13 - a03 * a10;
238
- const b03 = a01 * a12 - a02 * a11;
239
- const b04 = a01 * a13 - a03 * a11;
240
- const b05 = a02 * a13 - a03 * a12;
241
- const b06 = a20 * a31 - a21 * a30;
242
- const b07 = a20 * a32 - a22 * a30;
243
- const b08 = a20 * a33 - a23 * a30;
244
- const b09 = a21 * a32 - a22 * a31;
245
- const b10 = a21 * a33 - a23 * a31;
246
- const b11 = a22 * a33 - a23 * a32;
247
- out[0] = a11 * b11 - a12 * b10 + a13 * b09;
248
- out[1] = a02 * b10 - a01 * b11 - a03 * b09;
249
- out[2] = a31 * b05 - a32 * b04 + a33 * b03;
250
- out[3] = a22 * b04 - a21 * b05 - a23 * b03;
251
- out[4] = a12 * b08 - a10 * b11 - a13 * b07;
252
- out[5] = a00 * b11 - a02 * b08 + a03 * b07;
253
- out[6] = a32 * b02 - a30 * b05 - a33 * b01;
254
- out[7] = a20 * b05 - a22 * b02 + a23 * b01;
255
- out[8] = a10 * b10 - a11 * b08 + a13 * b06;
256
- out[9] = a01 * b08 - a00 * b10 - a03 * b06;
257
- out[10] = a30 * b04 - a31 * b02 + a33 * b00;
258
- out[11] = a21 * b02 - a20 * b04 - a23 * b00;
259
- out[12] = a11 * b07 - a10 * b09 - a12 * b06;
260
- out[13] = a00 * b09 - a01 * b07 + a02 * b06;
261
- out[14] = a31 * b01 - a30 * b03 - a32 * b00;
262
- out[15] = a20 * b03 - a21 * b01 + a22 * b00;
263
- return out;
311
+ const a00 = a[0];
312
+ const a01 = a[1];
313
+ const a02 = a[2];
314
+ const a03 = a[3];
315
+ const a10 = a[4];
316
+ const a11 = a[5];
317
+ const a12 = a[6];
318
+ const a13 = a[7];
319
+ const a20 = a[8];
320
+ const a21 = a[9];
321
+ const a22 = a[10];
322
+ const a23 = a[11];
323
+ const a30 = a[12];
324
+ const a31 = a[13];
325
+ const a32 = a[14];
326
+ const a33 = a[15];
327
+ const b00 = a00 * a11 - a01 * a10;
328
+ const b01 = a00 * a12 - a02 * a10;
329
+ const b02 = a00 * a13 - a03 * a10;
330
+ const b03 = a01 * a12 - a02 * a11;
331
+ const b04 = a01 * a13 - a03 * a11;
332
+ const b05 = a02 * a13 - a03 * a12;
333
+ const b06 = a20 * a31 - a21 * a30;
334
+ const b07 = a20 * a32 - a22 * a30;
335
+ const b08 = a20 * a33 - a23 * a30;
336
+ const b09 = a21 * a32 - a22 * a31;
337
+ const b10 = a21 * a33 - a23 * a31;
338
+ const b11 = a22 * a33 - a23 * a32;
339
+ out[0] = a11 * b11 - a12 * b10 + a13 * b09;
340
+ out[1] = a02 * b10 - a01 * b11 - a03 * b09;
341
+ out[2] = a31 * b05 - a32 * b04 + a33 * b03;
342
+ out[3] = a22 * b04 - a21 * b05 - a23 * b03;
343
+ out[4] = a12 * b08 - a10 * b11 - a13 * b07;
344
+ out[5] = a00 * b11 - a02 * b08 + a03 * b07;
345
+ out[6] = a32 * b02 - a30 * b05 - a33 * b01;
346
+ out[7] = a20 * b05 - a22 * b02 + a23 * b01;
347
+ out[8] = a10 * b10 - a11 * b08 + a13 * b06;
348
+ out[9] = a01 * b08 - a00 * b10 - a03 * b06;
349
+ out[10] = a30 * b04 - a31 * b02 + a33 * b00;
350
+ out[11] = a21 * b02 - a20 * b04 - a23 * b00;
351
+ out[12] = a11 * b07 - a10 * b09 - a12 * b06;
352
+ out[13] = a00 * b09 - a01 * b07 + a02 * b06;
353
+ out[14] = a31 * b01 - a30 * b03 - a32 * b00;
354
+ out[15] = a20 * b03 - a21 * b01 + a22 * b00;
355
+ return out;
264
356
  }
357
+ /**
358
+ * Calculates the determinant of a mat4
359
+ *
360
+ * @param {ReadonlyMat4} a the source matrix
361
+ * @returns {Number} determinant of a
362
+ */
265
363
  export function determinant(a) {
266
- const a00 = a[0];
267
- const a01 = a[1];
268
- const a02 = a[2];
269
- const a03 = a[3];
270
- const a10 = a[4];
271
- const a11 = a[5];
272
- const a12 = a[6];
273
- const a13 = a[7];
274
- const a20 = a[8];
275
- const a21 = a[9];
276
- const a22 = a[10];
277
- const a23 = a[11];
278
- const a30 = a[12];
279
- const a31 = a[13];
280
- const a32 = a[14];
281
- const a33 = a[15];
282
- const b0 = a00 * a11 - a01 * a10;
283
- const b1 = a00 * a12 - a02 * a10;
284
- const b2 = a01 * a12 - a02 * a11;
285
- const b3 = a20 * a31 - a21 * a30;
286
- const b4 = a20 * a32 - a22 * a30;
287
- const b5 = a21 * a32 - a22 * a31;
288
- const b6 = a00 * b5 - a01 * b4 + a02 * b3;
289
- const b7 = a10 * b5 - a11 * b4 + a12 * b3;
290
- const b8 = a20 * b2 - a21 * b1 + a22 * b0;
291
- const b9 = a30 * b2 - a31 * b1 + a32 * b0;
292
- return a13 * b6 - a03 * b7 + a33 * b8 - a23 * b9;
364
+ const a00 = a[0];
365
+ const a01 = a[1];
366
+ const a02 = a[2];
367
+ const a03 = a[3];
368
+ const a10 = a[4];
369
+ const a11 = a[5];
370
+ const a12 = a[6];
371
+ const a13 = a[7];
372
+ const a20 = a[8];
373
+ const a21 = a[9];
374
+ const a22 = a[10];
375
+ const a23 = a[11];
376
+ const a30 = a[12];
377
+ const a31 = a[13];
378
+ const a32 = a[14];
379
+ const a33 = a[15];
380
+ const b0 = a00 * a11 - a01 * a10;
381
+ const b1 = a00 * a12 - a02 * a10;
382
+ const b2 = a01 * a12 - a02 * a11;
383
+ const b3 = a20 * a31 - a21 * a30;
384
+ const b4 = a20 * a32 - a22 * a30;
385
+ const b5 = a21 * a32 - a22 * a31;
386
+ const b6 = a00 * b5 - a01 * b4 + a02 * b3;
387
+ const b7 = a10 * b5 - a11 * b4 + a12 * b3;
388
+ const b8 = a20 * b2 - a21 * b1 + a22 * b0;
389
+ const b9 = a30 * b2 - a31 * b1 + a32 * b0;
390
+ // Calculate the determinant
391
+ return a13 * b6 - a03 * b7 + a33 * b8 - a23 * b9;
293
392
  }
393
+ /**
394
+ * Multiplies two mat4s
395
+ *
396
+ * @param {mat4} out the receiving matrix
397
+ * @param {ReadonlyMat4} a the first operand
398
+ * @param {ReadonlyMat4} b the second operand
399
+ * @returns {mat4} out
400
+ */
294
401
  export function multiply(out, a, b) {
295
- const a00 = a[0];
296
- const a01 = a[1];
297
- const a02 = a[2];
298
- const a03 = a[3];
299
- const a10 = a[4];
300
- const a11 = a[5];
301
- const a12 = a[6];
302
- const a13 = a[7];
303
- const a20 = a[8];
304
- const a21 = a[9];
305
- const a22 = a[10];
306
- const a23 = a[11];
307
- const a30 = a[12];
308
- const a31 = a[13];
309
- const a32 = a[14];
310
- const a33 = a[15];
311
- let b0 = b[0];
312
- let b1 = b[1];
313
- let b2 = b[2];
314
- let b3 = b[3];
315
- out[0] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
316
- out[1] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
317
- out[2] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
318
- out[3] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
319
- b0 = b[4];
320
- b1 = b[5];
321
- b2 = b[6];
322
- b3 = b[7];
323
- out[4] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
324
- out[5] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
325
- out[6] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
326
- out[7] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
327
- b0 = b[8];
328
- b1 = b[9];
329
- b2 = b[10];
330
- b3 = b[11];
331
- out[8] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
332
- out[9] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
333
- out[10] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
334
- out[11] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
335
- b0 = b[12];
336
- b1 = b[13];
337
- b2 = b[14];
338
- b3 = b[15];
339
- out[12] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
340
- out[13] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
341
- out[14] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
342
- out[15] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
343
- return out;
402
+ const a00 = a[0];
403
+ const a01 = a[1];
404
+ const a02 = a[2];
405
+ const a03 = a[3];
406
+ const a10 = a[4];
407
+ const a11 = a[5];
408
+ const a12 = a[6];
409
+ const a13 = a[7];
410
+ const a20 = a[8];
411
+ const a21 = a[9];
412
+ const a22 = a[10];
413
+ const a23 = a[11];
414
+ const a30 = a[12];
415
+ const a31 = a[13];
416
+ const a32 = a[14];
417
+ const a33 = a[15];
418
+ // Cache only the current line of the second matrix
419
+ let b0 = b[0];
420
+ let b1 = b[1];
421
+ let b2 = b[2];
422
+ let b3 = b[3];
423
+ out[0] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
424
+ out[1] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
425
+ out[2] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
426
+ out[3] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
427
+ b0 = b[4];
428
+ b1 = b[5];
429
+ b2 = b[6];
430
+ b3 = b[7];
431
+ out[4] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
432
+ out[5] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
433
+ out[6] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
434
+ out[7] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
435
+ b0 = b[8];
436
+ b1 = b[9];
437
+ b2 = b[10];
438
+ b3 = b[11];
439
+ out[8] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
440
+ out[9] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
441
+ out[10] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
442
+ out[11] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
443
+ b0 = b[12];
444
+ b1 = b[13];
445
+ b2 = b[14];
446
+ b3 = b[15];
447
+ out[12] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
448
+ out[13] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
449
+ out[14] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
450
+ out[15] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
451
+ return out;
344
452
  }
453
+ /**
454
+ * Translate a mat4 by the given vector
455
+ *
456
+ * @param {mat4} out the receiving matrix
457
+ * @param {ReadonlyMat4} a the matrix to translate
458
+ * @param {ReadonlyVec3} v vector to translate by
459
+ * @returns {mat4} out
460
+ */
345
461
  export function translate(out, a, v) {
346
- const x = v[0];
347
- const y = v[1];
348
- const z = v[2];
349
- let a00;
350
- let a01;
351
- let a02;
352
- let a03;
353
- let a10;
354
- let a11;
355
- let a12;
356
- let a13;
357
- let a20;
358
- let a21;
359
- let a22;
360
- let a23;
361
-
362
- if (a === out) {
363
- out[12] = a[0] * x + a[4] * y + a[8] * z + a[12];
364
- out[13] = a[1] * x + a[5] * y + a[9] * z + a[13];
365
- out[14] = a[2] * x + a[6] * y + a[10] * z + a[14];
366
- out[15] = a[3] * x + a[7] * y + a[11] * z + a[15];
367
- } else {
462
+ const x = v[0];
463
+ const y = v[1];
464
+ const z = v[2];
465
+ let a00;
466
+ let a01;
467
+ let a02;
468
+ let a03;
469
+ let a10;
470
+ let a11;
471
+ let a12;
472
+ let a13;
473
+ let a20;
474
+ let a21;
475
+ let a22;
476
+ let a23;
477
+ if (a === out) {
478
+ out[12] = a[0] * x + a[4] * y + a[8] * z + a[12];
479
+ out[13] = a[1] * x + a[5] * y + a[9] * z + a[13];
480
+ out[14] = a[2] * x + a[6] * y + a[10] * z + a[14];
481
+ out[15] = a[3] * x + a[7] * y + a[11] * z + a[15];
482
+ }
483
+ else {
484
+ a00 = a[0];
485
+ a01 = a[1];
486
+ a02 = a[2];
487
+ a03 = a[3];
488
+ a10 = a[4];
489
+ a11 = a[5];
490
+ a12 = a[6];
491
+ a13 = a[7];
492
+ a20 = a[8];
493
+ a21 = a[9];
494
+ a22 = a[10];
495
+ a23 = a[11];
496
+ out[0] = a00;
497
+ out[1] = a01;
498
+ out[2] = a02;
499
+ out[3] = a03;
500
+ out[4] = a10;
501
+ out[5] = a11;
502
+ out[6] = a12;
503
+ out[7] = a13;
504
+ out[8] = a20;
505
+ out[9] = a21;
506
+ out[10] = a22;
507
+ out[11] = a23;
508
+ out[12] = a00 * x + a10 * y + a20 * z + a[12];
509
+ out[13] = a01 * x + a11 * y + a21 * z + a[13];
510
+ out[14] = a02 * x + a12 * y + a22 * z + a[14];
511
+ out[15] = a03 * x + a13 * y + a23 * z + a[15];
512
+ }
513
+ return out;
514
+ }
515
+ /**
516
+ * Scales the mat4 by the dimensions in the given vec3 not using vectorization
517
+ *
518
+ * @param {mat4} out the receiving matrix
519
+ * @param {ReadonlyMat4} a the matrix to scale
520
+ * @param {ReadonlyVec3} v the vec3 to scale the matrix by
521
+ * @returns {mat4} out
522
+ **/
523
+ export function scale(out, a, v) {
524
+ const x = v[0];
525
+ const y = v[1];
526
+ const z = v[2];
527
+ out[0] = a[0] * x;
528
+ out[1] = a[1] * x;
529
+ out[2] = a[2] * x;
530
+ out[3] = a[3] * x;
531
+ out[4] = a[4] * y;
532
+ out[5] = a[5] * y;
533
+ out[6] = a[6] * y;
534
+ out[7] = a[7] * y;
535
+ out[8] = a[8] * z;
536
+ out[9] = a[9] * z;
537
+ out[10] = a[10] * z;
538
+ out[11] = a[11] * z;
539
+ out[12] = a[12];
540
+ out[13] = a[13];
541
+ out[14] = a[14];
542
+ out[15] = a[15];
543
+ return out;
544
+ }
545
+ /**
546
+ * Rotates a mat4 by the given angle around the given axis
547
+ *
548
+ * @param {mat4} out the receiving matrix
549
+ * @param {ReadonlyMat4} a the matrix to rotate
550
+ * @param {Number} rad the angle to rotate the matrix by
551
+ * @param {ReadonlyVec3} axis the axis to rotate around
552
+ * @returns {mat4} out
553
+ */
554
+ export function rotate(out, a, rad, axis) {
555
+ let x = axis[0];
556
+ let y = axis[1];
557
+ let z = axis[2];
558
+ let len = Math.sqrt(x * x + y * y + z * z);
559
+ let c;
560
+ let s;
561
+ let t;
562
+ let a00;
563
+ let a01;
564
+ let a02;
565
+ let a03;
566
+ let a10;
567
+ let a11;
568
+ let a12;
569
+ let a13;
570
+ let a20;
571
+ let a21;
572
+ let a22;
573
+ let a23;
574
+ let b00;
575
+ let b01;
576
+ let b02;
577
+ let b10;
578
+ let b11;
579
+ let b12;
580
+ let b20;
581
+ let b21;
582
+ let b22;
583
+ if (len < glMatrix.EPSILON) {
584
+ return null;
585
+ }
586
+ len = 1 / len;
587
+ x *= len;
588
+ y *= len;
589
+ z *= len;
590
+ s = Math.sin(rad);
591
+ c = Math.cos(rad);
592
+ t = 1 - c;
368
593
  a00 = a[0];
369
594
  a01 = a[1];
370
595
  a02 = a[2];
@@ -377,1079 +602,1394 @@ export function translate(out, a, v) {
377
602
  a21 = a[9];
378
603
  a22 = a[10];
379
604
  a23 = a[11];
380
- out[0] = a00;
381
- out[1] = a01;
382
- out[2] = a02;
383
- out[3] = a03;
384
- out[4] = a10;
385
- out[5] = a11;
386
- out[6] = a12;
387
- out[7] = a13;
388
- out[8] = a20;
389
- out[9] = a21;
390
- out[10] = a22;
391
- out[11] = a23;
392
- out[12] = a00 * x + a10 * y + a20 * z + a[12];
393
- out[13] = a01 * x + a11 * y + a21 * z + a[13];
394
- out[14] = a02 * x + a12 * y + a22 * z + a[14];
395
- out[15] = a03 * x + a13 * y + a23 * z + a[15];
396
- }
397
-
398
- return out;
399
- }
400
- export function scale(out, a, v) {
401
- const x = v[0];
402
- const y = v[1];
403
- const z = v[2];
404
- out[0] = a[0] * x;
405
- out[1] = a[1] * x;
406
- out[2] = a[2] * x;
407
- out[3] = a[3] * x;
408
- out[4] = a[4] * y;
409
- out[5] = a[5] * y;
410
- out[6] = a[6] * y;
411
- out[7] = a[7] * y;
412
- out[8] = a[8] * z;
413
- out[9] = a[9] * z;
414
- out[10] = a[10] * z;
415
- out[11] = a[11] * z;
416
- out[12] = a[12];
417
- out[13] = a[13];
418
- out[14] = a[14];
419
- out[15] = a[15];
420
- return out;
421
- }
422
- export function rotate(out, a, rad, axis) {
423
- let x = axis[0];
424
- let y = axis[1];
425
- let z = axis[2];
426
- let len = Math.sqrt(x * x + y * y + z * z);
427
- let c;
428
- let s;
429
- let t;
430
- let a00;
431
- let a01;
432
- let a02;
433
- let a03;
434
- let a10;
435
- let a11;
436
- let a12;
437
- let a13;
438
- let a20;
439
- let a21;
440
- let a22;
441
- let a23;
442
- let b00;
443
- let b01;
444
- let b02;
445
- let b10;
446
- let b11;
447
- let b12;
448
- let b20;
449
- let b21;
450
- let b22;
451
-
452
- if (len < glMatrix.EPSILON) {
453
- return null;
454
- }
455
-
456
- len = 1 / len;
457
- x *= len;
458
- y *= len;
459
- z *= len;
460
- s = Math.sin(rad);
461
- c = Math.cos(rad);
462
- t = 1 - c;
463
- a00 = a[0];
464
- a01 = a[1];
465
- a02 = a[2];
466
- a03 = a[3];
467
- a10 = a[4];
468
- a11 = a[5];
469
- a12 = a[6];
470
- a13 = a[7];
471
- a20 = a[8];
472
- a21 = a[9];
473
- a22 = a[10];
474
- a23 = a[11];
475
- b00 = x * x * t + c;
476
- b01 = y * x * t + z * s;
477
- b02 = z * x * t - y * s;
478
- b10 = x * y * t - z * s;
479
- b11 = y * y * t + c;
480
- b12 = z * y * t + x * s;
481
- b20 = x * z * t + y * s;
482
- b21 = y * z * t - x * s;
483
- b22 = z * z * t + c;
484
- out[0] = a00 * b00 + a10 * b01 + a20 * b02;
485
- out[1] = a01 * b00 + a11 * b01 + a21 * b02;
486
- out[2] = a02 * b00 + a12 * b01 + a22 * b02;
487
- out[3] = a03 * b00 + a13 * b01 + a23 * b02;
488
- out[4] = a00 * b10 + a10 * b11 + a20 * b12;
489
- out[5] = a01 * b10 + a11 * b11 + a21 * b12;
490
- out[6] = a02 * b10 + a12 * b11 + a22 * b12;
491
- out[7] = a03 * b10 + a13 * b11 + a23 * b12;
492
- out[8] = a00 * b20 + a10 * b21 + a20 * b22;
493
- out[9] = a01 * b20 + a11 * b21 + a21 * b22;
494
- out[10] = a02 * b20 + a12 * b21 + a22 * b22;
495
- out[11] = a03 * b20 + a13 * b21 + a23 * b22;
496
-
497
- if (a !== out) {
498
- out[12] = a[12];
499
- out[13] = a[13];
500
- out[14] = a[14];
501
- out[15] = a[15];
502
- }
503
-
504
- return out;
605
+ // Construct the elements of the rotation matrix
606
+ b00 = x * x * t + c;
607
+ b01 = y * x * t + z * s;
608
+ b02 = z * x * t - y * s;
609
+ b10 = x * y * t - z * s;
610
+ b11 = y * y * t + c;
611
+ b12 = z * y * t + x * s;
612
+ b20 = x * z * t + y * s;
613
+ b21 = y * z * t - x * s;
614
+ b22 = z * z * t + c;
615
+ // Perform rotation-specific matrix multiplication
616
+ out[0] = a00 * b00 + a10 * b01 + a20 * b02;
617
+ out[1] = a01 * b00 + a11 * b01 + a21 * b02;
618
+ out[2] = a02 * b00 + a12 * b01 + a22 * b02;
619
+ out[3] = a03 * b00 + a13 * b01 + a23 * b02;
620
+ out[4] = a00 * b10 + a10 * b11 + a20 * b12;
621
+ out[5] = a01 * b10 + a11 * b11 + a21 * b12;
622
+ out[6] = a02 * b10 + a12 * b11 + a22 * b12;
623
+ out[7] = a03 * b10 + a13 * b11 + a23 * b12;
624
+ out[8] = a00 * b20 + a10 * b21 + a20 * b22;
625
+ out[9] = a01 * b20 + a11 * b21 + a21 * b22;
626
+ out[10] = a02 * b20 + a12 * b21 + a22 * b22;
627
+ out[11] = a03 * b20 + a13 * b21 + a23 * b22;
628
+ if (a !== out) {
629
+ // If the source and destination differ, copy the unchanged last row
630
+ out[12] = a[12];
631
+ out[13] = a[13];
632
+ out[14] = a[14];
633
+ out[15] = a[15];
634
+ }
635
+ return out;
505
636
  }
637
+ /**
638
+ * Rotates a matrix by the given angle around the X axis
639
+ *
640
+ * @param {mat4} out the receiving matrix
641
+ * @param {ReadonlyMat4} a the matrix to rotate
642
+ * @param {Number} rad the angle to rotate the matrix by
643
+ * @returns {mat4} out
644
+ */
506
645
  export function rotateX(out, a, rad) {
507
- const s = Math.sin(rad);
508
- const c = Math.cos(rad);
509
- const a10 = a[4];
510
- const a11 = a[5];
511
- const a12 = a[6];
512
- const a13 = a[7];
513
- const a20 = a[8];
514
- const a21 = a[9];
515
- const a22 = a[10];
516
- const a23 = a[11];
517
-
518
- if (a !== out) {
519
- out[0] = a[0];
520
- out[1] = a[1];
521
- out[2] = a[2];
522
- out[3] = a[3];
523
- out[12] = a[12];
524
- out[13] = a[13];
525
- out[14] = a[14];
526
- out[15] = a[15];
527
- }
528
-
529
- out[4] = a10 * c + a20 * s;
530
- out[5] = a11 * c + a21 * s;
531
- out[6] = a12 * c + a22 * s;
532
- out[7] = a13 * c + a23 * s;
533
- out[8] = a20 * c - a10 * s;
534
- out[9] = a21 * c - a11 * s;
535
- out[10] = a22 * c - a12 * s;
536
- out[11] = a23 * c - a13 * s;
537
- return out;
646
+ const s = Math.sin(rad);
647
+ const c = Math.cos(rad);
648
+ const a10 = a[4];
649
+ const a11 = a[5];
650
+ const a12 = a[6];
651
+ const a13 = a[7];
652
+ const a20 = a[8];
653
+ const a21 = a[9];
654
+ const a22 = a[10];
655
+ const a23 = a[11];
656
+ if (a !== out) {
657
+ // If the source and destination differ, copy the unchanged rows
658
+ out[0] = a[0];
659
+ out[1] = a[1];
660
+ out[2] = a[2];
661
+ out[3] = a[3];
662
+ out[12] = a[12];
663
+ out[13] = a[13];
664
+ out[14] = a[14];
665
+ out[15] = a[15];
666
+ }
667
+ // Perform axis-specific matrix multiplication
668
+ out[4] = a10 * c + a20 * s;
669
+ out[5] = a11 * c + a21 * s;
670
+ out[6] = a12 * c + a22 * s;
671
+ out[7] = a13 * c + a23 * s;
672
+ out[8] = a20 * c - a10 * s;
673
+ out[9] = a21 * c - a11 * s;
674
+ out[10] = a22 * c - a12 * s;
675
+ out[11] = a23 * c - a13 * s;
676
+ return out;
538
677
  }
678
+ /**
679
+ * Rotates a matrix by the given angle around the Y axis
680
+ *
681
+ * @param {mat4} out the receiving matrix
682
+ * @param {ReadonlyMat4} a the matrix to rotate
683
+ * @param {Number} rad the angle to rotate the matrix by
684
+ * @returns {mat4} out
685
+ */
539
686
  export function rotateY(out, a, rad) {
540
- const s = Math.sin(rad);
541
- const c = Math.cos(rad);
542
- const a00 = a[0];
543
- const a01 = a[1];
544
- const a02 = a[2];
545
- const a03 = a[3];
546
- const a20 = a[8];
547
- const a21 = a[9];
548
- const a22 = a[10];
549
- const a23 = a[11];
550
-
551
- if (a !== out) {
552
- out[4] = a[4];
553
- out[5] = a[5];
554
- out[6] = a[6];
555
- out[7] = a[7];
556
- out[12] = a[12];
557
- out[13] = a[13];
558
- out[14] = a[14];
559
- out[15] = a[15];
560
- }
561
-
562
- out[0] = a00 * c - a20 * s;
563
- out[1] = a01 * c - a21 * s;
564
- out[2] = a02 * c - a22 * s;
565
- out[3] = a03 * c - a23 * s;
566
- out[8] = a00 * s + a20 * c;
567
- out[9] = a01 * s + a21 * c;
568
- out[10] = a02 * s + a22 * c;
569
- out[11] = a03 * s + a23 * c;
570
- return out;
687
+ const s = Math.sin(rad);
688
+ const c = Math.cos(rad);
689
+ const a00 = a[0];
690
+ const a01 = a[1];
691
+ const a02 = a[2];
692
+ const a03 = a[3];
693
+ const a20 = a[8];
694
+ const a21 = a[9];
695
+ const a22 = a[10];
696
+ const a23 = a[11];
697
+ if (a !== out) {
698
+ // If the source and destination differ, copy the unchanged rows
699
+ out[4] = a[4];
700
+ out[5] = a[5];
701
+ out[6] = a[6];
702
+ out[7] = a[7];
703
+ out[12] = a[12];
704
+ out[13] = a[13];
705
+ out[14] = a[14];
706
+ out[15] = a[15];
707
+ }
708
+ // Perform axis-specific matrix multiplication
709
+ out[0] = a00 * c - a20 * s;
710
+ out[1] = a01 * c - a21 * s;
711
+ out[2] = a02 * c - a22 * s;
712
+ out[3] = a03 * c - a23 * s;
713
+ out[8] = a00 * s + a20 * c;
714
+ out[9] = a01 * s + a21 * c;
715
+ out[10] = a02 * s + a22 * c;
716
+ out[11] = a03 * s + a23 * c;
717
+ return out;
571
718
  }
719
+ /**
720
+ * Rotates a matrix by the given angle around the Z axis
721
+ *
722
+ * @param {mat4} out the receiving matrix
723
+ * @param {ReadonlyMat4} a the matrix to rotate
724
+ * @param {Number} rad the angle to rotate the matrix by
725
+ * @returns {mat4} out
726
+ */
572
727
  export function rotateZ(out, a, rad) {
573
- const s = Math.sin(rad);
574
- const c = Math.cos(rad);
575
- const a00 = a[0];
576
- const a01 = a[1];
577
- const a02 = a[2];
578
- const a03 = a[3];
579
- const a10 = a[4];
580
- const a11 = a[5];
581
- const a12 = a[6];
582
- const a13 = a[7];
583
-
584
- if (a !== out) {
585
- out[8] = a[8];
586
- out[9] = a[9];
587
- out[10] = a[10];
588
- out[11] = a[11];
589
- out[12] = a[12];
590
- out[13] = a[13];
591
- out[14] = a[14];
592
- out[15] = a[15];
593
- }
594
-
595
- out[0] = a00 * c + a10 * s;
596
- out[1] = a01 * c + a11 * s;
597
- out[2] = a02 * c + a12 * s;
598
- out[3] = a03 * c + a13 * s;
599
- out[4] = a10 * c - a00 * s;
600
- out[5] = a11 * c - a01 * s;
601
- out[6] = a12 * c - a02 * s;
602
- out[7] = a13 * c - a03 * s;
603
- return out;
728
+ const s = Math.sin(rad);
729
+ const c = Math.cos(rad);
730
+ const a00 = a[0];
731
+ const a01 = a[1];
732
+ const a02 = a[2];
733
+ const a03 = a[3];
734
+ const a10 = a[4];
735
+ const a11 = a[5];
736
+ const a12 = a[6];
737
+ const a13 = a[7];
738
+ if (a !== out) {
739
+ // If the source and destination differ, copy the unchanged last row
740
+ out[8] = a[8];
741
+ out[9] = a[9];
742
+ out[10] = a[10];
743
+ out[11] = a[11];
744
+ out[12] = a[12];
745
+ out[13] = a[13];
746
+ out[14] = a[14];
747
+ out[15] = a[15];
748
+ }
749
+ // Perform axis-specific matrix multiplication
750
+ out[0] = a00 * c + a10 * s;
751
+ out[1] = a01 * c + a11 * s;
752
+ out[2] = a02 * c + a12 * s;
753
+ out[3] = a03 * c + a13 * s;
754
+ out[4] = a10 * c - a00 * s;
755
+ out[5] = a11 * c - a01 * s;
756
+ out[6] = a12 * c - a02 * s;
757
+ out[7] = a13 * c - a03 * s;
758
+ return out;
604
759
  }
760
+ /**
761
+ * Creates a matrix from a vector translation
762
+ * This is equivalent to (but much faster than):
763
+ *
764
+ * mat4.identity(dest);
765
+ * mat4.translate(dest, dest, vec);
766
+ *
767
+ * @param {mat4} out mat4 receiving operation result
768
+ * @param {ReadonlyVec3} v Translation vector
769
+ * @returns {mat4} out
770
+ */
605
771
  export function fromTranslation(out, v) {
606
- out[0] = 1;
607
- out[1] = 0;
608
- out[2] = 0;
609
- out[3] = 0;
610
- out[4] = 0;
611
- out[5] = 1;
612
- out[6] = 0;
613
- out[7] = 0;
614
- out[8] = 0;
615
- out[9] = 0;
616
- out[10] = 1;
617
- out[11] = 0;
618
- out[12] = v[0];
619
- out[13] = v[1];
620
- out[14] = v[2];
621
- out[15] = 1;
622
- return out;
772
+ out[0] = 1;
773
+ out[1] = 0;
774
+ out[2] = 0;
775
+ out[3] = 0;
776
+ out[4] = 0;
777
+ out[5] = 1;
778
+ out[6] = 0;
779
+ out[7] = 0;
780
+ out[8] = 0;
781
+ out[9] = 0;
782
+ out[10] = 1;
783
+ out[11] = 0;
784
+ out[12] = v[0];
785
+ out[13] = v[1];
786
+ out[14] = v[2];
787
+ out[15] = 1;
788
+ return out;
623
789
  }
790
+ /**
791
+ * Creates a matrix from a vector scaling
792
+ * This is equivalent to (but much faster than):
793
+ *
794
+ * mat4.identity(dest);
795
+ * mat4.scale(dest, dest, vec);
796
+ *
797
+ * @param {mat4} out mat4 receiving operation result
798
+ * @param {ReadonlyVec3} v Scaling vector
799
+ * @returns {mat4} out
800
+ */
624
801
  export function fromScaling(out, v) {
625
- out[0] = v[0];
626
- out[1] = 0;
627
- out[2] = 0;
628
- out[3] = 0;
629
- out[4] = 0;
630
- out[5] = v[1];
631
- out[6] = 0;
632
- out[7] = 0;
633
- out[8] = 0;
634
- out[9] = 0;
635
- out[10] = v[2];
636
- out[11] = 0;
637
- out[12] = 0;
638
- out[13] = 0;
639
- out[14] = 0;
640
- out[15] = 1;
641
- return out;
802
+ out[0] = v[0];
803
+ out[1] = 0;
804
+ out[2] = 0;
805
+ out[3] = 0;
806
+ out[4] = 0;
807
+ out[5] = v[1];
808
+ out[6] = 0;
809
+ out[7] = 0;
810
+ out[8] = 0;
811
+ out[9] = 0;
812
+ out[10] = v[2];
813
+ out[11] = 0;
814
+ out[12] = 0;
815
+ out[13] = 0;
816
+ out[14] = 0;
817
+ out[15] = 1;
818
+ return out;
642
819
  }
820
+ /**
821
+ * Creates a matrix from a given angle around a given axis
822
+ * This is equivalent to (but much faster than):
823
+ *
824
+ * mat4.identity(dest);
825
+ * mat4.rotate(dest, dest, rad, axis);
826
+ *
827
+ * @param {mat4} out mat4 receiving operation result
828
+ * @param {Number} rad the angle to rotate the matrix by
829
+ * @param {ReadonlyVec3} axis the axis to rotate around
830
+ * @returns {mat4} out
831
+ */
643
832
  export function fromRotation(out, rad, axis) {
644
- let x = axis[0];
645
- let y = axis[1];
646
- let z = axis[2];
647
- let len = Math.sqrt(x * x + y * y + z * z);
648
- let c;
649
- let s;
650
- let t;
651
-
652
- if (len < glMatrix.EPSILON) {
653
- return null;
654
- }
655
-
656
- len = 1 / len;
657
- x *= len;
658
- y *= len;
659
- z *= len;
660
- s = Math.sin(rad);
661
- c = Math.cos(rad);
662
- t = 1 - c;
663
- out[0] = x * x * t + c;
664
- out[1] = y * x * t + z * s;
665
- out[2] = z * x * t - y * s;
666
- out[3] = 0;
667
- out[4] = x * y * t - z * s;
668
- out[5] = y * y * t + c;
669
- out[6] = z * y * t + x * s;
670
- out[7] = 0;
671
- out[8] = x * z * t + y * s;
672
- out[9] = y * z * t - x * s;
673
- out[10] = z * z * t + c;
674
- out[11] = 0;
675
- out[12] = 0;
676
- out[13] = 0;
677
- out[14] = 0;
678
- out[15] = 1;
679
- return out;
833
+ let x = axis[0];
834
+ let y = axis[1];
835
+ let z = axis[2];
836
+ let len = Math.sqrt(x * x + y * y + z * z);
837
+ let c;
838
+ let s;
839
+ let t;
840
+ if (len < glMatrix.EPSILON) {
841
+ return null;
842
+ }
843
+ len = 1 / len;
844
+ x *= len;
845
+ y *= len;
846
+ z *= len;
847
+ s = Math.sin(rad);
848
+ c = Math.cos(rad);
849
+ t = 1 - c;
850
+ // Perform rotation-specific matrix multiplication
851
+ out[0] = x * x * t + c;
852
+ out[1] = y * x * t + z * s;
853
+ out[2] = z * x * t - y * s;
854
+ out[3] = 0;
855
+ out[4] = x * y * t - z * s;
856
+ out[5] = y * y * t + c;
857
+ out[6] = z * y * t + x * s;
858
+ out[7] = 0;
859
+ out[8] = x * z * t + y * s;
860
+ out[9] = y * z * t - x * s;
861
+ out[10] = z * z * t + c;
862
+ out[11] = 0;
863
+ out[12] = 0;
864
+ out[13] = 0;
865
+ out[14] = 0;
866
+ out[15] = 1;
867
+ return out;
680
868
  }
869
+ /**
870
+ * Creates a matrix from the given angle around the X axis
871
+ * This is equivalent to (but much faster than):
872
+ *
873
+ * mat4.identity(dest);
874
+ * mat4.rotateX(dest, dest, rad);
875
+ *
876
+ * @param {mat4} out mat4 receiving operation result
877
+ * @param {Number} rad the angle to rotate the matrix by
878
+ * @returns {mat4} out
879
+ */
681
880
  export function fromXRotation(out, rad) {
682
- const s = Math.sin(rad);
683
- const c = Math.cos(rad);
684
- out[0] = 1;
685
- out[1] = 0;
686
- out[2] = 0;
687
- out[3] = 0;
688
- out[4] = 0;
689
- out[5] = c;
690
- out[6] = s;
691
- out[7] = 0;
692
- out[8] = 0;
693
- out[9] = -s;
694
- out[10] = c;
695
- out[11] = 0;
696
- out[12] = 0;
697
- out[13] = 0;
698
- out[14] = 0;
699
- out[15] = 1;
700
- return out;
881
+ const s = Math.sin(rad);
882
+ const c = Math.cos(rad);
883
+ // Perform axis-specific matrix multiplication
884
+ out[0] = 1;
885
+ out[1] = 0;
886
+ out[2] = 0;
887
+ out[3] = 0;
888
+ out[4] = 0;
889
+ out[5] = c;
890
+ out[6] = s;
891
+ out[7] = 0;
892
+ out[8] = 0;
893
+ out[9] = -s;
894
+ out[10] = c;
895
+ out[11] = 0;
896
+ out[12] = 0;
897
+ out[13] = 0;
898
+ out[14] = 0;
899
+ out[15] = 1;
900
+ return out;
701
901
  }
902
+ /**
903
+ * Creates a matrix from the given angle around the Y axis
904
+ * This is equivalent to (but much faster than):
905
+ *
906
+ * mat4.identity(dest);
907
+ * mat4.rotateY(dest, dest, rad);
908
+ *
909
+ * @param {mat4} out mat4 receiving operation result
910
+ * @param {Number} rad the angle to rotate the matrix by
911
+ * @returns {mat4} out
912
+ */
702
913
  export function fromYRotation(out, rad) {
703
- const s = Math.sin(rad);
704
- const c = Math.cos(rad);
705
- out[0] = c;
706
- out[1] = 0;
707
- out[2] = -s;
708
- out[3] = 0;
709
- out[4] = 0;
710
- out[5] = 1;
711
- out[6] = 0;
712
- out[7] = 0;
713
- out[8] = s;
714
- out[9] = 0;
715
- out[10] = c;
716
- out[11] = 0;
717
- out[12] = 0;
718
- out[13] = 0;
719
- out[14] = 0;
720
- out[15] = 1;
721
- return out;
914
+ const s = Math.sin(rad);
915
+ const c = Math.cos(rad);
916
+ // Perform axis-specific matrix multiplication
917
+ out[0] = c;
918
+ out[1] = 0;
919
+ out[2] = -s;
920
+ out[3] = 0;
921
+ out[4] = 0;
922
+ out[5] = 1;
923
+ out[6] = 0;
924
+ out[7] = 0;
925
+ out[8] = s;
926
+ out[9] = 0;
927
+ out[10] = c;
928
+ out[11] = 0;
929
+ out[12] = 0;
930
+ out[13] = 0;
931
+ out[14] = 0;
932
+ out[15] = 1;
933
+ return out;
722
934
  }
935
+ /**
936
+ * Creates a matrix from the given angle around the Z axis
937
+ * This is equivalent to (but much faster than):
938
+ *
939
+ * mat4.identity(dest);
940
+ * mat4.rotateZ(dest, dest, rad);
941
+ *
942
+ * @param {mat4} out mat4 receiving operation result
943
+ * @param {Number} rad the angle to rotate the matrix by
944
+ * @returns {mat4} out
945
+ */
723
946
  export function fromZRotation(out, rad) {
724
- const s = Math.sin(rad);
725
- const c = Math.cos(rad);
726
- out[0] = c;
727
- out[1] = s;
728
- out[2] = 0;
729
- out[3] = 0;
730
- out[4] = -s;
731
- out[5] = c;
732
- out[6] = 0;
733
- out[7] = 0;
734
- out[8] = 0;
735
- out[9] = 0;
736
- out[10] = 1;
737
- out[11] = 0;
738
- out[12] = 0;
739
- out[13] = 0;
740
- out[14] = 0;
741
- out[15] = 1;
742
- return out;
947
+ const s = Math.sin(rad);
948
+ const c = Math.cos(rad);
949
+ // Perform axis-specific matrix multiplication
950
+ out[0] = c;
951
+ out[1] = s;
952
+ out[2] = 0;
953
+ out[3] = 0;
954
+ out[4] = -s;
955
+ out[5] = c;
956
+ out[6] = 0;
957
+ out[7] = 0;
958
+ out[8] = 0;
959
+ out[9] = 0;
960
+ out[10] = 1;
961
+ out[11] = 0;
962
+ out[12] = 0;
963
+ out[13] = 0;
964
+ out[14] = 0;
965
+ out[15] = 1;
966
+ return out;
743
967
  }
968
+ /**
969
+ * Creates a matrix from a quaternion rotation and vector translation
970
+ * This is equivalent to (but much faster than):
971
+ *
972
+ * mat4.identity(dest);
973
+ * mat4.translate(dest, vec);
974
+ * let quatMat = mat4.create();
975
+ * quat4.toMat4(quat, quatMat);
976
+ * mat4.multiply(dest, quatMat);
977
+ *
978
+ * @param {mat4} out mat4 receiving operation result
979
+ * @param {quat4} q Rotation quaternion
980
+ * @param {ReadonlyVec3} v Translation vector
981
+ * @returns {mat4} out
982
+ */
744
983
  export function fromRotationTranslation(out, q, v) {
745
- const x = q[0];
746
- const y = q[1];
747
- const z = q[2];
748
- const w = q[3];
749
- const x2 = x + x;
750
- const y2 = y + y;
751
- const z2 = z + z;
752
- const xx = x * x2;
753
- const xy = x * y2;
754
- const xz = x * z2;
755
- const yy = y * y2;
756
- const yz = y * z2;
757
- const zz = z * z2;
758
- const wx = w * x2;
759
- const wy = w * y2;
760
- const wz = w * z2;
761
- out[0] = 1 - (yy + zz);
762
- out[1] = xy + wz;
763
- out[2] = xz - wy;
764
- out[3] = 0;
765
- out[4] = xy - wz;
766
- out[5] = 1 - (xx + zz);
767
- out[6] = yz + wx;
768
- out[7] = 0;
769
- out[8] = xz + wy;
770
- out[9] = yz - wx;
771
- out[10] = 1 - (xx + yy);
772
- out[11] = 0;
773
- out[12] = v[0];
774
- out[13] = v[1];
775
- out[14] = v[2];
776
- out[15] = 1;
777
- return out;
984
+ // Quaternion math
985
+ const x = q[0];
986
+ const y = q[1];
987
+ const z = q[2];
988
+ const w = q[3];
989
+ const x2 = x + x;
990
+ const y2 = y + y;
991
+ const z2 = z + z;
992
+ const xx = x * x2;
993
+ const xy = x * y2;
994
+ const xz = x * z2;
995
+ const yy = y * y2;
996
+ const yz = y * z2;
997
+ const zz = z * z2;
998
+ const wx = w * x2;
999
+ const wy = w * y2;
1000
+ const wz = w * z2;
1001
+ out[0] = 1 - (yy + zz);
1002
+ out[1] = xy + wz;
1003
+ out[2] = xz - wy;
1004
+ out[3] = 0;
1005
+ out[4] = xy - wz;
1006
+ out[5] = 1 - (xx + zz);
1007
+ out[6] = yz + wx;
1008
+ out[7] = 0;
1009
+ out[8] = xz + wy;
1010
+ out[9] = yz - wx;
1011
+ out[10] = 1 - (xx + yy);
1012
+ out[11] = 0;
1013
+ out[12] = v[0];
1014
+ out[13] = v[1];
1015
+ out[14] = v[2];
1016
+ out[15] = 1;
1017
+ return out;
778
1018
  }
1019
+ /**
1020
+ * Creates a new mat4 from a dual quat.
1021
+ *
1022
+ * @param {mat4} out Matrix
1023
+ * @param {ReadonlyQuat2} a Dual Quaternion
1024
+ * @returns {mat4} mat4 receiving operation result
1025
+ */
779
1026
  export function fromQuat2(out, a) {
780
- const translation = new glMatrix.ARRAY_TYPE(3);
781
- const bx = -a[0];
782
- const by = -a[1];
783
- const bz = -a[2];
784
- const bw = a[3];
785
- const ax = a[4];
786
- const ay = a[5];
787
- const az = a[6];
788
- const aw = a[7];
789
- const magnitude = bx * bx + by * by + bz * bz + bw * bw;
790
-
791
- if (magnitude > 0) {
792
- translation[0] = (ax * bw + aw * bx + ay * bz - az * by) * 2 / magnitude;
793
- translation[1] = (ay * bw + aw * by + az * bx - ax * bz) * 2 / magnitude;
794
- translation[2] = (az * bw + aw * bz + ax * by - ay * bx) * 2 / magnitude;
795
- } else {
796
- translation[0] = (ax * bw + aw * bx + ay * bz - az * by) * 2;
797
- translation[1] = (ay * bw + aw * by + az * bx - ax * bz) * 2;
798
- translation[2] = (az * bw + aw * bz + ax * by - ay * bx) * 2;
799
- }
800
-
801
- fromRotationTranslation(out, a, translation);
802
- return out;
1027
+ const translation = new glMatrix.ARRAY_TYPE(3);
1028
+ const bx = -a[0];
1029
+ const by = -a[1];
1030
+ const bz = -a[2];
1031
+ const bw = a[3];
1032
+ const ax = a[4];
1033
+ const ay = a[5];
1034
+ const az = a[6];
1035
+ const aw = a[7];
1036
+ const magnitude = bx * bx + by * by + bz * bz + bw * bw;
1037
+ // Only scale if it makes sense
1038
+ if (magnitude > 0) {
1039
+ translation[0] = ((ax * bw + aw * bx + ay * bz - az * by) * 2) / magnitude;
1040
+ translation[1] = ((ay * bw + aw * by + az * bx - ax * bz) * 2) / magnitude;
1041
+ translation[2] = ((az * bw + aw * bz + ax * by - ay * bx) * 2) / magnitude;
1042
+ }
1043
+ else {
1044
+ translation[0] = (ax * bw + aw * bx + ay * bz - az * by) * 2;
1045
+ translation[1] = (ay * bw + aw * by + az * bx - ax * bz) * 2;
1046
+ translation[2] = (az * bw + aw * bz + ax * by - ay * bx) * 2;
1047
+ }
1048
+ fromRotationTranslation(out, a, translation);
1049
+ return out;
803
1050
  }
1051
+ /**
1052
+ * Returns the translation vector component of a transformation
1053
+ * matrix. If a matrix is built with fromRotationTranslation,
1054
+ * the returned vector will be the same as the translation vector
1055
+ * originally supplied.
1056
+ * @param {vec3} out Vector to receive translation component
1057
+ * @param {ReadonlyMat4} mat Matrix to be decomposed (input)
1058
+ * @return {vec3} out
1059
+ */
804
1060
  export function getTranslation(out, mat) {
805
- out[0] = mat[12];
806
- out[1] = mat[13];
807
- out[2] = mat[14];
808
- return out;
1061
+ out[0] = mat[12];
1062
+ out[1] = mat[13];
1063
+ out[2] = mat[14];
1064
+ return out;
809
1065
  }
1066
+ /**
1067
+ * Returns the scaling factor component of a transformation
1068
+ * matrix. If a matrix is built with fromRotationTranslationScale
1069
+ * with a normalized Quaternion paramter, the returned vector will be
1070
+ * the same as the scaling vector
1071
+ * originally supplied.
1072
+ * @param {vec3} out Vector to receive scaling factor component
1073
+ * @param {ReadonlyMat4} mat Matrix to be decomposed (input)
1074
+ * @return {vec3} out
1075
+ */
810
1076
  export function getScaling(out, mat) {
811
- const m11 = mat[0];
812
- const m12 = mat[1];
813
- const m13 = mat[2];
814
- const m21 = mat[4];
815
- const m22 = mat[5];
816
- const m23 = mat[6];
817
- const m31 = mat[8];
818
- const m32 = mat[9];
819
- const m33 = mat[10];
820
- out[0] = Math.sqrt(m11 * m11 + m12 * m12 + m13 * m13);
821
- out[1] = Math.sqrt(m21 * m21 + m22 * m22 + m23 * m23);
822
- out[2] = Math.sqrt(m31 * m31 + m32 * m32 + m33 * m33);
823
- return out;
1077
+ const m11 = mat[0];
1078
+ const m12 = mat[1];
1079
+ const m13 = mat[2];
1080
+ const m21 = mat[4];
1081
+ const m22 = mat[5];
1082
+ const m23 = mat[6];
1083
+ const m31 = mat[8];
1084
+ const m32 = mat[9];
1085
+ const m33 = mat[10];
1086
+ out[0] = Math.sqrt(m11 * m11 + m12 * m12 + m13 * m13);
1087
+ out[1] = Math.sqrt(m21 * m21 + m22 * m22 + m23 * m23);
1088
+ out[2] = Math.sqrt(m31 * m31 + m32 * m32 + m33 * m33);
1089
+ return out;
824
1090
  }
1091
+ /**
1092
+ * Returns a quaternion representing the rotational component
1093
+ * of a transformation matrix. If a matrix is built with
1094
+ * fromRotationTranslation, the returned quaternion will be the
1095
+ * same as the quaternion originally supplied.
1096
+ * @param {quat} out Quaternion to receive the rotation component
1097
+ * @param {ReadonlyMat4} mat Matrix to be decomposed (input)
1098
+ * @return {quat} out
1099
+ */
825
1100
  export function getRotation(out, mat) {
826
- const scaling = new glMatrix.ARRAY_TYPE(3);
827
- getScaling(scaling, mat);
828
- const is1 = 1 / scaling[0];
829
- const is2 = 1 / scaling[1];
830
- const is3 = 1 / scaling[2];
831
- const sm11 = mat[0] * is1;
832
- const sm12 = mat[1] * is2;
833
- const sm13 = mat[2] * is3;
834
- const sm21 = mat[4] * is1;
835
- const sm22 = mat[5] * is2;
836
- const sm23 = mat[6] * is3;
837
- const sm31 = mat[8] * is1;
838
- const sm32 = mat[9] * is2;
839
- const sm33 = mat[10] * is3;
840
- const trace = sm11 + sm22 + sm33;
841
- let S = 0;
842
-
843
- if (trace > 0) {
844
- S = Math.sqrt(trace + 1.0) * 2;
845
- out[3] = 0.25 * S;
846
- out[0] = (sm23 - sm32) / S;
847
- out[1] = (sm31 - sm13) / S;
848
- out[2] = (sm12 - sm21) / S;
849
- } else if (sm11 > sm22 && sm11 > sm33) {
850
- S = Math.sqrt(1.0 + sm11 - sm22 - sm33) * 2;
851
- out[3] = (sm23 - sm32) / S;
852
- out[0] = 0.25 * S;
853
- out[1] = (sm12 + sm21) / S;
854
- out[2] = (sm31 + sm13) / S;
855
- } else if (sm22 > sm33) {
856
- S = Math.sqrt(1.0 + sm22 - sm11 - sm33) * 2;
857
- out[3] = (sm31 - sm13) / S;
858
- out[0] = (sm12 + sm21) / S;
859
- out[1] = 0.25 * S;
860
- out[2] = (sm23 + sm32) / S;
861
- } else {
862
- S = Math.sqrt(1.0 + sm33 - sm11 - sm22) * 2;
863
- out[3] = (sm12 - sm21) / S;
864
- out[0] = (sm31 + sm13) / S;
865
- out[1] = (sm23 + sm32) / S;
866
- out[2] = 0.25 * S;
867
- }
868
-
869
- return out;
1101
+ const scaling = new glMatrix.ARRAY_TYPE(3);
1102
+ getScaling(scaling, mat);
1103
+ const is1 = 1 / scaling[0];
1104
+ const is2 = 1 / scaling[1];
1105
+ const is3 = 1 / scaling[2];
1106
+ const sm11 = mat[0] * is1;
1107
+ const sm12 = mat[1] * is2;
1108
+ const sm13 = mat[2] * is3;
1109
+ const sm21 = mat[4] * is1;
1110
+ const sm22 = mat[5] * is2;
1111
+ const sm23 = mat[6] * is3;
1112
+ const sm31 = mat[8] * is1;
1113
+ const sm32 = mat[9] * is2;
1114
+ const sm33 = mat[10] * is3;
1115
+ const trace = sm11 + sm22 + sm33;
1116
+ let S = 0;
1117
+ if (trace > 0) {
1118
+ S = Math.sqrt(trace + 1.0) * 2;
1119
+ out[3] = 0.25 * S;
1120
+ out[0] = (sm23 - sm32) / S;
1121
+ out[1] = (sm31 - sm13) / S;
1122
+ out[2] = (sm12 - sm21) / S;
1123
+ }
1124
+ else if (sm11 > sm22 && sm11 > sm33) {
1125
+ S = Math.sqrt(1.0 + sm11 - sm22 - sm33) * 2;
1126
+ out[3] = (sm23 - sm32) / S;
1127
+ out[0] = 0.25 * S;
1128
+ out[1] = (sm12 + sm21) / S;
1129
+ out[2] = (sm31 + sm13) / S;
1130
+ }
1131
+ else if (sm22 > sm33) {
1132
+ S = Math.sqrt(1.0 + sm22 - sm11 - sm33) * 2;
1133
+ out[3] = (sm31 - sm13) / S;
1134
+ out[0] = (sm12 + sm21) / S;
1135
+ out[1] = 0.25 * S;
1136
+ out[2] = (sm23 + sm32) / S;
1137
+ }
1138
+ else {
1139
+ S = Math.sqrt(1.0 + sm33 - sm11 - sm22) * 2;
1140
+ out[3] = (sm12 - sm21) / S;
1141
+ out[0] = (sm31 + sm13) / S;
1142
+ out[1] = (sm23 + sm32) / S;
1143
+ out[2] = 0.25 * S;
1144
+ }
1145
+ return out;
870
1146
  }
1147
+ /**
1148
+ * Decomposes a transformation matrix into its rotation, translation
1149
+ * and scale components. Returns only the rotation component
1150
+ * @param {quat} out_r Quaternion to receive the rotation component
1151
+ * @param {vec3} out_t Vector to receive the translation vector
1152
+ * @param {vec3} out_s Vector to receive the scaling factor
1153
+ * @param {ReadonlyMat4} mat Matrix to be decomposed (input)
1154
+ * @returns {quat} out_r
1155
+ */
871
1156
  export function decompose(out_r, out_t, out_s, mat) {
872
- out_t[0] = mat[12];
873
- out_t[1] = mat[13];
874
- out_t[2] = mat[14];
875
- const m11 = mat[0];
876
- const m12 = mat[1];
877
- const m13 = mat[2];
878
- const m21 = mat[4];
879
- const m22 = mat[5];
880
- const m23 = mat[6];
881
- const m31 = mat[8];
882
- const m32 = mat[9];
883
- const m33 = mat[10];
884
- out_s[0] = Math.sqrt(m11 * m11 + m12 * m12 + m13 * m13);
885
- out_s[1] = Math.sqrt(m21 * m21 + m22 * m22 + m23 * m23);
886
- out_s[2] = Math.sqrt(m31 * m31 + m32 * m32 + m33 * m33);
887
- const is1 = 1 / out_s[0];
888
- const is2 = 1 / out_s[1];
889
- const is3 = 1 / out_s[2];
890
- const sm11 = m11 * is1;
891
- const sm12 = m12 * is2;
892
- const sm13 = m13 * is3;
893
- const sm21 = m21 * is1;
894
- const sm22 = m22 * is2;
895
- const sm23 = m23 * is3;
896
- const sm31 = m31 * is1;
897
- const sm32 = m32 * is2;
898
- const sm33 = m33 * is3;
899
- const trace = sm11 + sm22 + sm33;
900
- let S = 0;
901
-
902
- if (trace > 0) {
903
- S = Math.sqrt(trace + 1.0) * 2;
904
- out_r[3] = 0.25 * S;
905
- out_r[0] = (sm23 - sm32) / S;
906
- out_r[1] = (sm31 - sm13) / S;
907
- out_r[2] = (sm12 - sm21) / S;
908
- } else if (sm11 > sm22 && sm11 > sm33) {
909
- S = Math.sqrt(1.0 + sm11 - sm22 - sm33) * 2;
910
- out_r[3] = (sm23 - sm32) / S;
911
- out_r[0] = 0.25 * S;
912
- out_r[1] = (sm12 + sm21) / S;
913
- out_r[2] = (sm31 + sm13) / S;
914
- } else if (sm22 > sm33) {
915
- S = Math.sqrt(1.0 + sm22 - sm11 - sm33) * 2;
916
- out_r[3] = (sm31 - sm13) / S;
917
- out_r[0] = (sm12 + sm21) / S;
918
- out_r[1] = 0.25 * S;
919
- out_r[2] = (sm23 + sm32) / S;
920
- } else {
921
- S = Math.sqrt(1.0 + sm33 - sm11 - sm22) * 2;
922
- out_r[3] = (sm12 - sm21) / S;
923
- out_r[0] = (sm31 + sm13) / S;
924
- out_r[1] = (sm23 + sm32) / S;
925
- out_r[2] = 0.25 * S;
926
- }
927
-
928
- return out_r;
1157
+ out_t[0] = mat[12];
1158
+ out_t[1] = mat[13];
1159
+ out_t[2] = mat[14];
1160
+ const m11 = mat[0];
1161
+ const m12 = mat[1];
1162
+ const m13 = mat[2];
1163
+ const m21 = mat[4];
1164
+ const m22 = mat[5];
1165
+ const m23 = mat[6];
1166
+ const m31 = mat[8];
1167
+ const m32 = mat[9];
1168
+ const m33 = mat[10];
1169
+ out_s[0] = Math.sqrt(m11 * m11 + m12 * m12 + m13 * m13);
1170
+ out_s[1] = Math.sqrt(m21 * m21 + m22 * m22 + m23 * m23);
1171
+ out_s[2] = Math.sqrt(m31 * m31 + m32 * m32 + m33 * m33);
1172
+ const is1 = 1 / out_s[0];
1173
+ const is2 = 1 / out_s[1];
1174
+ const is3 = 1 / out_s[2];
1175
+ const sm11 = m11 * is1;
1176
+ const sm12 = m12 * is2;
1177
+ const sm13 = m13 * is3;
1178
+ const sm21 = m21 * is1;
1179
+ const sm22 = m22 * is2;
1180
+ const sm23 = m23 * is3;
1181
+ const sm31 = m31 * is1;
1182
+ const sm32 = m32 * is2;
1183
+ const sm33 = m33 * is3;
1184
+ const trace = sm11 + sm22 + sm33;
1185
+ let S = 0;
1186
+ if (trace > 0) {
1187
+ S = Math.sqrt(trace + 1.0) * 2;
1188
+ out_r[3] = 0.25 * S;
1189
+ out_r[0] = (sm23 - sm32) / S;
1190
+ out_r[1] = (sm31 - sm13) / S;
1191
+ out_r[2] = (sm12 - sm21) / S;
1192
+ }
1193
+ else if (sm11 > sm22 && sm11 > sm33) {
1194
+ S = Math.sqrt(1.0 + sm11 - sm22 - sm33) * 2;
1195
+ out_r[3] = (sm23 - sm32) / S;
1196
+ out_r[0] = 0.25 * S;
1197
+ out_r[1] = (sm12 + sm21) / S;
1198
+ out_r[2] = (sm31 + sm13) / S;
1199
+ }
1200
+ else if (sm22 > sm33) {
1201
+ S = Math.sqrt(1.0 + sm22 - sm11 - sm33) * 2;
1202
+ out_r[3] = (sm31 - sm13) / S;
1203
+ out_r[0] = (sm12 + sm21) / S;
1204
+ out_r[1] = 0.25 * S;
1205
+ out_r[2] = (sm23 + sm32) / S;
1206
+ }
1207
+ else {
1208
+ S = Math.sqrt(1.0 + sm33 - sm11 - sm22) * 2;
1209
+ out_r[3] = (sm12 - sm21) / S;
1210
+ out_r[0] = (sm31 + sm13) / S;
1211
+ out_r[1] = (sm23 + sm32) / S;
1212
+ out_r[2] = 0.25 * S;
1213
+ }
1214
+ return out_r;
929
1215
  }
1216
+ /**
1217
+ * Creates a matrix from a quaternion rotation, vector translation and vector scale
1218
+ * This is equivalent to (but much faster than):
1219
+ *
1220
+ * mat4.identity(dest);
1221
+ * mat4.translate(dest, vec);
1222
+ * let quatMat = mat4.create();
1223
+ * quat4.toMat4(quat, quatMat);
1224
+ * mat4.multiply(dest, quatMat);
1225
+ * mat4.scale(dest, scale)
1226
+ *
1227
+ * @param {mat4} out mat4 receiving operation result
1228
+ * @param {quat4} q Rotation quaternion
1229
+ * @param {ReadonlyVec3} v Translation vector
1230
+ * @param {ReadonlyVec3} s Scaling vector
1231
+ * @returns {mat4} out
1232
+ */
930
1233
  export function fromRotationTranslationScale(out, q, v, s) {
931
- const x = q[0];
932
- const y = q[1];
933
- const z = q[2];
934
- const w = q[3];
935
- const x2 = x + x;
936
- const y2 = y + y;
937
- const z2 = z + z;
938
- const xx = x * x2;
939
- const xy = x * y2;
940
- const xz = x * z2;
941
- const yy = y * y2;
942
- const yz = y * z2;
943
- const zz = z * z2;
944
- const wx = w * x2;
945
- const wy = w * y2;
946
- const wz = w * z2;
947
- const sx = s[0];
948
- const sy = s[1];
949
- const sz = s[2];
950
- out[0] = (1 - (yy + zz)) * sx;
951
- out[1] = (xy + wz) * sx;
952
- out[2] = (xz - wy) * sx;
953
- out[3] = 0;
954
- out[4] = (xy - wz) * sy;
955
- out[5] = (1 - (xx + zz)) * sy;
956
- out[6] = (yz + wx) * sy;
957
- out[7] = 0;
958
- out[8] = (xz + wy) * sz;
959
- out[9] = (yz - wx) * sz;
960
- out[10] = (1 - (xx + yy)) * sz;
961
- out[11] = 0;
962
- out[12] = v[0];
963
- out[13] = v[1];
964
- out[14] = v[2];
965
- out[15] = 1;
966
- return out;
1234
+ // Quaternion math
1235
+ const x = q[0];
1236
+ const y = q[1];
1237
+ const z = q[2];
1238
+ const w = q[3];
1239
+ const x2 = x + x;
1240
+ const y2 = y + y;
1241
+ const z2 = z + z;
1242
+ const xx = x * x2;
1243
+ const xy = x * y2;
1244
+ const xz = x * z2;
1245
+ const yy = y * y2;
1246
+ const yz = y * z2;
1247
+ const zz = z * z2;
1248
+ const wx = w * x2;
1249
+ const wy = w * y2;
1250
+ const wz = w * z2;
1251
+ const sx = s[0];
1252
+ const sy = s[1];
1253
+ const sz = s[2];
1254
+ out[0] = (1 - (yy + zz)) * sx;
1255
+ out[1] = (xy + wz) * sx;
1256
+ out[2] = (xz - wy) * sx;
1257
+ out[3] = 0;
1258
+ out[4] = (xy - wz) * sy;
1259
+ out[5] = (1 - (xx + zz)) * sy;
1260
+ out[6] = (yz + wx) * sy;
1261
+ out[7] = 0;
1262
+ out[8] = (xz + wy) * sz;
1263
+ out[9] = (yz - wx) * sz;
1264
+ out[10] = (1 - (xx + yy)) * sz;
1265
+ out[11] = 0;
1266
+ out[12] = v[0];
1267
+ out[13] = v[1];
1268
+ out[14] = v[2];
1269
+ out[15] = 1;
1270
+ return out;
967
1271
  }
1272
+ /**
1273
+ * Creates a matrix from a quaternion rotation, vector translation and vector scale, rotating and scaling around the given origin
1274
+ * This is equivalent to (but much faster than):
1275
+ *
1276
+ * mat4.identity(dest);
1277
+ * mat4.translate(dest, vec);
1278
+ * mat4.translate(dest, origin);
1279
+ * let quatMat = mat4.create();
1280
+ * quat4.toMat4(quat, quatMat);
1281
+ * mat4.multiply(dest, quatMat);
1282
+ * mat4.scale(dest, scale)
1283
+ * mat4.translate(dest, negativeOrigin);
1284
+ *
1285
+ * @param {mat4} out mat4 receiving operation result
1286
+ * @param {quat4} q Rotation quaternion
1287
+ * @param {ReadonlyVec3} v Translation vector
1288
+ * @param {ReadonlyVec3} s Scaling vector
1289
+ * @param {ReadonlyVec3} o The origin vector around which to scale and rotate
1290
+ * @returns {mat4} out
1291
+ */
968
1292
  export function fromRotationTranslationScaleOrigin(out, q, v, s, o) {
969
- const x = q[0];
970
- const y = q[1];
971
- const z = q[2];
972
- const w = q[3];
973
- const x2 = x + x;
974
- const y2 = y + y;
975
- const z2 = z + z;
976
- const xx = x * x2;
977
- const xy = x * y2;
978
- const xz = x * z2;
979
- const yy = y * y2;
980
- const yz = y * z2;
981
- const zz = z * z2;
982
- const wx = w * x2;
983
- const wy = w * y2;
984
- const wz = w * z2;
985
- const sx = s[0];
986
- const sy = s[1];
987
- const sz = s[2];
988
- const ox = o[0];
989
- const oy = o[1];
990
- const oz = o[2];
991
- const out0 = (1 - (yy + zz)) * sx;
992
- const out1 = (xy + wz) * sx;
993
- const out2 = (xz - wy) * sx;
994
- const out4 = (xy - wz) * sy;
995
- const out5 = (1 - (xx + zz)) * sy;
996
- const out6 = (yz + wx) * sy;
997
- const out8 = (xz + wy) * sz;
998
- const out9 = (yz - wx) * sz;
999
- const out10 = (1 - (xx + yy)) * sz;
1000
- out[0] = out0;
1001
- out[1] = out1;
1002
- out[2] = out2;
1003
- out[3] = 0;
1004
- out[4] = out4;
1005
- out[5] = out5;
1006
- out[6] = out6;
1007
- out[7] = 0;
1008
- out[8] = out8;
1009
- out[9] = out9;
1010
- out[10] = out10;
1011
- out[11] = 0;
1012
- out[12] = v[0] + ox - (out0 * ox + out4 * oy + out8 * oz);
1013
- out[13] = v[1] + oy - (out1 * ox + out5 * oy + out9 * oz);
1014
- out[14] = v[2] + oz - (out2 * ox + out6 * oy + out10 * oz);
1015
- out[15] = 1;
1016
- return out;
1293
+ // Quaternion math
1294
+ const x = q[0];
1295
+ const y = q[1];
1296
+ const z = q[2];
1297
+ const w = q[3];
1298
+ const x2 = x + x;
1299
+ const y2 = y + y;
1300
+ const z2 = z + z;
1301
+ const xx = x * x2;
1302
+ const xy = x * y2;
1303
+ const xz = x * z2;
1304
+ const yy = y * y2;
1305
+ const yz = y * z2;
1306
+ const zz = z * z2;
1307
+ const wx = w * x2;
1308
+ const wy = w * y2;
1309
+ const wz = w * z2;
1310
+ const sx = s[0];
1311
+ const sy = s[1];
1312
+ const sz = s[2];
1313
+ const ox = o[0];
1314
+ const oy = o[1];
1315
+ const oz = o[2];
1316
+ const out0 = (1 - (yy + zz)) * sx;
1317
+ const out1 = (xy + wz) * sx;
1318
+ const out2 = (xz - wy) * sx;
1319
+ const out4 = (xy - wz) * sy;
1320
+ const out5 = (1 - (xx + zz)) * sy;
1321
+ const out6 = (yz + wx) * sy;
1322
+ const out8 = (xz + wy) * sz;
1323
+ const out9 = (yz - wx) * sz;
1324
+ const out10 = (1 - (xx + yy)) * sz;
1325
+ out[0] = out0;
1326
+ out[1] = out1;
1327
+ out[2] = out2;
1328
+ out[3] = 0;
1329
+ out[4] = out4;
1330
+ out[5] = out5;
1331
+ out[6] = out6;
1332
+ out[7] = 0;
1333
+ out[8] = out8;
1334
+ out[9] = out9;
1335
+ out[10] = out10;
1336
+ out[11] = 0;
1337
+ out[12] = v[0] + ox - (out0 * ox + out4 * oy + out8 * oz);
1338
+ out[13] = v[1] + oy - (out1 * ox + out5 * oy + out9 * oz);
1339
+ out[14] = v[2] + oz - (out2 * ox + out6 * oy + out10 * oz);
1340
+ out[15] = 1;
1341
+ return out;
1017
1342
  }
1343
+ /**
1344
+ * Calculates a 4x4 matrix from the given quaternion
1345
+ *
1346
+ * @param {mat4} out mat4 receiving operation result
1347
+ * @param {ReadonlyQuat} q Quaternion to create matrix from
1348
+ *
1349
+ * @returns {mat4} out
1350
+ */
1018
1351
  export function fromQuat(out, q) {
1019
- const x = q[0];
1020
- const y = q[1];
1021
- const z = q[2];
1022
- const w = q[3];
1023
- const x2 = x + x;
1024
- const y2 = y + y;
1025
- const z2 = z + z;
1026
- const xx = x * x2;
1027
- const yx = y * x2;
1028
- const yy = y * y2;
1029
- const zx = z * x2;
1030
- const zy = z * y2;
1031
- const zz = z * z2;
1032
- const wx = w * x2;
1033
- const wy = w * y2;
1034
- const wz = w * z2;
1035
- out[0] = 1 - yy - zz;
1036
- out[1] = yx + wz;
1037
- out[2] = zx - wy;
1038
- out[3] = 0;
1039
- out[4] = yx - wz;
1040
- out[5] = 1 - xx - zz;
1041
- out[6] = zy + wx;
1042
- out[7] = 0;
1043
- out[8] = zx + wy;
1044
- out[9] = zy - wx;
1045
- out[10] = 1 - xx - yy;
1046
- out[11] = 0;
1047
- out[12] = 0;
1048
- out[13] = 0;
1049
- out[14] = 0;
1050
- out[15] = 1;
1051
- return out;
1352
+ const x = q[0];
1353
+ const y = q[1];
1354
+ const z = q[2];
1355
+ const w = q[3];
1356
+ const x2 = x + x;
1357
+ const y2 = y + y;
1358
+ const z2 = z + z;
1359
+ const xx = x * x2;
1360
+ const yx = y * x2;
1361
+ const yy = y * y2;
1362
+ const zx = z * x2;
1363
+ const zy = z * y2;
1364
+ const zz = z * z2;
1365
+ const wx = w * x2;
1366
+ const wy = w * y2;
1367
+ const wz = w * z2;
1368
+ out[0] = 1 - yy - zz;
1369
+ out[1] = yx + wz;
1370
+ out[2] = zx - wy;
1371
+ out[3] = 0;
1372
+ out[4] = yx - wz;
1373
+ out[5] = 1 - xx - zz;
1374
+ out[6] = zy + wx;
1375
+ out[7] = 0;
1376
+ out[8] = zx + wy;
1377
+ out[9] = zy - wx;
1378
+ out[10] = 1 - xx - yy;
1379
+ out[11] = 0;
1380
+ out[12] = 0;
1381
+ out[13] = 0;
1382
+ out[14] = 0;
1383
+ out[15] = 1;
1384
+ return out;
1052
1385
  }
1386
+ /**
1387
+ * Generates a frustum matrix with the given bounds
1388
+ *
1389
+ * @param {mat4} out mat4 frustum matrix will be written into
1390
+ * @param {Number} left Left bound of the frustum
1391
+ * @param {Number} right Right bound of the frustum
1392
+ * @param {Number} bottom Bottom bound of the frustum
1393
+ * @param {Number} top Top bound of the frustum
1394
+ * @param {Number} near Near bound of the frustum
1395
+ * @param {Number} far Far bound of the frustum
1396
+ * @returns {mat4} out
1397
+ */
1053
1398
  export function frustum(out, left, right, bottom, top, near, far) {
1054
- const rl = 1 / (right - left);
1055
- const tb = 1 / (top - bottom);
1056
- const nf = 1 / (near - far);
1057
- out[0] = near * 2 * rl;
1058
- out[1] = 0;
1059
- out[2] = 0;
1060
- out[3] = 0;
1061
- out[4] = 0;
1062
- out[5] = near * 2 * tb;
1063
- out[6] = 0;
1064
- out[7] = 0;
1065
- out[8] = (right + left) * rl;
1066
- out[9] = (top + bottom) * tb;
1067
- out[10] = (far + near) * nf;
1068
- out[11] = -1;
1069
- out[12] = 0;
1070
- out[13] = 0;
1071
- out[14] = far * near * 2 * nf;
1072
- out[15] = 0;
1073
- return out;
1074
- }
1075
- export function perspectiveNO(out, fovy, aspect, near, far) {
1076
- const f = 1.0 / Math.tan(fovy / 2);
1077
- out[0] = f / aspect;
1078
- out[1] = 0;
1079
- out[2] = 0;
1080
- out[3] = 0;
1081
- out[4] = 0;
1082
- out[5] = f;
1083
- out[6] = 0;
1084
- out[7] = 0;
1085
- out[8] = 0;
1086
- out[9] = 0;
1087
- out[11] = -1;
1088
- out[12] = 0;
1089
- out[13] = 0;
1090
- out[15] = 0;
1091
-
1092
- if (far != null && far !== Infinity) {
1399
+ const rl = 1 / (right - left);
1400
+ const tb = 1 / (top - bottom);
1093
1401
  const nf = 1 / (near - far);
1402
+ out[0] = near * 2 * rl;
1403
+ out[1] = 0;
1404
+ out[2] = 0;
1405
+ out[3] = 0;
1406
+ out[4] = 0;
1407
+ out[5] = near * 2 * tb;
1408
+ out[6] = 0;
1409
+ out[7] = 0;
1410
+ out[8] = (right + left) * rl;
1411
+ out[9] = (top + bottom) * tb;
1094
1412
  out[10] = (far + near) * nf;
1095
- out[14] = 2 * far * near * nf;
1096
- } else {
1097
- out[10] = -1;
1098
- out[14] = -2 * near;
1099
- }
1100
-
1101
- return out;
1413
+ out[11] = -1;
1414
+ out[12] = 0;
1415
+ out[13] = 0;
1416
+ out[14] = far * near * 2 * nf;
1417
+ out[15] = 0;
1418
+ return out;
1419
+ }
1420
+ /**
1421
+ * Generates a perspective projection matrix with the given bounds.
1422
+ * The near/far clip planes correspond to a normalized device coordinate Z range of [-1, 1],
1423
+ * which matches WebGL/OpenGL's clip volume.
1424
+ * Passing null/undefined/no value for far will generate infinite projection matrix.
1425
+ *
1426
+ * @param {mat4} out mat4 frustum matrix will be written into
1427
+ * @param {number} fovy Vertical field of view in radians
1428
+ * @param {number} aspect Aspect ratio. typically viewport width/height
1429
+ * @param {number} near Near bound of the frustum
1430
+ * @param {number} far Far bound of the frustum, can be null or Infinity
1431
+ * @returns {mat4} out
1432
+ */
1433
+ export function perspectiveNO(out, fovy, aspect, near, far) {
1434
+ const f = 1.0 / Math.tan(fovy / 2);
1435
+ out[0] = f / aspect;
1436
+ out[1] = 0;
1437
+ out[2] = 0;
1438
+ out[3] = 0;
1439
+ out[4] = 0;
1440
+ out[5] = f;
1441
+ out[6] = 0;
1442
+ out[7] = 0;
1443
+ out[8] = 0;
1444
+ out[9] = 0;
1445
+ out[11] = -1;
1446
+ out[12] = 0;
1447
+ out[13] = 0;
1448
+ out[15] = 0;
1449
+ if (far != null && far !== Infinity) {
1450
+ const nf = 1 / (near - far);
1451
+ out[10] = (far + near) * nf;
1452
+ out[14] = 2 * far * near * nf;
1453
+ }
1454
+ else {
1455
+ out[10] = -1;
1456
+ out[14] = -2 * near;
1457
+ }
1458
+ return out;
1102
1459
  }
1460
+ /**
1461
+ * Alias for {@link mat4.perspectiveNO}
1462
+ * @function
1463
+ */
1103
1464
  export const perspective = perspectiveNO;
1465
+ /**
1466
+ * Generates a perspective projection matrix suitable for WebGPU with the given bounds.
1467
+ * The near/far clip planes correspond to a normalized device coordinate Z range of [0, 1],
1468
+ * which matches WebGPU/Vulkan/DirectX/Metal's clip volume.
1469
+ * Passing null/undefined/no value for far will generate infinite projection matrix.
1470
+ *
1471
+ * @param {mat4} out mat4 frustum matrix will be written into
1472
+ * @param {number} fovy Vertical field of view in radians
1473
+ * @param {number} aspect Aspect ratio. typically viewport width/height
1474
+ * @param {number} near Near bound of the frustum
1475
+ * @param {number} far Far bound of the frustum, can be null or Infinity
1476
+ * @returns {mat4} out
1477
+ */
1104
1478
  export function perspectiveZO(out, fovy, aspect, near, far) {
1105
- const f = 1.0 / Math.tan(fovy / 2);
1106
- out[0] = f / aspect;
1107
- out[1] = 0;
1108
- out[2] = 0;
1109
- out[3] = 0;
1110
- out[4] = 0;
1111
- out[5] = f;
1112
- out[6] = 0;
1113
- out[7] = 0;
1114
- out[8] = 0;
1115
- out[9] = 0;
1116
- out[11] = -1;
1117
- out[12] = 0;
1118
- out[13] = 0;
1119
- out[15] = 0;
1120
-
1121
- if (far != null && far !== Infinity) {
1122
- const nf = 1 / (near - far);
1123
- out[10] = far * nf;
1124
- out[14] = far * near * nf;
1125
- } else {
1126
- out[10] = -1;
1127
- out[14] = -near;
1128
- }
1129
-
1130
- return out;
1479
+ const f = 1.0 / Math.tan(fovy / 2);
1480
+ out[0] = f / aspect;
1481
+ out[1] = 0;
1482
+ out[2] = 0;
1483
+ out[3] = 0;
1484
+ out[4] = 0;
1485
+ out[5] = f;
1486
+ out[6] = 0;
1487
+ out[7] = 0;
1488
+ out[8] = 0;
1489
+ out[9] = 0;
1490
+ out[11] = -1;
1491
+ out[12] = 0;
1492
+ out[13] = 0;
1493
+ out[15] = 0;
1494
+ if (far != null && far !== Infinity) {
1495
+ const nf = 1 / (near - far);
1496
+ out[10] = far * nf;
1497
+ out[14] = far * near * nf;
1498
+ }
1499
+ else {
1500
+ out[10] = -1;
1501
+ out[14] = -near;
1502
+ }
1503
+ return out;
1131
1504
  }
1505
+ /**
1506
+ * Generates a perspective projection matrix with the given field of view.
1507
+ * This is primarily useful for generating projection matrices to be used
1508
+ * with the still experiemental WebVR API.
1509
+ *
1510
+ * @param {mat4} out mat4 frustum matrix will be written into
1511
+ * @param {Object} fov Object containing the following values: upDegrees, downDegrees, leftDegrees, rightDegrees
1512
+ * @param {number} near Near bound of the frustum
1513
+ * @param {number} far Far bound of the frustum
1514
+ * @returns {mat4} out
1515
+ */
1132
1516
  export function perspectiveFromFieldOfView(out, fov, near, far) {
1133
- const upTan = Math.tan(fov.upDegrees * Math.PI / 180.0);
1134
- const downTan = Math.tan(fov.downDegrees * Math.PI / 180.0);
1135
- const leftTan = Math.tan(fov.leftDegrees * Math.PI / 180.0);
1136
- const rightTan = Math.tan(fov.rightDegrees * Math.PI / 180.0);
1137
- const xScale = 2.0 / (leftTan + rightTan);
1138
- const yScale = 2.0 / (upTan + downTan);
1139
- out[0] = xScale;
1140
- out[1] = 0.0;
1141
- out[2] = 0.0;
1142
- out[3] = 0.0;
1143
- out[4] = 0.0;
1144
- out[5] = yScale;
1145
- out[6] = 0.0;
1146
- out[7] = 0.0;
1147
- out[8] = -((leftTan - rightTan) * xScale * 0.5);
1148
- out[9] = (upTan - downTan) * yScale * 0.5;
1149
- out[10] = far / (near - far);
1150
- out[11] = -1.0;
1151
- out[12] = 0.0;
1152
- out[13] = 0.0;
1153
- out[14] = far * near / (near - far);
1154
- out[15] = 0.0;
1155
- return out;
1517
+ const upTan = Math.tan((fov.upDegrees * Math.PI) / 180.0);
1518
+ const downTan = Math.tan((fov.downDegrees * Math.PI) / 180.0);
1519
+ const leftTan = Math.tan((fov.leftDegrees * Math.PI) / 180.0);
1520
+ const rightTan = Math.tan((fov.rightDegrees * Math.PI) / 180.0);
1521
+ const xScale = 2.0 / (leftTan + rightTan);
1522
+ const yScale = 2.0 / (upTan + downTan);
1523
+ out[0] = xScale;
1524
+ out[1] = 0.0;
1525
+ out[2] = 0.0;
1526
+ out[3] = 0.0;
1527
+ out[4] = 0.0;
1528
+ out[5] = yScale;
1529
+ out[6] = 0.0;
1530
+ out[7] = 0.0;
1531
+ out[8] = -((leftTan - rightTan) * xScale * 0.5);
1532
+ out[9] = (upTan - downTan) * yScale * 0.5;
1533
+ out[10] = far / (near - far);
1534
+ out[11] = -1.0;
1535
+ out[12] = 0.0;
1536
+ out[13] = 0.0;
1537
+ out[14] = (far * near) / (near - far);
1538
+ out[15] = 0.0;
1539
+ return out;
1156
1540
  }
1541
+ /**
1542
+ * Generates a orthogonal projection matrix with the given bounds.
1543
+ * The near/far clip planes correspond to a normalized device coordinate Z range of [-1, 1],
1544
+ * which matches WebGL/OpenGL's clip volume.
1545
+ *
1546
+ * @param {mat4} out mat4 frustum matrix will be written into
1547
+ * @param {number} left Left bound of the frustum
1548
+ * @param {number} right Right bound of the frustum
1549
+ * @param {number} bottom Bottom bound of the frustum
1550
+ * @param {number} top Top bound of the frustum
1551
+ * @param {number} near Near bound of the frustum
1552
+ * @param {number} far Far bound of the frustum
1553
+ * @returns {mat4} out
1554
+ */
1157
1555
  export function orthoNO(out, left, right, bottom, top, near, far) {
1158
- const lr = 1 / (left - right);
1159
- const bt = 1 / (bottom - top);
1160
- const nf = 1 / (near - far);
1161
- out[0] = -2 * lr;
1162
- out[1] = 0;
1163
- out[2] = 0;
1164
- out[3] = 0;
1165
- out[4] = 0;
1166
- out[5] = -2 * bt;
1167
- out[6] = 0;
1168
- out[7] = 0;
1169
- out[8] = 0;
1170
- out[9] = 0;
1171
- out[10] = 2 * nf;
1172
- out[11] = 0;
1173
- out[12] = (left + right) * lr;
1174
- out[13] = (top + bottom) * bt;
1175
- out[14] = (far + near) * nf;
1176
- out[15] = 1;
1177
- return out;
1556
+ const lr = 1 / (left - right);
1557
+ const bt = 1 / (bottom - top);
1558
+ const nf = 1 / (near - far);
1559
+ out[0] = -2 * lr;
1560
+ out[1] = 0;
1561
+ out[2] = 0;
1562
+ out[3] = 0;
1563
+ out[4] = 0;
1564
+ out[5] = -2 * bt;
1565
+ out[6] = 0;
1566
+ out[7] = 0;
1567
+ out[8] = 0;
1568
+ out[9] = 0;
1569
+ out[10] = 2 * nf;
1570
+ out[11] = 0;
1571
+ out[12] = (left + right) * lr;
1572
+ out[13] = (top + bottom) * bt;
1573
+ out[14] = (far + near) * nf;
1574
+ out[15] = 1;
1575
+ return out;
1178
1576
  }
1577
+ /**
1578
+ * Alias for {@link mat4.orthoNO}
1579
+ * @function
1580
+ */
1179
1581
  export const ortho = orthoNO;
1582
+ /**
1583
+ * Generates a orthogonal projection matrix with the given bounds.
1584
+ * The near/far clip planes correspond to a normalized device coordinate Z range of [0, 1],
1585
+ * which matches WebGPU/Vulkan/DirectX/Metal's clip volume.
1586
+ *
1587
+ * @param {mat4} out mat4 frustum matrix will be written into
1588
+ * @param {number} left Left bound of the frustum
1589
+ * @param {number} right Right bound of the frustum
1590
+ * @param {number} bottom Bottom bound of the frustum
1591
+ * @param {number} top Top bound of the frustum
1592
+ * @param {number} near Near bound of the frustum
1593
+ * @param {number} far Far bound of the frustum
1594
+ * @returns {mat4} out
1595
+ */
1180
1596
  export function orthoZO(out, left, right, bottom, top, near, far) {
1181
- const lr = 1 / (left - right);
1182
- const bt = 1 / (bottom - top);
1183
- const nf = 1 / (near - far);
1184
- out[0] = -2 * lr;
1185
- out[1] = 0;
1186
- out[2] = 0;
1187
- out[3] = 0;
1188
- out[4] = 0;
1189
- out[5] = -2 * bt;
1190
- out[6] = 0;
1191
- out[7] = 0;
1192
- out[8] = 0;
1193
- out[9] = 0;
1194
- out[10] = nf;
1195
- out[11] = 0;
1196
- out[12] = (left + right) * lr;
1197
- out[13] = (top + bottom) * bt;
1198
- out[14] = near * nf;
1199
- out[15] = 1;
1200
- return out;
1597
+ const lr = 1 / (left - right);
1598
+ const bt = 1 / (bottom - top);
1599
+ const nf = 1 / (near - far);
1600
+ out[0] = -2 * lr;
1601
+ out[1] = 0;
1602
+ out[2] = 0;
1603
+ out[3] = 0;
1604
+ out[4] = 0;
1605
+ out[5] = -2 * bt;
1606
+ out[6] = 0;
1607
+ out[7] = 0;
1608
+ out[8] = 0;
1609
+ out[9] = 0;
1610
+ out[10] = nf;
1611
+ out[11] = 0;
1612
+ out[12] = (left + right) * lr;
1613
+ out[13] = (top + bottom) * bt;
1614
+ out[14] = near * nf;
1615
+ out[15] = 1;
1616
+ return out;
1201
1617
  }
1618
+ /**
1619
+ * Generates a look-at matrix with the given eye position, focal point, and up axis.
1620
+ * If you want a matrix that actually makes an object look at another object, you should use targetTo instead.
1621
+ *
1622
+ * @param {mat4} out mat4 frustum matrix will be written into
1623
+ * @param {ReadonlyVec3} eye Position of the viewer
1624
+ * @param {ReadonlyVec3} center Point the viewer is looking at
1625
+ * @param {ReadonlyVec3} up vec3 pointing up
1626
+ * @returns {mat4} out
1627
+ */
1202
1628
  export function lookAt(out, eye, center, up) {
1203
- let len;
1204
- let x0;
1205
- let x1;
1206
- let x2;
1207
- let y0;
1208
- let y1;
1209
- let y2;
1210
- let z0;
1211
- let z1;
1212
- let z2;
1213
- const eyex = eye[0];
1214
- const eyey = eye[1];
1215
- const eyez = eye[2];
1216
- const upx = up[0];
1217
- const upy = up[1];
1218
- const upz = up[2];
1219
- const centerx = center[0];
1220
- const centery = center[1];
1221
- const centerz = center[2];
1222
-
1223
- if (Math.abs(eyex - centerx) < glMatrix.EPSILON && Math.abs(eyey - centery) < glMatrix.EPSILON && Math.abs(eyez - centerz) < glMatrix.EPSILON) {
1224
- return identity(out);
1225
- }
1226
-
1227
- z0 = eyex - centerx;
1228
- z1 = eyey - centery;
1229
- z2 = eyez - centerz;
1230
- len = 1 / Math.sqrt(z0 * z0 + z1 * z1 + z2 * z2);
1231
- z0 *= len;
1232
- z1 *= len;
1233
- z2 *= len;
1234
- x0 = upy * z2 - upz * z1;
1235
- x1 = upz * z0 - upx * z2;
1236
- x2 = upx * z1 - upy * z0;
1237
- len = Math.sqrt(x0 * x0 + x1 * x1 + x2 * x2);
1238
-
1239
- if (!len) {
1240
- x0 = 0;
1241
- x1 = 0;
1242
- x2 = 0;
1243
- } else {
1244
- len = 1 / len;
1245
- x0 *= len;
1246
- x1 *= len;
1247
- x2 *= len;
1248
- }
1249
-
1250
- y0 = z1 * x2 - z2 * x1;
1251
- y1 = z2 * x0 - z0 * x2;
1252
- y2 = z0 * x1 - z1 * x0;
1253
- len = Math.sqrt(y0 * y0 + y1 * y1 + y2 * y2);
1254
-
1255
- if (!len) {
1256
- y0 = 0;
1257
- y1 = 0;
1258
- y2 = 0;
1259
- } else {
1260
- len = 1 / len;
1261
- y0 *= len;
1262
- y1 *= len;
1263
- y2 *= len;
1264
- }
1265
-
1266
- out[0] = x0;
1267
- out[1] = y0;
1268
- out[2] = z0;
1269
- out[3] = 0;
1270
- out[4] = x1;
1271
- out[5] = y1;
1272
- out[6] = z1;
1273
- out[7] = 0;
1274
- out[8] = x2;
1275
- out[9] = y2;
1276
- out[10] = z2;
1277
- out[11] = 0;
1278
- out[12] = -(x0 * eyex + x1 * eyey + x2 * eyez);
1279
- out[13] = -(y0 * eyex + y1 * eyey + y2 * eyez);
1280
- out[14] = -(z0 * eyex + z1 * eyey + z2 * eyez);
1281
- out[15] = 1;
1282
- return out;
1283
- }
1284
- export function targetTo(out, eye, target, up) {
1285
- const eyex = eye[0];
1286
- const eyey = eye[1];
1287
- const eyez = eye[2];
1288
- const upx = up[0];
1289
- const upy = up[1];
1290
- const upz = up[2];
1291
- let z0 = eyex - target[0];
1292
- let z1 = eyey - target[1];
1293
- let z2 = eyez - target[2];
1294
- let len = z0 * z0 + z1 * z1 + z2 * z2;
1295
-
1296
- if (len > 0) {
1297
- len = 1 / Math.sqrt(len);
1629
+ let len;
1630
+ let x0;
1631
+ let x1;
1632
+ let x2;
1633
+ let y0;
1634
+ let y1;
1635
+ let y2;
1636
+ let z0;
1637
+ let z1;
1638
+ let z2;
1639
+ const eyex = eye[0];
1640
+ const eyey = eye[1];
1641
+ const eyez = eye[2];
1642
+ const upx = up[0];
1643
+ const upy = up[1];
1644
+ const upz = up[2];
1645
+ const centerx = center[0];
1646
+ const centery = center[1];
1647
+ const centerz = center[2];
1648
+ if (Math.abs(eyex - centerx) < glMatrix.EPSILON &&
1649
+ Math.abs(eyey - centery) < glMatrix.EPSILON &&
1650
+ Math.abs(eyez - centerz) < glMatrix.EPSILON) {
1651
+ return identity(out);
1652
+ }
1653
+ z0 = eyex - centerx;
1654
+ z1 = eyey - centery;
1655
+ z2 = eyez - centerz;
1656
+ len = 1 / Math.sqrt(z0 * z0 + z1 * z1 + z2 * z2);
1298
1657
  z0 *= len;
1299
1658
  z1 *= len;
1300
1659
  z2 *= len;
1301
- }
1302
-
1303
- let x0 = upy * z2 - upz * z1;
1304
- let x1 = upz * z0 - upx * z2;
1305
- let x2 = upx * z1 - upy * z0;
1306
- len = x0 * x0 + x1 * x1 + x2 * x2;
1307
-
1308
- if (len > 0) {
1309
- len = 1 / Math.sqrt(len);
1310
- x0 *= len;
1311
- x1 *= len;
1312
- x2 *= len;
1313
- }
1314
-
1315
- out[0] = x0;
1316
- out[1] = x1;
1317
- out[2] = x2;
1318
- out[3] = 0;
1319
- out[4] = z1 * x2 - z2 * x1;
1320
- out[5] = z2 * x0 - z0 * x2;
1321
- out[6] = z0 * x1 - z1 * x0;
1322
- out[7] = 0;
1323
- out[8] = z0;
1324
- out[9] = z1;
1325
- out[10] = z2;
1326
- out[11] = 0;
1327
- out[12] = eyex;
1328
- out[13] = eyey;
1329
- out[14] = eyez;
1330
- out[15] = 1;
1331
- return out;
1660
+ x0 = upy * z2 - upz * z1;
1661
+ x1 = upz * z0 - upx * z2;
1662
+ x2 = upx * z1 - upy * z0;
1663
+ len = Math.sqrt(x0 * x0 + x1 * x1 + x2 * x2);
1664
+ if (!len) {
1665
+ x0 = 0;
1666
+ x1 = 0;
1667
+ x2 = 0;
1668
+ }
1669
+ else {
1670
+ len = 1 / len;
1671
+ x0 *= len;
1672
+ x1 *= len;
1673
+ x2 *= len;
1674
+ }
1675
+ y0 = z1 * x2 - z2 * x1;
1676
+ y1 = z2 * x0 - z0 * x2;
1677
+ y2 = z0 * x1 - z1 * x0;
1678
+ len = Math.sqrt(y0 * y0 + y1 * y1 + y2 * y2);
1679
+ if (!len) {
1680
+ y0 = 0;
1681
+ y1 = 0;
1682
+ y2 = 0;
1683
+ }
1684
+ else {
1685
+ len = 1 / len;
1686
+ y0 *= len;
1687
+ y1 *= len;
1688
+ y2 *= len;
1689
+ }
1690
+ out[0] = x0;
1691
+ out[1] = y0;
1692
+ out[2] = z0;
1693
+ out[3] = 0;
1694
+ out[4] = x1;
1695
+ out[5] = y1;
1696
+ out[6] = z1;
1697
+ out[7] = 0;
1698
+ out[8] = x2;
1699
+ out[9] = y2;
1700
+ out[10] = z2;
1701
+ out[11] = 0;
1702
+ out[12] = -(x0 * eyex + x1 * eyey + x2 * eyez);
1703
+ out[13] = -(y0 * eyex + y1 * eyey + y2 * eyez);
1704
+ out[14] = -(z0 * eyex + z1 * eyey + z2 * eyez);
1705
+ out[15] = 1;
1706
+ return out;
1707
+ }
1708
+ /**
1709
+ * Generates a matrix that makes something look at something else.
1710
+ *
1711
+ * @param {mat4} out mat4 frustum matrix will be written into
1712
+ * @param {ReadonlyVec3} eye Position of the viewer
1713
+ * @param {ReadonlyVec3} center Point the viewer is looking at
1714
+ * @param {ReadonlyVec3} up vec3 pointing up
1715
+ * @returns {mat4} out
1716
+ */
1717
+ export function targetTo(out, eye, target, up) {
1718
+ const eyex = eye[0];
1719
+ const eyey = eye[1];
1720
+ const eyez = eye[2];
1721
+ const upx = up[0];
1722
+ const upy = up[1];
1723
+ const upz = up[2];
1724
+ let z0 = eyex - target[0];
1725
+ let z1 = eyey - target[1];
1726
+ let z2 = eyez - target[2];
1727
+ let len = z0 * z0 + z1 * z1 + z2 * z2;
1728
+ if (len > 0) {
1729
+ len = 1 / Math.sqrt(len);
1730
+ z0 *= len;
1731
+ z1 *= len;
1732
+ z2 *= len;
1733
+ }
1734
+ let x0 = upy * z2 - upz * z1;
1735
+ let x1 = upz * z0 - upx * z2;
1736
+ let x2 = upx * z1 - upy * z0;
1737
+ len = x0 * x0 + x1 * x1 + x2 * x2;
1738
+ if (len > 0) {
1739
+ len = 1 / Math.sqrt(len);
1740
+ x0 *= len;
1741
+ x1 *= len;
1742
+ x2 *= len;
1743
+ }
1744
+ out[0] = x0;
1745
+ out[1] = x1;
1746
+ out[2] = x2;
1747
+ out[3] = 0;
1748
+ out[4] = z1 * x2 - z2 * x1;
1749
+ out[5] = z2 * x0 - z0 * x2;
1750
+ out[6] = z0 * x1 - z1 * x0;
1751
+ out[7] = 0;
1752
+ out[8] = z0;
1753
+ out[9] = z1;
1754
+ out[10] = z2;
1755
+ out[11] = 0;
1756
+ out[12] = eyex;
1757
+ out[13] = eyey;
1758
+ out[14] = eyez;
1759
+ out[15] = 1;
1760
+ return out;
1332
1761
  }
1762
+ /**
1763
+ * Returns a string representation of a mat4
1764
+ *
1765
+ * @param {ReadonlyMat4} a matrix to represent as a string
1766
+ * @returns {String} string representation of the matrix
1767
+ */
1333
1768
  export function str(a) {
1334
- return "mat4(".concat(a[0], ", ").concat(a[1], ", ").concat(a[2], ", ").concat(a[3], ", ").concat(a[4], ", ").concat(a[5], ", ").concat(a[6], ", ").concat(a[7], ", ").concat(a[8], ", ").concat(a[9], ", ").concat(a[10], ", ").concat(a[11], ", ").concat(a[12], ", ").concat(a[13], ", ").concat(a[14], ", ").concat(a[15], ")");
1769
+ return `mat4(${a[0]}, ${a[1]}, ${a[2]}, ${a[3]}, ${a[4]}, ${a[5]}, ${a[6]}, ${a[7]}, ${a[8]}, ${a[9]}, ${a[10]}, ${a[11]}, ${a[12]}, ${a[13]}, ${a[14]}, ${a[15]})`;
1335
1770
  }
1771
+ /**
1772
+ * Returns Frobenius norm of a mat4
1773
+ *
1774
+ * @param {ReadonlyMat4} a the matrix to calculate Frobenius norm of
1775
+ * @returns {Number} Frobenius norm
1776
+ */
1336
1777
  export function frob(a) {
1337
- return Math.sqrt(a[0] * a[0] + a[1] * a[1] + a[2] * a[2] + a[3] * a[3] + a[4] * a[4] + a[5] * a[5] + a[6] * a[6] + a[7] * a[7] + a[8] * a[8] + a[9] * a[9] + a[10] * a[10] + a[11] * a[11] + a[12] * a[12] + a[13] * a[13] + a[14] * a[14] + a[15] * a[15]);
1778
+ return Math.sqrt(a[0] * a[0] +
1779
+ a[1] * a[1] +
1780
+ a[2] * a[2] +
1781
+ a[3] * a[3] +
1782
+ a[4] * a[4] +
1783
+ a[5] * a[5] +
1784
+ a[6] * a[6] +
1785
+ a[7] * a[7] +
1786
+ a[8] * a[8] +
1787
+ a[9] * a[9] +
1788
+ a[10] * a[10] +
1789
+ a[11] * a[11] +
1790
+ a[12] * a[12] +
1791
+ a[13] * a[13] +
1792
+ a[14] * a[14] +
1793
+ a[15] * a[15]);
1338
1794
  }
1795
+ /**
1796
+ * Adds two mat4's
1797
+ *
1798
+ * @param {mat4} out the receiving matrix
1799
+ * @param {ReadonlyMat4} a the first operand
1800
+ * @param {ReadonlyMat4} b the second operand
1801
+ * @returns {mat4} out
1802
+ */
1339
1803
  export function add(out, a, b) {
1340
- out[0] = a[0] + b[0];
1341
- out[1] = a[1] + b[1];
1342
- out[2] = a[2] + b[2];
1343
- out[3] = a[3] + b[3];
1344
- out[4] = a[4] + b[4];
1345
- out[5] = a[5] + b[5];
1346
- out[6] = a[6] + b[6];
1347
- out[7] = a[7] + b[7];
1348
- out[8] = a[8] + b[8];
1349
- out[9] = a[9] + b[9];
1350
- out[10] = a[10] + b[10];
1351
- out[11] = a[11] + b[11];
1352
- out[12] = a[12] + b[12];
1353
- out[13] = a[13] + b[13];
1354
- out[14] = a[14] + b[14];
1355
- out[15] = a[15] + b[15];
1356
- return out;
1804
+ out[0] = a[0] + b[0];
1805
+ out[1] = a[1] + b[1];
1806
+ out[2] = a[2] + b[2];
1807
+ out[3] = a[3] + b[3];
1808
+ out[4] = a[4] + b[4];
1809
+ out[5] = a[5] + b[5];
1810
+ out[6] = a[6] + b[6];
1811
+ out[7] = a[7] + b[7];
1812
+ out[8] = a[8] + b[8];
1813
+ out[9] = a[9] + b[9];
1814
+ out[10] = a[10] + b[10];
1815
+ out[11] = a[11] + b[11];
1816
+ out[12] = a[12] + b[12];
1817
+ out[13] = a[13] + b[13];
1818
+ out[14] = a[14] + b[14];
1819
+ out[15] = a[15] + b[15];
1820
+ return out;
1357
1821
  }
1822
+ /**
1823
+ * Subtracts matrix b from matrix a
1824
+ *
1825
+ * @param {mat4} out the receiving matrix
1826
+ * @param {ReadonlyMat4} a the first operand
1827
+ * @param {ReadonlyMat4} b the second operand
1828
+ * @returns {mat4} out
1829
+ */
1358
1830
  export function subtract(out, a, b) {
1359
- out[0] = a[0] - b[0];
1360
- out[1] = a[1] - b[1];
1361
- out[2] = a[2] - b[2];
1362
- out[3] = a[3] - b[3];
1363
- out[4] = a[4] - b[4];
1364
- out[5] = a[5] - b[5];
1365
- out[6] = a[6] - b[6];
1366
- out[7] = a[7] - b[7];
1367
- out[8] = a[8] - b[8];
1368
- out[9] = a[9] - b[9];
1369
- out[10] = a[10] - b[10];
1370
- out[11] = a[11] - b[11];
1371
- out[12] = a[12] - b[12];
1372
- out[13] = a[13] - b[13];
1373
- out[14] = a[14] - b[14];
1374
- out[15] = a[15] - b[15];
1375
- return out;
1831
+ out[0] = a[0] - b[0];
1832
+ out[1] = a[1] - b[1];
1833
+ out[2] = a[2] - b[2];
1834
+ out[3] = a[3] - b[3];
1835
+ out[4] = a[4] - b[4];
1836
+ out[5] = a[5] - b[5];
1837
+ out[6] = a[6] - b[6];
1838
+ out[7] = a[7] - b[7];
1839
+ out[8] = a[8] - b[8];
1840
+ out[9] = a[9] - b[9];
1841
+ out[10] = a[10] - b[10];
1842
+ out[11] = a[11] - b[11];
1843
+ out[12] = a[12] - b[12];
1844
+ out[13] = a[13] - b[13];
1845
+ out[14] = a[14] - b[14];
1846
+ out[15] = a[15] - b[15];
1847
+ return out;
1376
1848
  }
1849
+ /**
1850
+ * Multiply each element of the matrix by a scalar.
1851
+ *
1852
+ * @param {mat4} out the receiving matrix
1853
+ * @param {ReadonlyMat4} a the matrix to scale
1854
+ * @param {Number} b amount to scale the matrix's elements by
1855
+ * @returns {mat4} out
1856
+ */
1377
1857
  export function multiplyScalar(out, a, b) {
1378
- out[0] = a[0] * b;
1379
- out[1] = a[1] * b;
1380
- out[2] = a[2] * b;
1381
- out[3] = a[3] * b;
1382
- out[4] = a[4] * b;
1383
- out[5] = a[5] * b;
1384
- out[6] = a[6] * b;
1385
- out[7] = a[7] * b;
1386
- out[8] = a[8] * b;
1387
- out[9] = a[9] * b;
1388
- out[10] = a[10] * b;
1389
- out[11] = a[11] * b;
1390
- out[12] = a[12] * b;
1391
- out[13] = a[13] * b;
1392
- out[14] = a[14] * b;
1393
- out[15] = a[15] * b;
1394
- return out;
1858
+ out[0] = a[0] * b;
1859
+ out[1] = a[1] * b;
1860
+ out[2] = a[2] * b;
1861
+ out[3] = a[3] * b;
1862
+ out[4] = a[4] * b;
1863
+ out[5] = a[5] * b;
1864
+ out[6] = a[6] * b;
1865
+ out[7] = a[7] * b;
1866
+ out[8] = a[8] * b;
1867
+ out[9] = a[9] * b;
1868
+ out[10] = a[10] * b;
1869
+ out[11] = a[11] * b;
1870
+ out[12] = a[12] * b;
1871
+ out[13] = a[13] * b;
1872
+ out[14] = a[14] * b;
1873
+ out[15] = a[15] * b;
1874
+ return out;
1395
1875
  }
1876
+ /**
1877
+ * Adds two mat4's after multiplying each element of the second operand by a scalar value.
1878
+ *
1879
+ * @param {mat4} out the receiving vector
1880
+ * @param {ReadonlyMat4} a the first operand
1881
+ * @param {ReadonlyMat4} b the second operand
1882
+ * @param {Number} scale the amount to scale b's elements by before adding
1883
+ * @returns {mat4} out
1884
+ */
1396
1885
  export function multiplyScalarAndAdd(out, a, b, scale) {
1397
- out[0] = a[0] + b[0] * scale;
1398
- out[1] = a[1] + b[1] * scale;
1399
- out[2] = a[2] + b[2] * scale;
1400
- out[3] = a[3] + b[3] * scale;
1401
- out[4] = a[4] + b[4] * scale;
1402
- out[5] = a[5] + b[5] * scale;
1403
- out[6] = a[6] + b[6] * scale;
1404
- out[7] = a[7] + b[7] * scale;
1405
- out[8] = a[8] + b[8] * scale;
1406
- out[9] = a[9] + b[9] * scale;
1407
- out[10] = a[10] + b[10] * scale;
1408
- out[11] = a[11] + b[11] * scale;
1409
- out[12] = a[12] + b[12] * scale;
1410
- out[13] = a[13] + b[13] * scale;
1411
- out[14] = a[14] + b[14] * scale;
1412
- out[15] = a[15] + b[15] * scale;
1413
- return out;
1886
+ out[0] = a[0] + b[0] * scale;
1887
+ out[1] = a[1] + b[1] * scale;
1888
+ out[2] = a[2] + b[2] * scale;
1889
+ out[3] = a[3] + b[3] * scale;
1890
+ out[4] = a[4] + b[4] * scale;
1891
+ out[5] = a[5] + b[5] * scale;
1892
+ out[6] = a[6] + b[6] * scale;
1893
+ out[7] = a[7] + b[7] * scale;
1894
+ out[8] = a[8] + b[8] * scale;
1895
+ out[9] = a[9] + b[9] * scale;
1896
+ out[10] = a[10] + b[10] * scale;
1897
+ out[11] = a[11] + b[11] * scale;
1898
+ out[12] = a[12] + b[12] * scale;
1899
+ out[13] = a[13] + b[13] * scale;
1900
+ out[14] = a[14] + b[14] * scale;
1901
+ out[15] = a[15] + b[15] * scale;
1902
+ return out;
1414
1903
  }
1904
+ /**
1905
+ * Returns whether or not the matrices have exactly the same elements in the same position (when compared with ===)
1906
+ *
1907
+ * @param {ReadonlyMat4} a The first matrix.
1908
+ * @param {ReadonlyMat4} b The second matrix.
1909
+ * @returns {Boolean} True if the matrices are equal, false otherwise.
1910
+ */
1415
1911
  export function exactEquals(a, b) {
1416
- return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3] && a[4] === b[4] && a[5] === b[5] && a[6] === b[6] && a[7] === b[7] && a[8] === b[8] && a[9] === b[9] && a[10] === b[10] && a[11] === b[11] && a[12] === b[12] && a[13] === b[13] && a[14] === b[14] && a[15] === b[15];
1912
+ return (a[0] === b[0] &&
1913
+ a[1] === b[1] &&
1914
+ a[2] === b[2] &&
1915
+ a[3] === b[3] &&
1916
+ a[4] === b[4] &&
1917
+ a[5] === b[5] &&
1918
+ a[6] === b[6] &&
1919
+ a[7] === b[7] &&
1920
+ a[8] === b[8] &&
1921
+ a[9] === b[9] &&
1922
+ a[10] === b[10] &&
1923
+ a[11] === b[11] &&
1924
+ a[12] === b[12] &&
1925
+ a[13] === b[13] &&
1926
+ a[14] === b[14] &&
1927
+ a[15] === b[15]);
1417
1928
  }
1929
+ /**
1930
+ * Returns whether or not the matrices have approximately the same elements in the same position.
1931
+ *
1932
+ * @param {ReadonlyMat4} a The first matrix.
1933
+ * @param {ReadonlyMat4} b The second matrix.
1934
+ * @returns {Boolean} True if the matrices are equal, false otherwise.
1935
+ */
1418
1936
  export function equals(a, b) {
1419
- const a0 = a[0];
1420
- const a1 = a[1];
1421
- const a2 = a[2];
1422
- const a3 = a[3];
1423
- const a4 = a[4];
1424
- const a5 = a[5];
1425
- const a6 = a[6];
1426
- const a7 = a[7];
1427
- const a8 = a[8];
1428
- const a9 = a[9];
1429
- const a10 = a[10];
1430
- const a11 = a[11];
1431
- const a12 = a[12];
1432
- const a13 = a[13];
1433
- const a14 = a[14];
1434
- const a15 = a[15];
1435
- const b0 = b[0];
1436
- const b1 = b[1];
1437
- const b2 = b[2];
1438
- const b3 = b[3];
1439
- const b4 = b[4];
1440
- const b5 = b[5];
1441
- const b6 = b[6];
1442
- const b7 = b[7];
1443
- const b8 = b[8];
1444
- const b9 = b[9];
1445
- const b10 = b[10];
1446
- const b11 = b[11];
1447
- const b12 = b[12];
1448
- const b13 = b[13];
1449
- const b14 = b[14];
1450
- const b15 = b[15];
1451
- return Math.abs(a0 - b0) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) && Math.abs(a1 - b1) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1)) && Math.abs(a2 - b2) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a2), Math.abs(b2)) && Math.abs(a3 - b3) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a3), Math.abs(b3)) && Math.abs(a4 - b4) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a4), Math.abs(b4)) && Math.abs(a5 - b5) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a5), Math.abs(b5)) && Math.abs(a6 - b6) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a6), Math.abs(b6)) && Math.abs(a7 - b7) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a7), Math.abs(b7)) && Math.abs(a8 - b8) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a8), Math.abs(b8)) && Math.abs(a9 - b9) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a9), Math.abs(b9)) && Math.abs(a10 - b10) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a10), Math.abs(b10)) && Math.abs(a11 - b11) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a11), Math.abs(b11)) && Math.abs(a12 - b12) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a12), Math.abs(b12)) && Math.abs(a13 - b13) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a13), Math.abs(b13)) && Math.abs(a14 - b14) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a14), Math.abs(b14)) && Math.abs(a15 - b15) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a15), Math.abs(b15));
1937
+ const a0 = a[0];
1938
+ const a1 = a[1];
1939
+ const a2 = a[2];
1940
+ const a3 = a[3];
1941
+ const a4 = a[4];
1942
+ const a5 = a[5];
1943
+ const a6 = a[6];
1944
+ const a7 = a[7];
1945
+ const a8 = a[8];
1946
+ const a9 = a[9];
1947
+ const a10 = a[10];
1948
+ const a11 = a[11];
1949
+ const a12 = a[12];
1950
+ const a13 = a[13];
1951
+ const a14 = a[14];
1952
+ const a15 = a[15];
1953
+ const b0 = b[0];
1954
+ const b1 = b[1];
1955
+ const b2 = b[2];
1956
+ const b3 = b[3];
1957
+ const b4 = b[4];
1958
+ const b5 = b[5];
1959
+ const b6 = b[6];
1960
+ const b7 = b[7];
1961
+ const b8 = b[8];
1962
+ const b9 = b[9];
1963
+ const b10 = b[10];
1964
+ const b11 = b[11];
1965
+ const b12 = b[12];
1966
+ const b13 = b[13];
1967
+ const b14 = b[14];
1968
+ const b15 = b[15];
1969
+ return (Math.abs(a0 - b0) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a0), Math.abs(b0)) &&
1970
+ Math.abs(a1 - b1) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a1), Math.abs(b1)) &&
1971
+ Math.abs(a2 - b2) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a2), Math.abs(b2)) &&
1972
+ Math.abs(a3 - b3) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a3), Math.abs(b3)) &&
1973
+ Math.abs(a4 - b4) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a4), Math.abs(b4)) &&
1974
+ Math.abs(a5 - b5) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a5), Math.abs(b5)) &&
1975
+ Math.abs(a6 - b6) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a6), Math.abs(b6)) &&
1976
+ Math.abs(a7 - b7) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a7), Math.abs(b7)) &&
1977
+ Math.abs(a8 - b8) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a8), Math.abs(b8)) &&
1978
+ Math.abs(a9 - b9) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a9), Math.abs(b9)) &&
1979
+ Math.abs(a10 - b10) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a10), Math.abs(b10)) &&
1980
+ Math.abs(a11 - b11) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a11), Math.abs(b11)) &&
1981
+ Math.abs(a12 - b12) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a12), Math.abs(b12)) &&
1982
+ Math.abs(a13 - b13) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a13), Math.abs(b13)) &&
1983
+ Math.abs(a14 - b14) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a14), Math.abs(b14)) &&
1984
+ Math.abs(a15 - b15) <= glMatrix.EPSILON * Math.max(1.0, Math.abs(a15), Math.abs(b15)));
1452
1985
  }
1986
+ /**
1987
+ * Alias for {@link mat4.multiply}
1988
+ * @function
1989
+ */
1453
1990
  export const mul = multiply;
1991
+ /**
1992
+ * Alias for {@link mat4.subtract}
1993
+ * @function
1994
+ */
1454
1995
  export const sub = subtract;
1455
- //# sourceMappingURL=mat4.js.map