@math.gl/core 3.6.3 → 4.0.0-alpha.2

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