@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.
- package/dist/classes/base/math-array.d.ts +1 -2
- package/dist/classes/base/math-array.js +220 -266
- package/dist/classes/base/matrix.d.ts +1 -2
- package/dist/classes/base/matrix.js +52 -53
- package/dist/classes/base/vector.d.ts +1 -2
- package/dist/classes/base/vector.js +121 -135
- package/dist/classes/euler.d.ts +2 -3
- package/dist/classes/euler.js +462 -533
- package/dist/classes/matrix3.d.ts +2 -3
- package/dist/classes/matrix3.js +185 -190
- package/dist/classes/matrix4.d.ts +1 -2
- package/dist/classes/matrix4.js +516 -452
- package/dist/classes/pose.d.ts +4 -5
- package/dist/classes/pose.js +104 -119
- package/dist/classes/quaternion.d.ts +1 -2
- package/dist/classes/quaternion.js +257 -233
- package/dist/classes/spherical-coordinates.d.ts +3 -4
- package/dist/classes/spherical-coordinates.js +138 -147
- package/dist/classes/vector2.d.ts +1 -2
- package/dist/classes/vector2.js +101 -85
- package/dist/classes/vector3.d.ts +1 -2
- package/dist/classes/vector3.js +125 -136
- package/dist/classes/vector4.d.ts +2 -3
- package/dist/classes/vector4.js +106 -114
- package/dist/gl-matrix/common.d.ts +0 -1
- package/dist/gl-matrix/common.js +38 -6
- package/dist/gl-matrix/mat3.d.ts +0 -1
- package/dist/gl-matrix/mat3.js +699 -425
- package/dist/gl-matrix/mat4.d.ts +0 -1
- package/dist/gl-matrix/mat4.js +1879 -1339
- package/dist/gl-matrix/quat.d.ts +0 -1
- package/dist/gl-matrix/quat.js +655 -257
- package/dist/gl-matrix/vec2.d.ts +0 -1
- package/dist/gl-matrix/vec2.js +529 -212
- package/dist/gl-matrix/vec3.d.ts +0 -1
- package/dist/gl-matrix/vec3.js +703 -335
- package/dist/gl-matrix/vec4.d.ts +0 -1
- package/dist/gl-matrix/vec4.js +579 -293
- package/dist/gl-matrix/wip/index.d.ts +3 -4
- package/dist/gl-matrix/wip/index.js +2 -1
- package/dist/gl-matrix/wip/mat2.d.ts +0 -1
- package/dist/gl-matrix/wip/mat2.js +333 -157
- package/dist/gl-matrix/wip/mat2d.d.ts +0 -1
- package/dist/gl-matrix/wip/mat2d.js +377 -202
- package/dist/gl-matrix/wip/quat2.d.ts +0 -1
- package/dist/gl-matrix/wip/quat2.js +647 -409
- package/dist/index.cjs +60 -100
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +21 -22
- package/dist/index.js +23 -16
- package/dist/lib/assert.d.ts +0 -1
- package/dist/lib/assert.js +3 -4
- package/dist/lib/common.d.ts +2 -3
- package/dist/lib/common.js +163 -134
- package/dist/lib/gl-matrix-extras.d.ts +0 -1
- package/dist/lib/gl-matrix-extras.js +39 -36
- package/dist/lib/math-utils.d.ts +0 -1
- package/dist/lib/math-utils.js +2 -1
- package/dist/lib/validators.d.ts +0 -1
- package/dist/lib/validators.js +22 -25
- package/package.json +5 -6
- package/src/classes/matrix3.ts +1 -1
- package/dist/classes/base/math-array.d.ts.map +0 -1
- package/dist/classes/base/math-array.js.map +0 -1
- package/dist/classes/base/matrix.d.ts.map +0 -1
- package/dist/classes/base/matrix.js.map +0 -1
- package/dist/classes/base/vector.d.ts.map +0 -1
- package/dist/classes/base/vector.js.map +0 -1
- package/dist/classes/euler.d.ts.map +0 -1
- package/dist/classes/euler.js.map +0 -1
- package/dist/classes/matrix3.d.ts.map +0 -1
- package/dist/classes/matrix3.js.map +0 -1
- package/dist/classes/matrix4.d.ts.map +0 -1
- package/dist/classes/matrix4.js.map +0 -1
- package/dist/classes/pose.d.ts.map +0 -1
- package/dist/classes/pose.js.map +0 -1
- package/dist/classes/quaternion.d.ts.map +0 -1
- package/dist/classes/quaternion.js.map +0 -1
- package/dist/classes/spherical-coordinates.d.ts.map +0 -1
- package/dist/classes/spherical-coordinates.js.map +0 -1
- package/dist/classes/vector2.d.ts.map +0 -1
- package/dist/classes/vector2.js.map +0 -1
- package/dist/classes/vector3.d.ts.map +0 -1
- package/dist/classes/vector3.js.map +0 -1
- package/dist/classes/vector4.d.ts.map +0 -1
- package/dist/classes/vector4.js.map +0 -1
- package/dist/gl-matrix/common.d.ts.map +0 -1
- package/dist/gl-matrix/common.js.map +0 -1
- package/dist/gl-matrix/mat3.d.ts.map +0 -1
- package/dist/gl-matrix/mat3.js.map +0 -1
- package/dist/gl-matrix/mat4.d.ts.map +0 -1
- package/dist/gl-matrix/mat4.js.map +0 -1
- package/dist/gl-matrix/quat.d.ts.map +0 -1
- package/dist/gl-matrix/quat.js.map +0 -1
- package/dist/gl-matrix/vec2.d.ts.map +0 -1
- package/dist/gl-matrix/vec2.js.map +0 -1
- package/dist/gl-matrix/vec3.d.ts.map +0 -1
- package/dist/gl-matrix/vec3.js.map +0 -1
- package/dist/gl-matrix/vec4.d.ts.map +0 -1
- package/dist/gl-matrix/vec4.js.map +0 -1
- package/dist/gl-matrix/wip/index.d.ts.map +0 -1
- package/dist/gl-matrix/wip/index.js.map +0 -1
- package/dist/gl-matrix/wip/mat2.d.ts.map +0 -1
- package/dist/gl-matrix/wip/mat2.js.map +0 -1
- package/dist/gl-matrix/wip/mat2d.d.ts.map +0 -1
- package/dist/gl-matrix/wip/mat2d.js.map +0 -1
- package/dist/gl-matrix/wip/quat2.d.ts.map +0 -1
- package/dist/gl-matrix/wip/quat2.js.map +0 -1
- package/dist/gl-matrix/wip/types.d.js +0 -2
- package/dist/gl-matrix/wip/types.d.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/assert.d.ts.map +0 -1
- package/dist/lib/assert.js.map +0 -1
- package/dist/lib/common.d.ts.map +0 -1
- package/dist/lib/common.js.map +0 -1
- package/dist/lib/gl-matrix-extras.d.ts.map +0 -1
- package/dist/lib/gl-matrix-extras.js.map +0 -1
- package/dist/lib/gl-matrix.d.js +0 -2
- package/dist/lib/gl-matrix.d.js.map +0 -1
- package/dist/lib/math-utils.d.ts.map +0 -1
- package/dist/lib/math-utils.js.map +0 -1
- package/dist/lib/validators.d.ts.map +0 -1
- package/dist/lib/validators.js.map +0 -1
package/dist/classes/matrix4.js
CHANGED
|
@@ -1,478 +1,542 @@
|
|
|
1
|
+
// Copyright (c) 2017 Uber Technologies, Inc.
|
|
2
|
+
// MIT License
|
|
1
3
|
import { Matrix } from "./base/matrix.js";
|
|
2
4
|
import { checkVector } from "../lib/validators.js";
|
|
5
|
+
/* eslint-disable camelcase */
|
|
3
6
|
import { vec2_transformMat4AsVector, vec3_transformMat4AsVector } from "../lib/gl-matrix-extras.js";
|
|
7
|
+
// @ts-ignore gl-matrix types...
|
|
4
8
|
import { fromQuat as mat4_fromQuat, frustum as mat4_frustum, lookAt as mat4_lookAt, ortho as mat4_ortho, perspective as mat4_perspective, determinant as mat4_determinant, transpose as mat4_transpose, invert as mat4_invert, multiply as mat4_multiply, rotateX as mat4_rotateX, rotateY as mat4_rotateY, rotateZ as mat4_rotateZ, rotate as mat4_rotate, scale as mat4_scale, translate as mat4_translate } from "../gl-matrix/mat4.js";
|
|
5
9
|
import { transformMat4 as vec2_transformMat4 } from "../gl-matrix/vec2.js";
|
|
6
10
|
import { transformMat4 as vec3_transformMat4 } from "../gl-matrix/vec3.js";
|
|
7
11
|
import { transformMat4 as vec4_transformMat4 } from "../gl-matrix/vec4.js";
|
|
8
12
|
var INDICES;
|
|
9
|
-
|
|
10
13
|
(function (INDICES) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
14
|
+
INDICES[INDICES["COL0ROW0"] = 0] = "COL0ROW0";
|
|
15
|
+
INDICES[INDICES["COL0ROW1"] = 1] = "COL0ROW1";
|
|
16
|
+
INDICES[INDICES["COL0ROW2"] = 2] = "COL0ROW2";
|
|
17
|
+
INDICES[INDICES["COL0ROW3"] = 3] = "COL0ROW3";
|
|
18
|
+
INDICES[INDICES["COL1ROW0"] = 4] = "COL1ROW0";
|
|
19
|
+
INDICES[INDICES["COL1ROW1"] = 5] = "COL1ROW1";
|
|
20
|
+
INDICES[INDICES["COL1ROW2"] = 6] = "COL1ROW2";
|
|
21
|
+
INDICES[INDICES["COL1ROW3"] = 7] = "COL1ROW3";
|
|
22
|
+
INDICES[INDICES["COL2ROW0"] = 8] = "COL2ROW0";
|
|
23
|
+
INDICES[INDICES["COL2ROW1"] = 9] = "COL2ROW1";
|
|
24
|
+
INDICES[INDICES["COL2ROW2"] = 10] = "COL2ROW2";
|
|
25
|
+
INDICES[INDICES["COL2ROW3"] = 11] = "COL2ROW3";
|
|
26
|
+
INDICES[INDICES["COL3ROW0"] = 12] = "COL3ROW0";
|
|
27
|
+
INDICES[INDICES["COL3ROW1"] = 13] = "COL3ROW1";
|
|
28
|
+
INDICES[INDICES["COL3ROW2"] = 14] = "COL3ROW2";
|
|
29
|
+
INDICES[INDICES["COL3ROW3"] = 15] = "COL3ROW3";
|
|
27
30
|
})(INDICES || (INDICES = {}));
|
|
28
|
-
|
|
29
|
-
const DEFAULT_FOVY = 45 * Math.PI / 180;
|
|
31
|
+
const DEFAULT_FOVY = (45 * Math.PI) / 180;
|
|
30
32
|
const DEFAULT_ASPECT = 1;
|
|
31
33
|
const DEFAULT_NEAR = 0.1;
|
|
32
34
|
const DEFAULT_FAR = 500;
|
|
33
35
|
const IDENTITY_MATRIX = Object.freeze([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
|
|
36
|
+
/** 4x4 matrix */
|
|
34
37
|
export class Matrix4 extends Matrix {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
result
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
result
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
38
|
+
static get IDENTITY() {
|
|
39
|
+
return getIdentityMatrix();
|
|
40
|
+
}
|
|
41
|
+
static get ZERO() {
|
|
42
|
+
return getZeroMatrix();
|
|
43
|
+
}
|
|
44
|
+
get ELEMENTS() {
|
|
45
|
+
return 16;
|
|
46
|
+
}
|
|
47
|
+
get RANK() {
|
|
48
|
+
return 4;
|
|
49
|
+
}
|
|
50
|
+
get INDICES() {
|
|
51
|
+
return INDICES;
|
|
52
|
+
}
|
|
53
|
+
constructor(array) {
|
|
54
|
+
// PERF NOTE: initialize elements as double precision numbers
|
|
55
|
+
super(-0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0);
|
|
56
|
+
if (arguments.length === 1 && Array.isArray(array)) {
|
|
57
|
+
this.copy(array);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
this.identity();
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
copy(array) {
|
|
64
|
+
this[0] = array[0];
|
|
65
|
+
this[1] = array[1];
|
|
66
|
+
this[2] = array[2];
|
|
67
|
+
this[3] = array[3];
|
|
68
|
+
this[4] = array[4];
|
|
69
|
+
this[5] = array[5];
|
|
70
|
+
this[6] = array[6];
|
|
71
|
+
this[7] = array[7];
|
|
72
|
+
this[8] = array[8];
|
|
73
|
+
this[9] = array[9];
|
|
74
|
+
this[10] = array[10];
|
|
75
|
+
this[11] = array[11];
|
|
76
|
+
this[12] = array[12];
|
|
77
|
+
this[13] = array[13];
|
|
78
|
+
this[14] = array[14];
|
|
79
|
+
this[15] = array[15];
|
|
80
|
+
return this.check();
|
|
81
|
+
}
|
|
82
|
+
// eslint-disable-next-line max-params
|
|
83
|
+
set(m00, m10, m20, m30, m01, m11, m21, m31, m02, m12, m22, m32, m03, m13, m23, m33) {
|
|
84
|
+
this[0] = m00;
|
|
85
|
+
this[1] = m10;
|
|
86
|
+
this[2] = m20;
|
|
87
|
+
this[3] = m30;
|
|
88
|
+
this[4] = m01;
|
|
89
|
+
this[5] = m11;
|
|
90
|
+
this[6] = m21;
|
|
91
|
+
this[7] = m31;
|
|
92
|
+
this[8] = m02;
|
|
93
|
+
this[9] = m12;
|
|
94
|
+
this[10] = m22;
|
|
95
|
+
this[11] = m32;
|
|
96
|
+
this[12] = m03;
|
|
97
|
+
this[13] = m13;
|
|
98
|
+
this[14] = m23;
|
|
99
|
+
this[15] = m33;
|
|
100
|
+
return this.check();
|
|
101
|
+
}
|
|
102
|
+
// accepts row major order, stores as column major
|
|
103
|
+
// eslint-disable-next-line max-params
|
|
104
|
+
setRowMajor(m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33) {
|
|
105
|
+
this[0] = m00;
|
|
106
|
+
this[1] = m10;
|
|
107
|
+
this[2] = m20;
|
|
108
|
+
this[3] = m30;
|
|
109
|
+
this[4] = m01;
|
|
110
|
+
this[5] = m11;
|
|
111
|
+
this[6] = m21;
|
|
112
|
+
this[7] = m31;
|
|
113
|
+
this[8] = m02;
|
|
114
|
+
this[9] = m12;
|
|
115
|
+
this[10] = m22;
|
|
116
|
+
this[11] = m32;
|
|
117
|
+
this[12] = m03;
|
|
118
|
+
this[13] = m13;
|
|
119
|
+
this[14] = m23;
|
|
120
|
+
this[15] = m33;
|
|
121
|
+
return this.check();
|
|
122
|
+
}
|
|
123
|
+
toRowMajor(result) {
|
|
124
|
+
result[0] = this[0];
|
|
125
|
+
result[1] = this[4];
|
|
126
|
+
result[2] = this[8];
|
|
127
|
+
result[3] = this[12];
|
|
128
|
+
result[4] = this[1];
|
|
129
|
+
result[5] = this[5];
|
|
130
|
+
result[6] = this[9];
|
|
131
|
+
result[7] = this[13];
|
|
132
|
+
result[8] = this[2];
|
|
133
|
+
result[9] = this[6];
|
|
134
|
+
result[10] = this[10];
|
|
135
|
+
result[11] = this[14];
|
|
136
|
+
result[12] = this[3];
|
|
137
|
+
result[13] = this[7];
|
|
138
|
+
result[14] = this[11];
|
|
139
|
+
result[15] = this[15];
|
|
140
|
+
return result;
|
|
141
|
+
}
|
|
142
|
+
// Constructors
|
|
143
|
+
/** Set to identity matrix */
|
|
144
|
+
identity() {
|
|
145
|
+
return this.copy(IDENTITY_MATRIX);
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
*
|
|
149
|
+
* @param object
|
|
150
|
+
* @returns self
|
|
151
|
+
*/
|
|
152
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
153
|
+
fromObject(object) {
|
|
154
|
+
return this.check();
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Calculates a 4x4 matrix from the given quaternion
|
|
158
|
+
* @param quaternion Quaternion to create matrix from
|
|
159
|
+
* @returns self
|
|
160
|
+
*/
|
|
161
|
+
fromQuaternion(quaternion) {
|
|
162
|
+
mat4_fromQuat(this, quaternion);
|
|
163
|
+
return this.check();
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Generates a frustum matrix with the given bounds
|
|
167
|
+
* @param view.left - Left bound of the frustum
|
|
168
|
+
* @param view.right - Right bound of the frustum
|
|
169
|
+
* @param view.bottom - Bottom bound of the frustum
|
|
170
|
+
* @param view.top - Top bound of the frustum
|
|
171
|
+
* @param view.near - Near bound of the frustum
|
|
172
|
+
* @param view.far - Far bound of the frustum. Can be set to Infinity.
|
|
173
|
+
* @returns self
|
|
174
|
+
*/
|
|
175
|
+
frustum(view) {
|
|
176
|
+
const { left, right, bottom, top, near = DEFAULT_NEAR, far = DEFAULT_FAR } = view;
|
|
177
|
+
if (far === Infinity) {
|
|
178
|
+
computeInfinitePerspectiveOffCenter(this, left, right, bottom, top, near);
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
mat4_frustum(this, left, right, bottom, top, near, far);
|
|
182
|
+
}
|
|
183
|
+
return this.check();
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Generates a look-at matrix with the given eye position, focal point,
|
|
187
|
+
* and up axis
|
|
188
|
+
* @param view.eye - (vector) Position of the viewer
|
|
189
|
+
* @param view.center - (vector) Point the viewer is looking at
|
|
190
|
+
* @param view.up - (vector) Up axis
|
|
191
|
+
* @returns self
|
|
192
|
+
*/
|
|
193
|
+
lookAt(view) {
|
|
194
|
+
const { eye, center = [0, 0, 0], up = [0, 1, 0] } = view;
|
|
195
|
+
mat4_lookAt(this, eye, center, up);
|
|
196
|
+
return this.check();
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Generates a orthogonal projection matrix with the given bounds
|
|
200
|
+
* from "traditional" view space parameters
|
|
201
|
+
* @param view.left - Left bound of the frustum
|
|
202
|
+
* @param view.right number Right bound of the frustum
|
|
203
|
+
* @param view.bottom - Bottom bound of the frustum
|
|
204
|
+
* @param view.top number Top bound of the frustum
|
|
205
|
+
* @param view.near - Near bound of the frustum
|
|
206
|
+
* @param view.far number Far bound of the frustum
|
|
207
|
+
* @returns self
|
|
208
|
+
*/
|
|
209
|
+
ortho(view) {
|
|
210
|
+
const { left, right, bottom, top, near = DEFAULT_NEAR, far = DEFAULT_FAR } = view;
|
|
211
|
+
mat4_ortho(this, left, right, bottom, top, near, far);
|
|
212
|
+
return this.check();
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Generates an orthogonal projection matrix with the same parameters
|
|
216
|
+
* as a perspective matrix (plus focalDistance)
|
|
217
|
+
* @param view.fovy Vertical field of view in radians
|
|
218
|
+
* @param view.aspect Aspect ratio. Typically viewport width / viewport height
|
|
219
|
+
* @param view.focalDistance Distance in the view frustum used for extent calculations
|
|
220
|
+
* @param view.near Near bound of the frustum
|
|
221
|
+
* @param view.far Far bound of the frustum
|
|
222
|
+
* @returns self
|
|
223
|
+
*/
|
|
224
|
+
orthographic(view) {
|
|
225
|
+
const { fovy = DEFAULT_FOVY, aspect = DEFAULT_ASPECT, focalDistance = 1, near = DEFAULT_NEAR, far = DEFAULT_FAR } = view;
|
|
226
|
+
checkRadians(fovy);
|
|
227
|
+
const halfY = fovy / 2;
|
|
228
|
+
const top = focalDistance * Math.tan(halfY); // focus_plane is the distance from the camera
|
|
229
|
+
const right = top * aspect;
|
|
230
|
+
return this.ortho({
|
|
231
|
+
left: -right,
|
|
232
|
+
right,
|
|
233
|
+
bottom: -top,
|
|
234
|
+
top,
|
|
235
|
+
near,
|
|
236
|
+
far
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Generates a perspective projection matrix with the given bounds
|
|
241
|
+
* @param view.fovy Vertical field of view in radians
|
|
242
|
+
* @param view.aspect Aspect ratio. typically viewport width/height
|
|
243
|
+
* @param view.near Near bound of the frustum
|
|
244
|
+
* @param view.far Far bound of the frustum
|
|
245
|
+
* @returns self
|
|
246
|
+
*/
|
|
247
|
+
perspective(view) {
|
|
248
|
+
const { fovy = (45 * Math.PI) / 180, aspect = 1, near = 0.1, far = 500 } = view;
|
|
249
|
+
checkRadians(fovy);
|
|
250
|
+
mat4_perspective(this, fovy, aspect, near, far);
|
|
251
|
+
return this.check();
|
|
252
|
+
}
|
|
253
|
+
// Accessors
|
|
254
|
+
determinant() {
|
|
255
|
+
return mat4_determinant(this);
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Extracts the non-uniform scale assuming the matrix is an affine transformation.
|
|
259
|
+
* The scales are the "lengths" of the column vectors in the upper-left 3x3 matrix.
|
|
260
|
+
* @param result
|
|
261
|
+
* @returns self
|
|
262
|
+
*/
|
|
263
|
+
getScale(result = [-0, -0, -0]) {
|
|
264
|
+
// explicit is faster than hypot...
|
|
265
|
+
result[0] = Math.sqrt(this[0] * this[0] + this[1] * this[1] + this[2] * this[2]);
|
|
266
|
+
result[1] = Math.sqrt(this[4] * this[4] + this[5] * this[5] + this[6] * this[6]);
|
|
267
|
+
result[2] = Math.sqrt(this[8] * this[8] + this[9] * this[9] + this[10] * this[10]);
|
|
268
|
+
// result[0] = Math.hypot(this[0], this[1], this[2]);
|
|
269
|
+
// result[1] = Math.hypot(this[4], this[5], this[6]);
|
|
270
|
+
// result[2] = Math.hypot(this[8], this[9], this[10]);
|
|
271
|
+
return result;
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Gets the translation portion, assuming the matrix is a affine transformation matrix.
|
|
275
|
+
* @param result
|
|
276
|
+
* @returns self
|
|
277
|
+
*/
|
|
278
|
+
getTranslation(result = [-0, -0, -0]) {
|
|
279
|
+
result[0] = this[12];
|
|
280
|
+
result[1] = this[13];
|
|
281
|
+
result[2] = this[14];
|
|
282
|
+
return result;
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Gets upper left 3x3 pure rotation matrix (non-scaling), assume affine transformation matrix
|
|
286
|
+
* @param result
|
|
287
|
+
* @param scaleResult
|
|
288
|
+
* @returns self
|
|
289
|
+
*/
|
|
290
|
+
getRotation(result, scaleResult) {
|
|
291
|
+
result = result || [-0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0];
|
|
292
|
+
scaleResult = scaleResult || [-0, -0, -0];
|
|
293
|
+
const scale = this.getScale(scaleResult);
|
|
294
|
+
const inverseScale0 = 1 / scale[0];
|
|
295
|
+
const inverseScale1 = 1 / scale[1];
|
|
296
|
+
const inverseScale2 = 1 / scale[2];
|
|
297
|
+
result[0] = this[0] * inverseScale0;
|
|
298
|
+
result[1] = this[1] * inverseScale1;
|
|
299
|
+
result[2] = this[2] * inverseScale2;
|
|
300
|
+
result[3] = 0;
|
|
301
|
+
result[4] = this[4] * inverseScale0;
|
|
302
|
+
result[5] = this[5] * inverseScale1;
|
|
303
|
+
result[6] = this[6] * inverseScale2;
|
|
304
|
+
result[7] = 0;
|
|
305
|
+
result[8] = this[8] * inverseScale0;
|
|
306
|
+
result[9] = this[9] * inverseScale1;
|
|
307
|
+
result[10] = this[10] * inverseScale2;
|
|
308
|
+
result[11] = 0;
|
|
309
|
+
result[12] = 0;
|
|
310
|
+
result[13] = 0;
|
|
311
|
+
result[14] = 0;
|
|
312
|
+
result[15] = 1;
|
|
313
|
+
return result;
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
*
|
|
317
|
+
* @param result
|
|
318
|
+
* @param scaleResult
|
|
319
|
+
* @returns self
|
|
320
|
+
*/
|
|
321
|
+
getRotationMatrix3(result, scaleResult) {
|
|
322
|
+
result = result || [-0, -0, -0, -0, -0, -0, -0, -0, -0];
|
|
323
|
+
scaleResult = scaleResult || [-0, -0, -0];
|
|
324
|
+
const scale = this.getScale(scaleResult);
|
|
325
|
+
const inverseScale0 = 1 / scale[0];
|
|
326
|
+
const inverseScale1 = 1 / scale[1];
|
|
327
|
+
const inverseScale2 = 1 / scale[2];
|
|
328
|
+
result[0] = this[0] * inverseScale0;
|
|
329
|
+
result[1] = this[1] * inverseScale1;
|
|
330
|
+
result[2] = this[2] * inverseScale2;
|
|
331
|
+
result[3] = this[4] * inverseScale0;
|
|
332
|
+
result[4] = this[5] * inverseScale1;
|
|
333
|
+
result[5] = this[6] * inverseScale2;
|
|
334
|
+
result[6] = this[8] * inverseScale0;
|
|
335
|
+
result[7] = this[9] * inverseScale1;
|
|
336
|
+
result[8] = this[10] * inverseScale2;
|
|
337
|
+
return result;
|
|
338
|
+
}
|
|
339
|
+
// Modifiers
|
|
340
|
+
transpose() {
|
|
341
|
+
mat4_transpose(this, this);
|
|
342
|
+
return this.check();
|
|
343
|
+
}
|
|
344
|
+
invert() {
|
|
345
|
+
mat4_invert(this, this);
|
|
346
|
+
return this.check();
|
|
347
|
+
}
|
|
348
|
+
// Operations
|
|
349
|
+
multiplyLeft(a) {
|
|
350
|
+
mat4_multiply(this, a, this);
|
|
351
|
+
return this.check();
|
|
352
|
+
}
|
|
353
|
+
multiplyRight(a) {
|
|
354
|
+
mat4_multiply(this, this, a);
|
|
355
|
+
return this.check();
|
|
356
|
+
}
|
|
357
|
+
// Rotates a matrix by the given angle around the X axis
|
|
358
|
+
rotateX(radians) {
|
|
359
|
+
mat4_rotateX(this, this, radians);
|
|
360
|
+
// mat4_rotate(this, this, radians, [1, 0, 0]);
|
|
361
|
+
return this.check();
|
|
362
|
+
}
|
|
363
|
+
// Rotates a matrix by the given angle around the Y axis.
|
|
364
|
+
rotateY(radians) {
|
|
365
|
+
mat4_rotateY(this, this, radians);
|
|
366
|
+
// mat4_rotate(this, this, radians, [0, 1, 0]);
|
|
367
|
+
return this.check();
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* Rotates a matrix by the given angle around the Z axis.
|
|
371
|
+
* @param radians
|
|
372
|
+
* @returns self
|
|
373
|
+
*/
|
|
374
|
+
rotateZ(radians) {
|
|
375
|
+
mat4_rotateZ(this, this, radians);
|
|
376
|
+
// mat4_rotate(this, this, radians, [0, 0, 1]);
|
|
377
|
+
return this.check();
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
*
|
|
381
|
+
* @param param0
|
|
382
|
+
* @returns self
|
|
383
|
+
*/
|
|
384
|
+
rotateXYZ(angleXYZ) {
|
|
385
|
+
return this.rotateX(angleXYZ[0]).rotateY(angleXYZ[1]).rotateZ(angleXYZ[2]);
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
*
|
|
389
|
+
* @param radians
|
|
390
|
+
* @param axis
|
|
391
|
+
* @returns self
|
|
392
|
+
*/
|
|
393
|
+
rotateAxis(radians, axis) {
|
|
394
|
+
mat4_rotate(this, this, radians, axis);
|
|
395
|
+
return this.check();
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
*
|
|
399
|
+
* @param factor
|
|
400
|
+
* @returns self
|
|
401
|
+
*/
|
|
402
|
+
scale(factor) {
|
|
403
|
+
mat4_scale(this, this, Array.isArray(factor) ? factor : [factor, factor, factor]);
|
|
404
|
+
return this.check();
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
*
|
|
408
|
+
* @param vec
|
|
409
|
+
* @returns self
|
|
410
|
+
*/
|
|
411
|
+
translate(vector) {
|
|
412
|
+
mat4_translate(this, this, vector);
|
|
413
|
+
return this.check();
|
|
414
|
+
}
|
|
415
|
+
// Transforms
|
|
416
|
+
/**
|
|
417
|
+
* Transforms any 2, 3 or 4 element vector. 2 and 3 elements are treated as points
|
|
418
|
+
* @param vector
|
|
419
|
+
* @param result
|
|
420
|
+
* @returns self
|
|
421
|
+
*/
|
|
422
|
+
transform(vector, result) {
|
|
423
|
+
if (vector.length === 4) {
|
|
424
|
+
result = vec4_transformMat4(result || [-0, -0, -0, -0], vector, this);
|
|
425
|
+
checkVector(result, 4);
|
|
426
|
+
return result;
|
|
427
|
+
}
|
|
428
|
+
return this.transformAsPoint(vector, result);
|
|
429
|
+
}
|
|
430
|
+
/**
|
|
431
|
+
* Transforms any 2 or 3 element array as point (w implicitly 1)
|
|
432
|
+
* @param vector
|
|
433
|
+
* @param result
|
|
434
|
+
* @returns self
|
|
435
|
+
*/
|
|
436
|
+
transformAsPoint(vector, result) {
|
|
437
|
+
const { length } = vector;
|
|
438
|
+
let out;
|
|
439
|
+
switch (length) {
|
|
440
|
+
case 2:
|
|
441
|
+
out = vec2_transformMat4(result || [-0, -0], vector, this);
|
|
442
|
+
break;
|
|
443
|
+
case 3:
|
|
444
|
+
out = vec3_transformMat4(result || [-0, -0, -0], vector, this);
|
|
445
|
+
break;
|
|
446
|
+
default:
|
|
447
|
+
throw new Error('Illegal vector');
|
|
448
|
+
}
|
|
449
|
+
checkVector(out, vector.length);
|
|
450
|
+
return out;
|
|
451
|
+
}
|
|
452
|
+
/**
|
|
453
|
+
* Transforms any 2 or 3 element array as vector (w implicitly 0)
|
|
454
|
+
* @param vector
|
|
455
|
+
* @param result
|
|
456
|
+
* @returns self
|
|
457
|
+
*/
|
|
458
|
+
transformAsVector(vector, result) {
|
|
459
|
+
let out;
|
|
460
|
+
switch (vector.length) {
|
|
461
|
+
case 2:
|
|
462
|
+
out = vec2_transformMat4AsVector(result || [-0, -0], vector, this);
|
|
463
|
+
break;
|
|
464
|
+
case 3:
|
|
465
|
+
out = vec3_transformMat4AsVector(result || [-0, -0, -0], vector, this);
|
|
466
|
+
break;
|
|
467
|
+
default:
|
|
468
|
+
throw new Error('Illegal vector');
|
|
469
|
+
}
|
|
470
|
+
checkVector(out, vector.length);
|
|
471
|
+
return out;
|
|
472
|
+
}
|
|
473
|
+
/** @deprecated */
|
|
474
|
+
transformPoint(vector, result) {
|
|
475
|
+
return this.transformAsPoint(vector, result);
|
|
476
|
+
}
|
|
477
|
+
/** @deprecated */
|
|
478
|
+
transformVector(vector, result) {
|
|
479
|
+
return this.transformAsPoint(vector, result);
|
|
480
|
+
}
|
|
481
|
+
/** @deprecated */
|
|
482
|
+
transformDirection(vector, result) {
|
|
483
|
+
return this.transformAsVector(vector, result);
|
|
484
|
+
}
|
|
485
|
+
// three.js math API compatibility
|
|
486
|
+
makeRotationX(radians) {
|
|
487
|
+
return this.identity().rotateX(radians);
|
|
488
|
+
}
|
|
489
|
+
makeTranslation(x, y, z) {
|
|
490
|
+
return this.identity().translate([x, y, z]);
|
|
491
|
+
}
|
|
424
492
|
}
|
|
493
|
+
// TODO initializing static members directly is an option, but make sure no tree-shaking issues
|
|
425
494
|
let ZERO;
|
|
426
495
|
let IDENTITY;
|
|
427
|
-
|
|
428
496
|
function getZeroMatrix() {
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
return ZERO;
|
|
497
|
+
if (!ZERO) {
|
|
498
|
+
ZERO = new Matrix4([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
|
|
499
|
+
Object.freeze(ZERO);
|
|
500
|
+
}
|
|
501
|
+
return ZERO;
|
|
435
502
|
}
|
|
436
|
-
|
|
437
503
|
function getIdentityMatrix() {
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
return IDENTITY;
|
|
504
|
+
if (!IDENTITY) {
|
|
505
|
+
IDENTITY = new Matrix4();
|
|
506
|
+
Object.freeze(IDENTITY);
|
|
507
|
+
}
|
|
508
|
+
return IDENTITY;
|
|
444
509
|
}
|
|
445
|
-
|
|
510
|
+
// HELPER FUNCTIONS
|
|
446
511
|
function checkRadians(possiblyDegrees) {
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
512
|
+
if (possiblyDegrees > Math.PI * 2) {
|
|
513
|
+
throw Error('expected radians');
|
|
514
|
+
}
|
|
450
515
|
}
|
|
451
|
-
|
|
516
|
+
// eslint-disable-next-line max-params
|
|
452
517
|
function computeInfinitePerspectiveOffCenter(result, left, right, bottom, top, near) {
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
518
|
+
const column0Row0 = (2 * near) / (right - left);
|
|
519
|
+
const column1Row1 = (2 * near) / (top - bottom);
|
|
520
|
+
const column2Row0 = (right + left) / (right - left);
|
|
521
|
+
const column2Row1 = (top + bottom) / (top - bottom);
|
|
522
|
+
const column2Row2 = -1;
|
|
523
|
+
const column2Row3 = -1;
|
|
524
|
+
const column3Row2 = -2 * near;
|
|
525
|
+
result[0] = column0Row0;
|
|
526
|
+
result[1] = 0;
|
|
527
|
+
result[2] = 0;
|
|
528
|
+
result[3] = 0;
|
|
529
|
+
result[4] = 0;
|
|
530
|
+
result[5] = column1Row1;
|
|
531
|
+
result[6] = 0;
|
|
532
|
+
result[7] = 0;
|
|
533
|
+
result[8] = column2Row0;
|
|
534
|
+
result[9] = column2Row1;
|
|
535
|
+
result[10] = column2Row2;
|
|
536
|
+
result[11] = column2Row3;
|
|
537
|
+
result[12] = 0;
|
|
538
|
+
result[13] = 0;
|
|
539
|
+
result[14] = column3Row2;
|
|
540
|
+
result[15] = 0;
|
|
541
|
+
return result;
|
|
477
542
|
}
|
|
478
|
-
//# sourceMappingURL=matrix4.js.map
|