glmaths 0.0.2 → 0.0.4
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/README.md +570 -552
- package/benchmark.js +2 -2
- package/dist/cjs/glmaths.d.ts +240 -198
- package/dist/cjs/glmaths.js +544 -462
- package/dist/cjs/glmaths.js.map +1 -1
- package/dist/cjs/glmaths.min.js +1 -1
- package/dist/cjs/glmaths.min.js.map +1 -1
- package/dist/esm/glmaths.d.ts +240 -198
- package/dist/esm/glmaths.js +544 -462
- package/dist/esm/glmaths.js.map +1 -1
- package/dist/esm/glmaths.min.js +1 -1
- package/dist/esm/glmaths.min.js.map +1 -1
- package/dist/glmaths.d.ts +240 -198
- package/dist/glmaths.js +544 -462
- package/dist/glmaths.js.map +1 -1
- package/dist/glmaths.min.js +1 -1
- package/dist/glmaths.min.js.map +1 -1
- package/examples/index.html +23 -0
- package/examples/main.js +134 -0
- package/examples/main.ts +159 -0
- package/package.json +1 -1
- package/src/mat2.ts +27 -27
- package/src/mat2x3.ts +37 -31
- package/src/mat3.ts +53 -54
- package/src/mat4.ts +81 -82
- package/src/quat.ts +36 -23
- package/src/quat2.ts +45 -31
- package/src/vec2.ts +90 -70
- package/src/vec3.ts +143 -121
- package/src/vec4.ts +79 -57
- package/tests/mat2.test.ts +53 -53
- package/tests/mat2x3.test.ts +46 -46
- package/tests/mat3.test.ts +59 -59
package/dist/esm/glmaths.js
CHANGED
|
@@ -3,20 +3,20 @@
|
|
|
3
3
|
* @extends Float32Array
|
|
4
4
|
*/
|
|
5
5
|
class Vec3 extends Float32Array {
|
|
6
|
-
static get zero() { return
|
|
7
|
-
static get Zero() { return
|
|
8
|
-
static get ZERO() { return
|
|
9
|
-
static get one() { return
|
|
10
|
-
static get One() { return
|
|
11
|
-
static get ONE() { return
|
|
12
|
-
static get unitX() { return
|
|
13
|
-
static get UnitX() { return
|
|
14
|
-
static get unitY() { return
|
|
15
|
-
static get UnitY() { return
|
|
16
|
-
static get unitZ() { return
|
|
17
|
-
static get UnitZ() { return
|
|
18
|
-
/**
|
|
19
|
-
* Creates
|
|
6
|
+
static get zero() { return vec3(0, 0, 0); }
|
|
7
|
+
static get Zero() { return vec3(0, 0, 0); }
|
|
8
|
+
static get ZERO() { return vec3(0, 0, 0); }
|
|
9
|
+
static get one() { return vec3(1, 1, 1); }
|
|
10
|
+
static get One() { return vec3(1, 1, 1); }
|
|
11
|
+
static get ONE() { return vec3(1, 1, 1); }
|
|
12
|
+
static get unitX() { return vec3(1, 0, 0); }
|
|
13
|
+
static get UnitX() { return vec3(1, 0, 0); }
|
|
14
|
+
static get unitY() { return vec3(0, 1, 0); }
|
|
15
|
+
static get UnitY() { return vec3(0, 1, 0); }
|
|
16
|
+
static get unitZ() { return vec3(0, 0, 1); }
|
|
17
|
+
static get UnitZ() { return vec3(0, 0, 1); }
|
|
18
|
+
/**
|
|
19
|
+
* Creates new vec3
|
|
20
20
|
*
|
|
21
21
|
* @param {Number} x X component, defaults to 0
|
|
22
22
|
* @param {Number} y Y component, defaults to 0
|
|
@@ -38,10 +38,10 @@ class Vec3 extends Float32Array {
|
|
|
38
38
|
* Adds two vec3's
|
|
39
39
|
*
|
|
40
40
|
* @param {Number | Vec3} b the second operand
|
|
41
|
-
* @param {Vec3} out the receiving vector, defaults to
|
|
41
|
+
* @param {Vec3} out the receiving vector, defaults to new vec3()
|
|
42
42
|
* @returns {Vec3} out
|
|
43
43
|
*/
|
|
44
|
-
plus(b, out = index.ALWAYS_COPY ?
|
|
44
|
+
plus(b, out = index.ALWAYS_COPY ? vec3() : this) {
|
|
45
45
|
if (typeof b === 'number') {
|
|
46
46
|
out[0] = this[0] + b;
|
|
47
47
|
out[1] = this[1] + b;
|
|
@@ -58,10 +58,10 @@ class Vec3 extends Float32Array {
|
|
|
58
58
|
* Subtracts two vec3's
|
|
59
59
|
*
|
|
60
60
|
* @param {Number | Vec3} b the second operand
|
|
61
|
-
* @param {Vec3} out the receiving vector, defaults to
|
|
61
|
+
* @param {Vec3} out the receiving vector, defaults to new vec3()
|
|
62
62
|
* @returns {Vec3} out
|
|
63
63
|
*/
|
|
64
|
-
minus(b, out = index.ALWAYS_COPY ?
|
|
64
|
+
minus(b, out = index.ALWAYS_COPY ? vec3() : this) {
|
|
65
65
|
if (typeof b === 'number') {
|
|
66
66
|
out[0] = this[0] - b;
|
|
67
67
|
out[1] = this[1] - b;
|
|
@@ -78,10 +78,10 @@ class Vec3 extends Float32Array {
|
|
|
78
78
|
* Multiplies two vec3's
|
|
79
79
|
*
|
|
80
80
|
* @param {Number | Vec3} b the second operand
|
|
81
|
-
* @param {Vec3} out the receiving vector, defaults to
|
|
81
|
+
* @param {Vec3} out the receiving vector, defaults to new vec3()
|
|
82
82
|
* @returns {Vec3} out
|
|
83
83
|
*/
|
|
84
|
-
mult(b, out = index.ALWAYS_COPY ?
|
|
84
|
+
mult(b, out = index.ALWAYS_COPY ? vec3() : this) {
|
|
85
85
|
if (typeof b === 'number') {
|
|
86
86
|
out[0] = this[0] * b;
|
|
87
87
|
out[1] = this[1] * b;
|
|
@@ -98,10 +98,10 @@ class Vec3 extends Float32Array {
|
|
|
98
98
|
* Divides two vec3's
|
|
99
99
|
*
|
|
100
100
|
* @param {Number | Vec3} b the second operand
|
|
101
|
-
* @param {Vec3} out the receiving vector, defaults to
|
|
101
|
+
* @param {Vec3} out the receiving vector, defaults to new vec3()
|
|
102
102
|
* @returns {Vec3} out
|
|
103
103
|
*/
|
|
104
|
-
div(b, out = index.ALWAYS_COPY ?
|
|
104
|
+
div(b, out = index.ALWAYS_COPY ? vec3() : this) {
|
|
105
105
|
if (typeof b === 'number') {
|
|
106
106
|
out[0] = this[0] / b;
|
|
107
107
|
out[1] = this[1] / b;
|
|
@@ -114,7 +114,7 @@ class Vec3 extends Float32Array {
|
|
|
114
114
|
}
|
|
115
115
|
return out;
|
|
116
116
|
}
|
|
117
|
-
invDiv(b, out = index.ALWAYS_COPY ?
|
|
117
|
+
invDiv(b, out = index.ALWAYS_COPY ? vec3() : this) {
|
|
118
118
|
if (typeof b === 'number') {
|
|
119
119
|
out[0] = b / this[0];
|
|
120
120
|
out[1] = b / this[1];
|
|
@@ -128,18 +128,18 @@ class Vec3 extends Float32Array {
|
|
|
128
128
|
return out;
|
|
129
129
|
}
|
|
130
130
|
/**
|
|
131
|
-
* Negates the components of
|
|
131
|
+
* Negates the components of this vec3
|
|
132
132
|
*
|
|
133
|
-
* @param {Vec3} out the receiving vector, defaults to
|
|
133
|
+
* @param {Vec3} out the receiving vector, defaults to new vec3()
|
|
134
134
|
* @returns {Vec3} out
|
|
135
135
|
*/
|
|
136
|
-
negate(out = index.ALWAYS_COPY ?
|
|
136
|
+
negate(out = index.ALWAYS_COPY ? vec3() : this) {
|
|
137
137
|
out[0] = -this[0];
|
|
138
138
|
out[1] = -this[1];
|
|
139
139
|
out[2] = -this[2];
|
|
140
140
|
return out;
|
|
141
141
|
}
|
|
142
|
-
unaryPlus(out = index.ALWAYS_COPY ?
|
|
142
|
+
unaryPlus(out = index.ALWAYS_COPY ? vec3() : this) {
|
|
143
143
|
if (!out.equals(this)) {
|
|
144
144
|
out[0] = this[0];
|
|
145
145
|
out[1] = this[1];
|
|
@@ -148,13 +148,13 @@ class Vec3 extends Float32Array {
|
|
|
148
148
|
return out;
|
|
149
149
|
}
|
|
150
150
|
/**
|
|
151
|
-
* Normalizes
|
|
151
|
+
* Normalizes vec3
|
|
152
152
|
*
|
|
153
153
|
* @param {Vec3} v the vector to normalize
|
|
154
|
-
* @param {Vec3} out the receiving vector, defaults to
|
|
154
|
+
* @param {Vec3} out the receiving vector, defaults to new vec3
|
|
155
155
|
* @returns {Vec3} out
|
|
156
156
|
*/
|
|
157
|
-
static normalize(v, out =
|
|
157
|
+
static normalize(v, out = vec3()) {
|
|
158
158
|
const x = v[0], y = v[1], z = v[2];
|
|
159
159
|
let len = x * x + y * y + z * z;
|
|
160
160
|
if (len > 0)
|
|
@@ -165,12 +165,12 @@ class Vec3 extends Float32Array {
|
|
|
165
165
|
return out;
|
|
166
166
|
}
|
|
167
167
|
/**
|
|
168
|
-
* Normalizes
|
|
168
|
+
* Normalizes this vec3
|
|
169
169
|
*
|
|
170
|
-
* @param {Vec3} out the receiving vector, defaults to
|
|
170
|
+
* @param {Vec3} out the receiving vector, defaults to new vec3()
|
|
171
171
|
* @returns {Vec3} out
|
|
172
172
|
*/
|
|
173
|
-
normalize(out = index.ALWAYS_COPY ?
|
|
173
|
+
normalize(out = index.ALWAYS_COPY ? vec3() : this) {
|
|
174
174
|
const x = this[0], y = this[1], z = this[2];
|
|
175
175
|
let len = x * x + y * y + z * z;
|
|
176
176
|
if (len > 0)
|
|
@@ -201,7 +201,7 @@ class Vec3 extends Float32Array {
|
|
|
201
201
|
return this[0] === b[0] && this[1] === b[1] && this[2] === b[2];
|
|
202
202
|
}
|
|
203
203
|
/**
|
|
204
|
-
* Calculates the squared length of
|
|
204
|
+
* Calculates the squared length of vec3
|
|
205
205
|
*
|
|
206
206
|
* @returns {Number} squared length of a vector
|
|
207
207
|
*/
|
|
@@ -210,7 +210,7 @@ class Vec3 extends Float32Array {
|
|
|
210
210
|
return x * x + y * y + z * z;
|
|
211
211
|
}
|
|
212
212
|
/**
|
|
213
|
-
* Calculates the length of
|
|
213
|
+
* Calculates the length of vec3
|
|
214
214
|
*
|
|
215
215
|
* @returns {Number} length of a vector
|
|
216
216
|
*/
|
|
@@ -219,104 +219,104 @@ class Vec3 extends Float32Array {
|
|
|
219
219
|
return Math.sqrt(x * x + y * y + z * z);
|
|
220
220
|
}
|
|
221
221
|
/**
|
|
222
|
-
* Returns
|
|
222
|
+
* Returns vec3 with each component floored
|
|
223
223
|
*
|
|
224
224
|
* @param {Vec3} v the vector to floor
|
|
225
225
|
* @returns {Vec3} a new floored vector
|
|
226
226
|
*/
|
|
227
|
-
static floor(v, out =
|
|
227
|
+
static floor(v, out = vec3()) {
|
|
228
228
|
out[0] = Math.floor(v[0]);
|
|
229
229
|
out[1] = Math.floor(v[1]);
|
|
230
230
|
out[2] = Math.floor(v[2]);
|
|
231
231
|
return out;
|
|
232
232
|
}
|
|
233
233
|
/**
|
|
234
|
-
* Returns
|
|
234
|
+
* Returns vec3 with each component rounded
|
|
235
235
|
*
|
|
236
236
|
* @param {Vec3} v the vector to round
|
|
237
237
|
* @returns {Vec3} a new rounded vector
|
|
238
238
|
*/
|
|
239
|
-
static round(v, out =
|
|
239
|
+
static round(v, out = vec3()) {
|
|
240
240
|
out[0] = Math.round(v[0]);
|
|
241
241
|
out[1] = Math.round(v[1]);
|
|
242
242
|
out[2] = Math.round(v[2]);
|
|
243
243
|
return out;
|
|
244
244
|
}
|
|
245
245
|
/**
|
|
246
|
-
* Returns
|
|
246
|
+
* Returns vec3 with each component ceiled
|
|
247
247
|
*
|
|
248
248
|
* @param {Vec3} v the vector to ceil
|
|
249
249
|
* @returns {Vec3} a new ceiled vector
|
|
250
250
|
*/
|
|
251
|
-
static ceil(v, out =
|
|
251
|
+
static ceil(v, out = vec3()) {
|
|
252
252
|
out[0] = Math.ceil(v[0]);
|
|
253
253
|
out[1] = Math.ceil(v[1]);
|
|
254
254
|
out[2] = Math.ceil(v[2]);
|
|
255
255
|
return out;
|
|
256
256
|
}
|
|
257
257
|
/**
|
|
258
|
-
* Floors each component of
|
|
258
|
+
* Floors each component of vec3
|
|
259
259
|
*
|
|
260
260
|
* @returns {Vec3} this
|
|
261
261
|
*/
|
|
262
|
-
floor(out = index.ALWAYS_COPY ?
|
|
262
|
+
floor(out = index.ALWAYS_COPY ? vec3() : this) {
|
|
263
263
|
out[0] = Math.floor(this[0]);
|
|
264
264
|
out[1] = Math.floor(this[1]);
|
|
265
265
|
out[2] = Math.floor(this[2]);
|
|
266
266
|
return out;
|
|
267
267
|
}
|
|
268
268
|
/**
|
|
269
|
-
* Rounds each component of
|
|
269
|
+
* Rounds each component of vec3
|
|
270
270
|
*
|
|
271
271
|
* @returns {Vec3} this
|
|
272
272
|
*/
|
|
273
|
-
round(out = index.ALWAYS_COPY ?
|
|
273
|
+
round(out = index.ALWAYS_COPY ? vec3() : this) {
|
|
274
274
|
out[0] = Math.round(this[0]);
|
|
275
275
|
out[1] = Math.round(this[1]);
|
|
276
276
|
out[2] = Math.round(this[2]);
|
|
277
277
|
return out;
|
|
278
278
|
}
|
|
279
279
|
/**
|
|
280
|
-
* Ceils each component of
|
|
280
|
+
* Ceils each component of vec3
|
|
281
281
|
*
|
|
282
282
|
* @returns {Vec3} this
|
|
283
283
|
*/
|
|
284
|
-
ceil(out = index.ALWAYS_COPY ?
|
|
284
|
+
ceil(out = index.ALWAYS_COPY ? vec3() : this) {
|
|
285
285
|
out[0] = Math.ceil(this[0]);
|
|
286
286
|
out[1] = Math.ceil(this[1]);
|
|
287
287
|
out[2] = Math.ceil(this[2]);
|
|
288
288
|
return out;
|
|
289
289
|
}
|
|
290
290
|
/**
|
|
291
|
-
* Returns the inverse of
|
|
291
|
+
* Returns the inverse of vec3
|
|
292
292
|
*
|
|
293
293
|
* @param {Vec3} v the source vector
|
|
294
294
|
* @returns {Vec3} a new inverted vector
|
|
295
295
|
*/
|
|
296
|
-
static inverse(v, out =
|
|
296
|
+
static inverse(v, out = vec3()) {
|
|
297
297
|
out[0] = 1.0 / v[0];
|
|
298
298
|
out[1] = 1.0 / v[1];
|
|
299
299
|
out[2] = 1.0 / v[2];
|
|
300
300
|
return out;
|
|
301
301
|
}
|
|
302
302
|
/**
|
|
303
|
-
* Inverts
|
|
303
|
+
* Inverts vec3 component-wise
|
|
304
304
|
*
|
|
305
305
|
* @returns {Vec3} this
|
|
306
306
|
*/
|
|
307
|
-
inverse(out = index.ALWAYS_COPY ?
|
|
307
|
+
inverse(out = index.ALWAYS_COPY ? vec3() : this) {
|
|
308
308
|
out[0] = 1.0 / this[0];
|
|
309
309
|
out[1] = 1.0 / this[1];
|
|
310
310
|
out[2] = 1.0 / this[2];
|
|
311
311
|
return out;
|
|
312
312
|
}
|
|
313
313
|
/**
|
|
314
|
-
* Creates
|
|
314
|
+
* Creates vec3 initialized with values from a vector
|
|
315
315
|
*
|
|
316
|
-
* @returns {Vec3}
|
|
316
|
+
* @returns {Vec3} vec3
|
|
317
317
|
*/
|
|
318
318
|
clone() {
|
|
319
|
-
return
|
|
319
|
+
return vec3(this[0], this[1], this[2]);
|
|
320
320
|
}
|
|
321
321
|
/**
|
|
322
322
|
* Returns a string representation of a vector
|
|
@@ -336,7 +336,7 @@ class Vec3 extends Float32Array {
|
|
|
336
336
|
const r = index.RANDOM() * 2.0 * Math.PI;
|
|
337
337
|
const z = index.RANDOM() * 2.0 - 1.0;
|
|
338
338
|
const zScale = Math.sqrt(1.0 - z * z) * scale;
|
|
339
|
-
return
|
|
339
|
+
return vec3(Math.cos(r) * zScale, Math.sin(r) * zScale, z * scale);
|
|
340
340
|
}
|
|
341
341
|
/**
|
|
342
342
|
* Calculates the angle between two vec3's
|
|
@@ -367,10 +367,10 @@ class Vec3 extends Float32Array {
|
|
|
367
367
|
*
|
|
368
368
|
* @param {Vec3} a the first operand
|
|
369
369
|
* @param {Vec3} b the second operand
|
|
370
|
-
* @param {Vec3} out the receiving vector, defaults to
|
|
370
|
+
* @param {Vec3} out the receiving vector, defaults to new vec3
|
|
371
371
|
* @returns {Vec3} out
|
|
372
372
|
*/
|
|
373
|
-
static cross(a, b, out =
|
|
373
|
+
static cross(a, b, out = vec3()) {
|
|
374
374
|
const ax = a[0], ay = a[1], az = a[2];
|
|
375
375
|
const bx = b[0], by = b[1], bz = b[2];
|
|
376
376
|
out[0] = ay * bz - az * by;
|
|
@@ -410,10 +410,10 @@ class Vec3 extends Float32Array {
|
|
|
410
410
|
* @param {Vec3} a the first operand
|
|
411
411
|
* @param {Vec3} b the second operand
|
|
412
412
|
* @param {Number} t interpolation amount, in the range [0-1], between the two inputs
|
|
413
|
-
* @param {Vec3} out the receiving vector, defaults to
|
|
413
|
+
* @param {Vec3} out the receiving vector, defaults to new vec3
|
|
414
414
|
* @returns {Vec3} out
|
|
415
415
|
*/
|
|
416
|
-
static lerp(a, b, t, out =
|
|
416
|
+
static lerp(a, b, t, out = vec3()) {
|
|
417
417
|
const ax = a[0], ay = a[1], az = a[2];
|
|
418
418
|
out[0] = ax + (b[0] - ax) * t;
|
|
419
419
|
out[1] = ay + (b[1] - ay) * t;
|
|
@@ -426,10 +426,10 @@ class Vec3 extends Float32Array {
|
|
|
426
426
|
* @param {Vec3} a the first operand
|
|
427
427
|
* @param {Vec3} b the second operand
|
|
428
428
|
* @param {Number} t interpolation amount, in the range [0-1], between the two inputs
|
|
429
|
-
* @param {Vec3} out the receiving vector, defaults to
|
|
429
|
+
* @param {Vec3} out the receiving vector, defaults to new vec3
|
|
430
430
|
* @returns {Vec3} out
|
|
431
431
|
*/
|
|
432
|
-
static slerp(a, b, t, out =
|
|
432
|
+
static slerp(a, b, t, out = vec3()) {
|
|
433
433
|
const angle = Math.acos(Math.min(Math.max(Vec3.dot(a, b), -1), 1));
|
|
434
434
|
const sinTotal = Math.sin(angle);
|
|
435
435
|
const ratioA = Math.sin((1 - t) * angle) / sinTotal;
|
|
@@ -446,7 +446,7 @@ class Vec3 extends Float32Array {
|
|
|
446
446
|
* @param {Vec3} b the second operand
|
|
447
447
|
* @returns {Vec3} a new vector with the max components
|
|
448
448
|
*/
|
|
449
|
-
static max(a, b, out =
|
|
449
|
+
static max(a, b, out = vec3()) {
|
|
450
450
|
out[0] = Math.max(a[0], b[0]);
|
|
451
451
|
out[1] = Math.max(a[1], b[1]);
|
|
452
452
|
out[2] = Math.max(a[2], b[2]);
|
|
@@ -459,7 +459,7 @@ class Vec3 extends Float32Array {
|
|
|
459
459
|
* @param {Vec3} b the second operand
|
|
460
460
|
* @returns {Vec3} a new vector with the min components
|
|
461
461
|
*/
|
|
462
|
-
static min(a, b, out =
|
|
462
|
+
static min(a, b, out = vec3()) {
|
|
463
463
|
out[0] = Math.min(a[0], b[0]);
|
|
464
464
|
out[1] = Math.min(a[1], b[1]);
|
|
465
465
|
out[2] = Math.min(a[2], b[2]);
|
|
@@ -474,7 +474,7 @@ class Vec3 extends Float32Array {
|
|
|
474
474
|
* @param {Vec3} out the receiving vector
|
|
475
475
|
* @returns {Vec3} out
|
|
476
476
|
*/
|
|
477
|
-
static clamp(v, min, max, out =
|
|
477
|
+
static clamp(v, min, max, out = vec3()) {
|
|
478
478
|
const minX = typeof min === 'number' ? min : min[0];
|
|
479
479
|
const minY = typeof min === 'number' ? min : min[1];
|
|
480
480
|
const minZ = typeof min === 'number' ? min : min[2];
|
|
@@ -495,7 +495,7 @@ class Vec3 extends Float32Array {
|
|
|
495
495
|
* @param {Vec3} out the receiving vector
|
|
496
496
|
* @returns {Vec3} out
|
|
497
497
|
*/
|
|
498
|
-
static mix(a, b, t, out =
|
|
498
|
+
static mix(a, b, t, out = vec3()) {
|
|
499
499
|
if (typeof t === 'number') {
|
|
500
500
|
out[0] = a[0] + (b[0] - a[0]) * t;
|
|
501
501
|
out[1] = a[1] + (b[1] - a[1]) * t;
|
|
@@ -517,7 +517,7 @@ class Vec3 extends Float32Array {
|
|
|
517
517
|
* @param {Vec3} out the receiving vector
|
|
518
518
|
* @returns {Vec3} out
|
|
519
519
|
*/
|
|
520
|
-
static smoothstep(edge0, edge1, v, out =
|
|
520
|
+
static smoothstep(edge0, edge1, v, out = vec3()) {
|
|
521
521
|
const e0x = typeof edge0 === 'number' ? edge0 : edge0[0];
|
|
522
522
|
const e0y = typeof edge0 === 'number' ? edge0 : edge0[1];
|
|
523
523
|
const e0z = typeof edge0 === 'number' ? edge0 : edge0[2];
|
|
@@ -533,14 +533,14 @@ class Vec3 extends Float32Array {
|
|
|
533
533
|
return out;
|
|
534
534
|
}
|
|
535
535
|
/**
|
|
536
|
-
* Rotates
|
|
536
|
+
* Rotates vec3 around the X axis
|
|
537
537
|
*
|
|
538
538
|
* @param {Vec3} v the vector to rotate
|
|
539
539
|
* @param {Number} rad the angle of rotation in radians
|
|
540
|
-
* @param {Vec3} origin the origin of the rotation, defaults to vec3(0)
|
|
540
|
+
* @param {Vec3} origin the origin of the rotation, defaults to vec3(0, 0, 0)
|
|
541
541
|
* @returns {Vec3} a new rotated vector
|
|
542
542
|
*/
|
|
543
|
-
static rotateX(v, rad, origin =
|
|
543
|
+
static rotateX(v, rad, origin = vec3.zero, out = vec3()) {
|
|
544
544
|
const p1 = v[1] - origin[1];
|
|
545
545
|
const p2 = v[2] - origin[2];
|
|
546
546
|
out[0] = v[0];
|
|
@@ -549,13 +549,13 @@ class Vec3 extends Float32Array {
|
|
|
549
549
|
return out;
|
|
550
550
|
}
|
|
551
551
|
/**
|
|
552
|
-
* Rotates
|
|
552
|
+
* Rotates vec3 around the X axis
|
|
553
553
|
*
|
|
554
554
|
* @param {Number} rad the angle of rotation in radians
|
|
555
|
-
* @param {Vec3} origin the origin of the rotation, defaults to vec3(0)
|
|
555
|
+
* @param {Vec3} origin the origin of the rotation, defaults to vec3(0, 0, 0)
|
|
556
556
|
* @returns {Vec3} a rotated vector
|
|
557
557
|
*/
|
|
558
|
-
rotateX(rad, origin =
|
|
558
|
+
rotateX(rad, origin = vec3.zero, out = index.ALWAYS_COPY ? vec3() : this) {
|
|
559
559
|
const p1 = this[1] - origin[1];
|
|
560
560
|
const p2 = this[2] - origin[2];
|
|
561
561
|
out[0] = this[0];
|
|
@@ -564,14 +564,14 @@ class Vec3 extends Float32Array {
|
|
|
564
564
|
return out;
|
|
565
565
|
}
|
|
566
566
|
/**
|
|
567
|
-
* Rotates
|
|
567
|
+
* Rotates vec3 around the Y axis
|
|
568
568
|
*
|
|
569
569
|
* @param {Vec3} v the vector to rotate
|
|
570
570
|
* @param {Number} rad the angle of rotation in radians
|
|
571
|
-
* @param {Vec3} origin the origin of the rotation, defaults to vec3(0)
|
|
571
|
+
* @param {Vec3} origin the origin of the rotation, defaults to vec3(0, 0, 0)
|
|
572
572
|
* @returns {Vec3} a rotated vector
|
|
573
573
|
*/
|
|
574
|
-
static rotateY(v, rad, origin =
|
|
574
|
+
static rotateY(v, rad, origin = vec3.zero, out = vec3()) {
|
|
575
575
|
const p0 = v[0] - origin[0];
|
|
576
576
|
const p2 = v[2] - origin[2];
|
|
577
577
|
out[0] = p2 * Math.sin(rad) + p0 * Math.cos(rad) + origin[0];
|
|
@@ -580,12 +580,12 @@ class Vec3 extends Float32Array {
|
|
|
580
580
|
return out;
|
|
581
581
|
}
|
|
582
582
|
/**
|
|
583
|
-
* Rotates
|
|
583
|
+
* Rotates vec3 around the Y axis
|
|
584
584
|
*
|
|
585
585
|
* @param {Number} rad the angle of rotation in radians
|
|
586
|
-
* @param {Vec3} origin the origin of the rotation, defaults to vec3(0)
|
|
586
|
+
* @param {Vec3} origin the origin of the rotation, defaults to vec3(0, 0, 0)
|
|
587
587
|
*/
|
|
588
|
-
rotateY(rad, origin =
|
|
588
|
+
rotateY(rad, origin = vec3.zero, out = index.ALWAYS_COPY ? vec3() : this) {
|
|
589
589
|
const p0 = this[0] - origin[0];
|
|
590
590
|
const p2 = this[2] - origin[2];
|
|
591
591
|
out[0] = p2 * Math.sin(rad) + p0 * Math.cos(rad) + origin[0];
|
|
@@ -594,14 +594,14 @@ class Vec3 extends Float32Array {
|
|
|
594
594
|
return out;
|
|
595
595
|
}
|
|
596
596
|
/**
|
|
597
|
-
* Rotates
|
|
597
|
+
* Rotates vec3 around the Z axis
|
|
598
598
|
*
|
|
599
599
|
* @param {Vec3} v the vector to rotate
|
|
600
600
|
* @param {Number} rad the angle of rotation in radians
|
|
601
601
|
* @param {Vec3} origin the origin of the rotation, defaults to ZERO
|
|
602
602
|
* @returns {Vec3} a new rotated vector
|
|
603
603
|
*/
|
|
604
|
-
static rotateZ(v, rad, origin =
|
|
604
|
+
static rotateZ(v, rad, origin = vec3.zero, out = vec3()) {
|
|
605
605
|
const p0 = v[0] - origin[0];
|
|
606
606
|
const p1 = v[1] - origin[1];
|
|
607
607
|
out[0] = p0 * Math.cos(rad) - p1 * Math.sin(rad) + origin[0];
|
|
@@ -610,12 +610,12 @@ class Vec3 extends Float32Array {
|
|
|
610
610
|
return out;
|
|
611
611
|
}
|
|
612
612
|
/**
|
|
613
|
-
* Rotates
|
|
613
|
+
* Rotates vec3 around the Z axis
|
|
614
614
|
*
|
|
615
615
|
* @param {Number} rad the angle of rotation in radians
|
|
616
|
-
* @param {Vec3} origin the origin of the rotation, defaults to vec3(0)
|
|
616
|
+
* @param {Vec3} origin the origin of the rotation, defaults to vec3(0, 0, 0)
|
|
617
617
|
*/
|
|
618
|
-
rotateZ(rad, origin =
|
|
618
|
+
rotateZ(rad, origin = vec3.zero, out = index.ALWAYS_COPY ? vec3() : this) {
|
|
619
619
|
const p0 = this[0] - origin[0];
|
|
620
620
|
const p1 = this[1] - origin[1];
|
|
621
621
|
out[0] = p0 * Math.cos(rad) - p1 * Math.sin(rad) + origin[0];
|
|
@@ -633,7 +633,7 @@ class Vec3 extends Float32Array {
|
|
|
633
633
|
* @param {Number} t interpolation amount, in the range [0-1], between the two inputs
|
|
634
634
|
* @returns {Vec3} a new vector
|
|
635
635
|
*/
|
|
636
|
-
static hermite(a, b, c, d, t, out =
|
|
636
|
+
static hermite(a, b, c, d, t, out = vec3()) {
|
|
637
637
|
const factorTimes2 = t * t;
|
|
638
638
|
const factor1 = factorTimes2 * (2 * t - 3) + 1;
|
|
639
639
|
const factor2 = factorTimes2 * (t - 2) + t;
|
|
@@ -654,7 +654,7 @@ class Vec3 extends Float32Array {
|
|
|
654
654
|
* @param {Number} t interpolation amount, in the range [0-1], between the two inputs
|
|
655
655
|
* @returns {Vec3} a new vector
|
|
656
656
|
*/
|
|
657
|
-
static bezier(a, b, c, d, t, out =
|
|
657
|
+
static bezier(a, b, c, d, t, out = vec3()) {
|
|
658
658
|
const inverseFactor = 1 - t;
|
|
659
659
|
const inverseFactorTimesTwo = inverseFactor * inverseFactor;
|
|
660
660
|
const factorTimes2 = t * t;
|
|
@@ -673,10 +673,10 @@ class Vec3 extends Float32Array {
|
|
|
673
673
|
* @param {Vec3} a the first operand
|
|
674
674
|
* @param {Vec3} b the second operand
|
|
675
675
|
* @param {Number} scale the amount to scale b by before adding
|
|
676
|
-
* @param {Vec3} out the receiving vector, defaults to
|
|
676
|
+
* @param {Vec3} out the receiving vector, defaults to new vec3
|
|
677
677
|
* @returns {Vec3} out
|
|
678
678
|
*/
|
|
679
|
-
static scaleAndAdd(a, b, scale, out =
|
|
679
|
+
static scaleAndAdd(a, b, scale, out = vec3()) {
|
|
680
680
|
out[0] = a[0] + b[0] * scale;
|
|
681
681
|
out[1] = a[1] + b[1] * scale;
|
|
682
682
|
out[2] = a[2] + b[2] * scale;
|
|
@@ -687,10 +687,10 @@ class Vec3 extends Float32Array {
|
|
|
687
687
|
*
|
|
688
688
|
* @param {Vec3} I the incident vector
|
|
689
689
|
* @param {Vec3} N the surface normal
|
|
690
|
-
* @param {Vec3} out the receiving vector, defaults to
|
|
690
|
+
* @param {Vec3} out the receiving vector, defaults to new vec3
|
|
691
691
|
* @returns {Vec3} out
|
|
692
692
|
*/
|
|
693
|
-
static reflect(I, N, out =
|
|
693
|
+
static reflect(I, N, out = vec3()) {
|
|
694
694
|
const d = Vec3.dot(N, I) * 2;
|
|
695
695
|
out[0] = I[0] - d * N[0];
|
|
696
696
|
out[1] = I[1] - d * N[1];
|
|
@@ -703,10 +703,10 @@ class Vec3 extends Float32Array {
|
|
|
703
703
|
* @param {Vec3} I the incident vector
|
|
704
704
|
* @param {Vec3} N the surface normal
|
|
705
705
|
* @param {Number} eta the ratio of indices of refraction
|
|
706
|
-
* @param {Vec3} out the receiving vector, defaults to
|
|
706
|
+
* @param {Vec3} out the receiving vector, defaults to new vec3
|
|
707
707
|
* @returns {Vec3} out
|
|
708
708
|
*/
|
|
709
|
-
static refract(I, N, eta, out =
|
|
709
|
+
static refract(I, N, eta, out = vec3()) {
|
|
710
710
|
const d = Vec3.dot(N, I);
|
|
711
711
|
const k = 1.0 - eta * eta * (1.0 - d * d);
|
|
712
712
|
if (k < 0.0) {
|
|
@@ -725,10 +725,10 @@ class Vec3 extends Float32Array {
|
|
|
725
725
|
* @param {Vec3} N the vector to orient
|
|
726
726
|
* @param {Vec3} I the incident vector
|
|
727
727
|
* @param {Vec3} Nref the reference vector
|
|
728
|
-
* @param {Vec3} out the receiving vector, defaults to
|
|
728
|
+
* @param {Vec3} out the receiving vector, defaults to new vec3
|
|
729
729
|
* @returns {Vec3} out
|
|
730
730
|
*/
|
|
731
|
-
static faceforward(N, I, Nref, out =
|
|
731
|
+
static faceforward(N, I, Nref, out = vec3()) {
|
|
732
732
|
const d = Vec3.dot(Nref, I);
|
|
733
733
|
const sign = d < 0 ? 1 : -1;
|
|
734
734
|
out[0] = N[0] * sign;
|
|
@@ -742,10 +742,10 @@ class Vec3 extends Float32Array {
|
|
|
742
742
|
* @param {Vec3} p1 the first vertex
|
|
743
743
|
* @param {Vec3} p2 the second vertex
|
|
744
744
|
* @param {Vec3} p3 the third vertex
|
|
745
|
-
* @param {Vec3} out the receiving vector, defaults to
|
|
745
|
+
* @param {Vec3} out the receiving vector, defaults to new vec3
|
|
746
746
|
* @returns {Vec3} out
|
|
747
747
|
*/
|
|
748
|
-
static triangleNormal(p1, p2, p3, out =
|
|
748
|
+
static triangleNormal(p1, p2, p3, out = vec3()) {
|
|
749
749
|
const e1x = p2[0] - p1[0], e1y = p2[1] - p1[1], e1z = p2[2] - p1[2];
|
|
750
750
|
const e2x = p3[0] - p1[0], e2y = p3[1] - p1[1], e2z = p3[2] - p1[2];
|
|
751
751
|
out[0] = e1y * e2z - e1z * e2y;
|
|
@@ -765,10 +765,10 @@ class Vec3 extends Float32Array {
|
|
|
765
765
|
*
|
|
766
766
|
* @param {Vec3} a the vector to project
|
|
767
767
|
* @param {Vec3} b the vector to project onto
|
|
768
|
-
* @param {Vec3} out the receiving vector, defaults to
|
|
768
|
+
* @param {Vec3} out the receiving vector, defaults to new vec3
|
|
769
769
|
* @returns {Vec3} out
|
|
770
770
|
*/
|
|
771
|
-
static project(a, b, out =
|
|
771
|
+
static project(a, b, out = vec3()) {
|
|
772
772
|
const d = Vec3.dot(a, b) / Vec3.dot(b, b);
|
|
773
773
|
out[0] = b[0] * d;
|
|
774
774
|
out[1] = b[1] * d;
|
|
@@ -793,22 +793,22 @@ class Vec3 extends Float32Array {
|
|
|
793
793
|
*
|
|
794
794
|
* @param {Vec3} b the second operand
|
|
795
795
|
* @param {Number} scale the amount to scale b by before adding
|
|
796
|
-
* @param {Vec3} out the receiving vector, defaults to
|
|
796
|
+
* @param {Vec3} out the receiving vector, defaults to new vec3()
|
|
797
797
|
* @returns {Vec3} out
|
|
798
798
|
*/
|
|
799
|
-
scaleAndAdd(b, scale, out = index.ALWAYS_COPY ?
|
|
799
|
+
scaleAndAdd(b, scale, out = index.ALWAYS_COPY ? vec3() : this) {
|
|
800
800
|
out[0] = this[0] + b[0] * scale;
|
|
801
801
|
out[1] = this[1] + b[1] * scale;
|
|
802
802
|
out[2] = this[2] + b[2] * scale;
|
|
803
803
|
return out;
|
|
804
804
|
}
|
|
805
805
|
/**
|
|
806
|
-
* Returns
|
|
806
|
+
* Returns vec3 with each component set to its absolute value
|
|
807
807
|
*
|
|
808
|
-
* @param {Vec3} out the receiving vector, defaults to
|
|
808
|
+
* @param {Vec3} out the receiving vector, defaults to new vec3()
|
|
809
809
|
* @returns {Vec3} out
|
|
810
810
|
*/
|
|
811
|
-
abs(out = index.ALWAYS_COPY ?
|
|
811
|
+
abs(out = index.ALWAYS_COPY ? vec3() : this) {
|
|
812
812
|
out[0] = Math.abs(this[0]);
|
|
813
813
|
out[1] = Math.abs(this[1]);
|
|
814
814
|
out[2] = Math.abs(this[2]);
|
|
@@ -819,10 +819,10 @@ class Vec3 extends Float32Array {
|
|
|
819
819
|
*
|
|
820
820
|
* @param {Vec3 | number} min the lower bound (per-component or scalar)
|
|
821
821
|
* @param {Vec3 | number} max the upper bound (per-component or scalar)
|
|
822
|
-
* @param {Vec3} out the receiving vector, defaults to
|
|
822
|
+
* @param {Vec3} out the receiving vector, defaults to new vec3()
|
|
823
823
|
* @returns {Vec3} out
|
|
824
824
|
*/
|
|
825
|
-
clamp(min, max, out = index.ALWAYS_COPY ?
|
|
825
|
+
clamp(min, max, out = index.ALWAYS_COPY ? vec3() : this) {
|
|
826
826
|
const minX = typeof min === 'number' ? min : min[0];
|
|
827
827
|
const minY = typeof min === 'number' ? min : min[1];
|
|
828
828
|
const minZ = typeof min === 'number' ? min : min[2];
|
|
@@ -839,10 +839,10 @@ class Vec3 extends Float32Array {
|
|
|
839
839
|
*
|
|
840
840
|
* @param {Vec3} b the second operand
|
|
841
841
|
* @param {Vec3 | number} t interpolation amount (per-component or scalar)
|
|
842
|
-
* @param {Vec3} out the receiving vector, defaults to
|
|
842
|
+
* @param {Vec3} out the receiving vector, defaults to new vec3()
|
|
843
843
|
* @returns {Vec3} out
|
|
844
844
|
*/
|
|
845
|
-
mix(b, t, out = index.ALWAYS_COPY ?
|
|
845
|
+
mix(b, t, out = index.ALWAYS_COPY ? vec3() : this) {
|
|
846
846
|
if (typeof t === 'number') {
|
|
847
847
|
out[0] = this[0] + (b[0] - this[0]) * t;
|
|
848
848
|
out[1] = this[1] + (b[1] - this[1]) * t;
|
|
@@ -859,10 +859,10 @@ class Vec3 extends Float32Array {
|
|
|
859
859
|
* Generates a step function by comparing this vector to edge.
|
|
860
860
|
*
|
|
861
861
|
* @param {Vec3 | number} edge the edge value (per-component or scalar)
|
|
862
|
-
* @param {Vec3} out the receiving vector, defaults to
|
|
862
|
+
* @param {Vec3} out the receiving vector, defaults to new vec3()
|
|
863
863
|
* @returns {Vec3} out
|
|
864
864
|
*/
|
|
865
|
-
step(edge, out = index.ALWAYS_COPY ?
|
|
865
|
+
step(edge, out = index.ALWAYS_COPY ? vec3() : this) {
|
|
866
866
|
if (typeof edge === 'number') {
|
|
867
867
|
out[0] = this[0] < edge ? 0 : 1;
|
|
868
868
|
out[1] = this[1] < edge ? 0 : 1;
|
|
@@ -880,10 +880,10 @@ class Vec3 extends Float32Array {
|
|
|
880
880
|
*
|
|
881
881
|
* @param {Vec3 | number} edge0 the lower edge (per-component or scalar)
|
|
882
882
|
* @param {Vec3 | number} edge1 the upper edge (per-component or scalar)
|
|
883
|
-
* @param {Vec3} out the receiving vector, defaults to
|
|
883
|
+
* @param {Vec3} out the receiving vector, defaults to new vec3()
|
|
884
884
|
* @returns {Vec3} out
|
|
885
885
|
*/
|
|
886
|
-
smoothstep(edge0, edge1, out = index.ALWAYS_COPY ?
|
|
886
|
+
smoothstep(edge0, edge1, out = index.ALWAYS_COPY ? vec3() : this) {
|
|
887
887
|
const e0x = typeof edge0 === 'number' ? edge0 : edge0[0];
|
|
888
888
|
const e0y = typeof edge0 === 'number' ? edge0 : edge0[1];
|
|
889
889
|
const e0z = typeof edge0 === 'number' ? edge0 : edge0[2];
|
|
@@ -901,10 +901,10 @@ class Vec3 extends Float32Array {
|
|
|
901
901
|
/**
|
|
902
902
|
* Returns the fractional part of each component.
|
|
903
903
|
*
|
|
904
|
-
* @param {Vec3} out the receiving vector, defaults to
|
|
904
|
+
* @param {Vec3} out the receiving vector, defaults to new vec3()
|
|
905
905
|
* @returns {Vec3} out
|
|
906
906
|
*/
|
|
907
|
-
fract(out = index.ALWAYS_COPY ?
|
|
907
|
+
fract(out = index.ALWAYS_COPY ? vec3() : this) {
|
|
908
908
|
out[0] = this[0] - Math.floor(this[0]);
|
|
909
909
|
out[1] = this[1] - Math.floor(this[1]);
|
|
910
910
|
out[2] = this[2] - Math.floor(this[2]);
|
|
@@ -913,10 +913,10 @@ class Vec3 extends Float32Array {
|
|
|
913
913
|
/**
|
|
914
914
|
* Returns the sign of each component (-1, 0, or 1).
|
|
915
915
|
*
|
|
916
|
-
* @param {Vec3} out the receiving vector, defaults to
|
|
916
|
+
* @param {Vec3} out the receiving vector, defaults to new vec3()
|
|
917
917
|
* @returns {Vec3} out
|
|
918
918
|
*/
|
|
919
|
-
sign(out = index.ALWAYS_COPY ?
|
|
919
|
+
sign(out = index.ALWAYS_COPY ? vec3() : this) {
|
|
920
920
|
out[0] = this[0] > 0 ? 1 : this[0] < 0 ? -1 : 0;
|
|
921
921
|
out[1] = this[1] > 0 ? 1 : this[1] < 0 ? -1 : 0;
|
|
922
922
|
out[2] = this[2] > 0 ? 1 : this[2] < 0 ? -1 : 0;
|
|
@@ -925,10 +925,10 @@ class Vec3 extends Float32Array {
|
|
|
925
925
|
/**
|
|
926
926
|
* Clamps each component to [0, 1].
|
|
927
927
|
*
|
|
928
|
-
* @param {Vec3} out the receiving vector, defaults to
|
|
928
|
+
* @param {Vec3} out the receiving vector, defaults to new vec3()
|
|
929
929
|
* @returns {Vec3} out
|
|
930
930
|
*/
|
|
931
|
-
saturate(out = index.ALWAYS_COPY ?
|
|
931
|
+
saturate(out = index.ALWAYS_COPY ? vec3() : this) {
|
|
932
932
|
out[0] = Math.min(Math.max(this[0], 0), 1);
|
|
933
933
|
out[1] = Math.min(Math.max(this[1], 0), 1);
|
|
934
934
|
out[2] = Math.min(Math.max(this[2], 0), 1);
|
|
@@ -938,10 +938,10 @@ class Vec3 extends Float32Array {
|
|
|
938
938
|
* Transforms this vec3 with a Mat3
|
|
939
939
|
*
|
|
940
940
|
* @param {Mat3} m the 3x3 matrix to transform with
|
|
941
|
-
* @param {Vec3} out the receiving vector, defaults to
|
|
941
|
+
* @param {Vec3} out the receiving vector, defaults to new vec3()
|
|
942
942
|
* @returns {Vec3} out
|
|
943
943
|
*/
|
|
944
|
-
transformMat3(m, out = index.ALWAYS_COPY ?
|
|
944
|
+
transformMat3(m, out = index.ALWAYS_COPY ? vec3() : this) {
|
|
945
945
|
const x = this[0], y = this[1], z = this[2];
|
|
946
946
|
out[0] = x * m[0] + y * m[3] + z * m[6];
|
|
947
947
|
out[1] = x * m[1] + y * m[4] + z * m[7];
|
|
@@ -952,10 +952,10 @@ class Vec3 extends Float32Array {
|
|
|
952
952
|
* Transforms this vec3 with a Mat4 (as a point, w=1)
|
|
953
953
|
*
|
|
954
954
|
* @param {Mat4} m the 4x4 matrix to transform with
|
|
955
|
-
* @param {Vec3} out the receiving vector, defaults to
|
|
955
|
+
* @param {Vec3} out the receiving vector, defaults to new vec3()
|
|
956
956
|
* @returns {Vec3} out
|
|
957
957
|
*/
|
|
958
|
-
transformMat4(m, out = index.ALWAYS_COPY ?
|
|
958
|
+
transformMat4(m, out = index.ALWAYS_COPY ? vec3() : this) {
|
|
959
959
|
const x = this[0], y = this[1], z = this[2];
|
|
960
960
|
let w = m[3] * x + m[7] * y + m[11] * z + m[15];
|
|
961
961
|
w = w || 1.0;
|
|
@@ -968,10 +968,10 @@ class Vec3 extends Float32Array {
|
|
|
968
968
|
* Transforms this vec3 with a quaternion
|
|
969
969
|
*
|
|
970
970
|
* @param {Quat} q the quaternion to transform with
|
|
971
|
-
* @param {Vec3} out the receiving vector, defaults to
|
|
971
|
+
* @param {Vec3} out the receiving vector, defaults to new vec3()
|
|
972
972
|
* @returns {Vec3} out
|
|
973
973
|
*/
|
|
974
|
-
transformQuat(q, out = index.ALWAYS_COPY ?
|
|
974
|
+
transformQuat(q, out = index.ALWAYS_COPY ? vec3() : this) {
|
|
975
975
|
const qx = q[0], qy = q[1], qz = q[2], qw = q[3];
|
|
976
976
|
const x = this[0], y = this[1], z = this[2];
|
|
977
977
|
let uvx = qy * z - qz * y, uvy = qz * x - qx * z, uvz = qx * y - qy * x;
|
|
@@ -1005,6 +1005,7 @@ Vec3.prototype.neg = Vec3.prototype.negate;
|
|
|
1005
1005
|
Vec3.prototype.unaryMinus = Vec3.prototype.negate;
|
|
1006
1006
|
Vec3.prototype.sqrLen = Vec3.prototype.squaredLength;
|
|
1007
1007
|
Vec3.prototype.str = Vec3.prototype.toString;
|
|
1008
|
+
Vec3.prototype.normalized = Vec3.prototype.normalize;
|
|
1008
1009
|
Vec3.prototype.transformMat3x3 = Vec3.prototype.transformMat3;
|
|
1009
1010
|
Vec3.prototype.transformMat4x4 = Vec3.prototype.transformMat4;
|
|
1010
1011
|
const createVec3 = (...args) => {
|
|
@@ -1029,14 +1030,14 @@ const vec3 = createVec3;
|
|
|
1029
1030
|
* @extends Float32Array
|
|
1030
1031
|
*/
|
|
1031
1032
|
class Vec4 extends Float32Array {
|
|
1032
|
-
static get zero() { return
|
|
1033
|
-
static get Zero() { return
|
|
1034
|
-
static get ZERO() { return
|
|
1035
|
-
static get one() { return
|
|
1036
|
-
static get One() { return
|
|
1037
|
-
static get ONE() { return
|
|
1033
|
+
static get zero() { return vec4(0, 0, 0, 0); }
|
|
1034
|
+
static get Zero() { return vec4(0, 0, 0, 0); }
|
|
1035
|
+
static get ZERO() { return vec4(0, 0, 0, 0); }
|
|
1036
|
+
static get one() { return vec4(1, 1, 1, 1); }
|
|
1037
|
+
static get One() { return vec4(1, 1, 1, 1); }
|
|
1038
|
+
static get ONE() { return vec4(1, 1, 1, 1); }
|
|
1038
1039
|
/**
|
|
1039
|
-
* Creates a
|
|
1040
|
+
* Creates a vec4
|
|
1040
1041
|
*
|
|
1041
1042
|
* @param {Number} x X component, defaults to 0
|
|
1042
1043
|
* @param {Number} y Y component, defaults to 0
|
|
@@ -1062,10 +1063,10 @@ class Vec4 extends Float32Array {
|
|
|
1062
1063
|
* Adds two vec4's
|
|
1063
1064
|
*
|
|
1064
1065
|
* @param {Vec4 | Number} b the second operand
|
|
1065
|
-
* @param {Vec4} out the receiving vector, defaults to
|
|
1066
|
+
* @param {Vec4} out the receiving vector, defaults to new vec4()
|
|
1066
1067
|
* @returns {Vec4} out
|
|
1067
1068
|
*/
|
|
1068
|
-
plus(b, out = index.ALWAYS_COPY ?
|
|
1069
|
+
plus(b, out = index.ALWAYS_COPY ? vec4() : this) {
|
|
1069
1070
|
if (typeof b === 'number') {
|
|
1070
1071
|
out[0] = this[0] + b;
|
|
1071
1072
|
out[1] = this[1] + b;
|
|
@@ -1084,10 +1085,10 @@ class Vec4 extends Float32Array {
|
|
|
1084
1085
|
* Subtracts two vec4's
|
|
1085
1086
|
*
|
|
1086
1087
|
* @param {Vec4 | Number} b the second operand
|
|
1087
|
-
* @param {Vec4} out the receiving vector, defaults to
|
|
1088
|
+
* @param {Vec4} out the receiving vector, defaults to new vec4()
|
|
1088
1089
|
* @returns {Vec4} out
|
|
1089
1090
|
*/
|
|
1090
|
-
minus(b, out = index.ALWAYS_COPY ?
|
|
1091
|
+
minus(b, out = index.ALWAYS_COPY ? vec4() : this) {
|
|
1091
1092
|
if (typeof b === 'number') {
|
|
1092
1093
|
out[0] = this[0] - b;
|
|
1093
1094
|
out[1] = this[1] - b;
|
|
@@ -1106,10 +1107,10 @@ class Vec4 extends Float32Array {
|
|
|
1106
1107
|
* Multiplies two vec4's
|
|
1107
1108
|
*
|
|
1108
1109
|
* @param {Vec4 | Number} b the second operand
|
|
1109
|
-
* @param {Vec4} out the receiving vector, defaults to
|
|
1110
|
+
* @param {Vec4} out the receiving vector, defaults to new vec4()
|
|
1110
1111
|
* @returns {Vec4} out
|
|
1111
1112
|
*/
|
|
1112
|
-
mult(b, out = index.ALWAYS_COPY ?
|
|
1113
|
+
mult(b, out = index.ALWAYS_COPY ? vec4() : this) {
|
|
1113
1114
|
if (typeof b === 'number') {
|
|
1114
1115
|
out[0] = this[0] * b;
|
|
1115
1116
|
out[1] = this[1] * b;
|
|
@@ -1128,10 +1129,10 @@ class Vec4 extends Float32Array {
|
|
|
1128
1129
|
* Divides two vec4's
|
|
1129
1130
|
*
|
|
1130
1131
|
* @param {Vec4 | Number} b the second operand
|
|
1131
|
-
* @param {Vec4} out the receiving vector, defaults to
|
|
1132
|
+
* @param {Vec4} out the receiving vector, defaults to new vec4()
|
|
1132
1133
|
* @returns {Vec4} out
|
|
1133
1134
|
*/
|
|
1134
|
-
div(b, out = index.ALWAYS_COPY ?
|
|
1135
|
+
div(b, out = index.ALWAYS_COPY ? vec4() : this) {
|
|
1135
1136
|
if (typeof b === 'number') {
|
|
1136
1137
|
out[0] = this[0] / b;
|
|
1137
1138
|
out[1] = this[1] / b;
|
|
@@ -1146,7 +1147,7 @@ class Vec4 extends Float32Array {
|
|
|
1146
1147
|
}
|
|
1147
1148
|
return out;
|
|
1148
1149
|
}
|
|
1149
|
-
invDiv(b, out = index.ALWAYS_COPY ?
|
|
1150
|
+
invDiv(b, out = index.ALWAYS_COPY ? vec4() : this) {
|
|
1150
1151
|
if (typeof b === 'number') {
|
|
1151
1152
|
out[0] = b / this[0];
|
|
1152
1153
|
out[1] = b / this[1];
|
|
@@ -1164,17 +1165,17 @@ class Vec4 extends Float32Array {
|
|
|
1164
1165
|
/**
|
|
1165
1166
|
* Negates the components of a vec4
|
|
1166
1167
|
*
|
|
1167
|
-
* @param {Vec4} out the receiving vector, defaults to
|
|
1168
|
+
* @param {Vec4} out the receiving vector, defaults to new vec4()
|
|
1168
1169
|
* @returns {Vec4} out
|
|
1169
1170
|
*/
|
|
1170
|
-
negate(out = index.ALWAYS_COPY ?
|
|
1171
|
+
negate(out = index.ALWAYS_COPY ? vec4() : this) {
|
|
1171
1172
|
out[0] = -this[0];
|
|
1172
1173
|
out[1] = -this[1];
|
|
1173
1174
|
out[2] = -this[2];
|
|
1174
1175
|
out[3] = -this[3];
|
|
1175
1176
|
return out;
|
|
1176
1177
|
}
|
|
1177
|
-
unaryPlus(out = index.ALWAYS_COPY ?
|
|
1178
|
+
unaryPlus(out = index.ALWAYS_COPY ? vec4() : this) {
|
|
1178
1179
|
if (!out.equals(this)) {
|
|
1179
1180
|
out[0] = this[0];
|
|
1180
1181
|
out[1] = this[1];
|
|
@@ -1186,10 +1187,29 @@ class Vec4 extends Float32Array {
|
|
|
1186
1187
|
/**
|
|
1187
1188
|
* Normalizes a vec4
|
|
1188
1189
|
*
|
|
1189
|
-
* @param {Vec4}
|
|
1190
|
+
* @param {Vec4} v vector to normalize
|
|
1191
|
+
* @param {Vec4} out the receiving vector, defaults to new vec4()
|
|
1192
|
+
* @returns {Vec4} out
|
|
1193
|
+
*/
|
|
1194
|
+
static normalize(v, out = vec4()) {
|
|
1195
|
+
const x = v[0], y = v[1], z = v[2], w = v[3];
|
|
1196
|
+
let len = x * x + y * y + z * z + w * w;
|
|
1197
|
+
if (len > 0) {
|
|
1198
|
+
len = 1.0 / Math.sqrt(len);
|
|
1199
|
+
}
|
|
1200
|
+
out[0] = x * len;
|
|
1201
|
+
out[1] = y * len;
|
|
1202
|
+
out[2] = z * len;
|
|
1203
|
+
out[3] = w * len;
|
|
1204
|
+
return out;
|
|
1205
|
+
}
|
|
1206
|
+
/**
|
|
1207
|
+
* Normalizes a vec4
|
|
1208
|
+
*
|
|
1209
|
+
* @param {Vec4} out the receiving vector, defaults to new vec4()
|
|
1190
1210
|
* @returns {Vec4} out
|
|
1191
1211
|
*/
|
|
1192
|
-
normalize(out = index.ALWAYS_COPY ?
|
|
1212
|
+
normalize(out = index.ALWAYS_COPY ? vec4() : this) {
|
|
1193
1213
|
const x = this[0], y = this[1], z = this[2], w = this[3];
|
|
1194
1214
|
let len = x * x + y * y + z * z + w * w;
|
|
1195
1215
|
if (len > 0) {
|
|
@@ -1241,10 +1261,10 @@ class Vec4 extends Float32Array {
|
|
|
1241
1261
|
/**
|
|
1242
1262
|
* Math.floor the components of a vec4
|
|
1243
1263
|
*
|
|
1244
|
-
* @param {Vec4} out the receiving vector, defaults to
|
|
1264
|
+
* @param {Vec4} out the receiving vector, defaults to new vec4()
|
|
1245
1265
|
* @returns {Vec4} out
|
|
1246
1266
|
*/
|
|
1247
|
-
floor(out = index.ALWAYS_COPY ?
|
|
1267
|
+
floor(out = index.ALWAYS_COPY ? vec4() : this) {
|
|
1248
1268
|
out[0] = Math.floor(this[0]);
|
|
1249
1269
|
out[1] = Math.floor(this[1]);
|
|
1250
1270
|
out[2] = Math.floor(this[2]);
|
|
@@ -1254,10 +1274,10 @@ class Vec4 extends Float32Array {
|
|
|
1254
1274
|
/**
|
|
1255
1275
|
* Math.round the components of a vec4
|
|
1256
1276
|
*
|
|
1257
|
-
* @param {Vec4} out the receiving vector, defaults to
|
|
1277
|
+
* @param {Vec4} out the receiving vector, defaults to new vec4()
|
|
1258
1278
|
* @returns {Vec4} out
|
|
1259
1279
|
*/
|
|
1260
|
-
round(out = index.ALWAYS_COPY ?
|
|
1280
|
+
round(out = index.ALWAYS_COPY ? vec4() : this) {
|
|
1261
1281
|
out[0] = Math.round(this[0]);
|
|
1262
1282
|
out[1] = Math.round(this[1]);
|
|
1263
1283
|
out[2] = Math.round(this[2]);
|
|
@@ -1267,10 +1287,10 @@ class Vec4 extends Float32Array {
|
|
|
1267
1287
|
/**
|
|
1268
1288
|
* Math.ceil the components of a vec4
|
|
1269
1289
|
*
|
|
1270
|
-
* @param {Vec4} out the receiving vector, defaults to
|
|
1290
|
+
* @param {Vec4} out the receiving vector, defaults to new vec4()
|
|
1271
1291
|
* @returns {Vec4} out
|
|
1272
1292
|
*/
|
|
1273
|
-
ceil(out = index.ALWAYS_COPY ?
|
|
1293
|
+
ceil(out = index.ALWAYS_COPY ? vec4() : this) {
|
|
1274
1294
|
out[0] = Math.ceil(this[0]);
|
|
1275
1295
|
out[1] = Math.ceil(this[1]);
|
|
1276
1296
|
out[2] = Math.ceil(this[2]);
|
|
@@ -1280,10 +1300,10 @@ class Vec4 extends Float32Array {
|
|
|
1280
1300
|
/**
|
|
1281
1301
|
* Returns the inverse of the components of a vec4
|
|
1282
1302
|
*
|
|
1283
|
-
* @param {Vec4} out the receiving vector, defaults to
|
|
1303
|
+
* @param {Vec4} out the receiving vector, defaults to new vec4()
|
|
1284
1304
|
* @returns {Vec4} out
|
|
1285
1305
|
*/
|
|
1286
|
-
inverse(out = index.ALWAYS_COPY ?
|
|
1306
|
+
inverse(out = index.ALWAYS_COPY ? vec4() : this) {
|
|
1287
1307
|
out[0] = 1.0 / this[0];
|
|
1288
1308
|
out[1] = 1.0 / this[1];
|
|
1289
1309
|
out[2] = 1.0 / this[2];
|
|
@@ -1291,12 +1311,12 @@ class Vec4 extends Float32Array {
|
|
|
1291
1311
|
return out;
|
|
1292
1312
|
}
|
|
1293
1313
|
/**
|
|
1294
|
-
* Creates a
|
|
1314
|
+
* Creates a vec4 initialized with values from a vector
|
|
1295
1315
|
*
|
|
1296
|
-
* @returns {Vec4} a
|
|
1316
|
+
* @returns {Vec4} a vec4
|
|
1297
1317
|
*/
|
|
1298
1318
|
clone() {
|
|
1299
|
-
return
|
|
1319
|
+
return vec4(this[0], this[1], this[2], this[3]);
|
|
1300
1320
|
}
|
|
1301
1321
|
/**
|
|
1302
1322
|
* Returns a string representation of a vec4
|
|
@@ -1310,10 +1330,10 @@ class Vec4 extends Float32Array {
|
|
|
1310
1330
|
* Generates a random vector with the given scale
|
|
1311
1331
|
*
|
|
1312
1332
|
* @param {Number} scale length of the resulting vector, defaults to 1.0
|
|
1313
|
-
* @param {Vec4} out the receiving vector, defaults to new
|
|
1333
|
+
* @param {Vec4} out the receiving vector, defaults to new vec4()
|
|
1314
1334
|
* @returns {Vec4} out
|
|
1315
1335
|
*/
|
|
1316
|
-
static random(scale = 1.0, out =
|
|
1336
|
+
static random(scale = 1.0, out = vec4()) {
|
|
1317
1337
|
// Marsaglia, George. Choosing a Point from the Surface of a
|
|
1318
1338
|
// Sphere. Ann. Math. Statist. 43 (1972), no. 2, 645--646.
|
|
1319
1339
|
// http://projecteuclid.org/euclid.aoms/1177692644;
|
|
@@ -1351,10 +1371,10 @@ class Vec4 extends Float32Array {
|
|
|
1351
1371
|
* @param {Vec4} u the first operand
|
|
1352
1372
|
* @param {Vec4} v the second operand
|
|
1353
1373
|
* @param {Vec4} w the third operand
|
|
1354
|
-
* @param {Vec4} out the receiving vector, defaults to new
|
|
1374
|
+
* @param {Vec4} out the receiving vector, defaults to new vec4()
|
|
1355
1375
|
* @returns {Vec4} out
|
|
1356
1376
|
*/
|
|
1357
|
-
static cross(u, v, w, out =
|
|
1377
|
+
static cross(u, v, w, out = vec4()) {
|
|
1358
1378
|
const A = v[0] * w[1] - v[1] * w[0], B = v[0] * w[2] - v[2] * w[0], C = v[0] * w[3] - v[3] * w[0], D = v[1] * w[2] - v[2] * w[1], E = v[1] * w[3] - v[3] * w[1], F = v[2] * w[3] - v[3] * w[2];
|
|
1359
1379
|
const G = u[0], H = u[1], I = u[2], J = u[3];
|
|
1360
1380
|
out[0] = H * F - I * E + J * D;
|
|
@@ -1397,10 +1417,10 @@ class Vec4 extends Float32Array {
|
|
|
1397
1417
|
* @param {Vec4} a the first operand
|
|
1398
1418
|
* @param {Vec4} b the second operand
|
|
1399
1419
|
* @param {Number} t interpolation amount, in the range [0-1], between the two inputs
|
|
1400
|
-
* @param {Vec4} out the receiving vector, defaults to new
|
|
1420
|
+
* @param {Vec4} out the receiving vector, defaults to new vec4()
|
|
1401
1421
|
* @returns {Vec4} out
|
|
1402
1422
|
*/
|
|
1403
|
-
static lerp(a, b, t, out =
|
|
1423
|
+
static lerp(a, b, t, out = vec4()) {
|
|
1404
1424
|
const ax = a[0], ay = a[1], az = a[2], aw = a[3];
|
|
1405
1425
|
out[0] = ax + (b[0] - ax) * t;
|
|
1406
1426
|
out[1] = ay + (b[1] - ay) * t;
|
|
@@ -1413,10 +1433,10 @@ class Vec4 extends Float32Array {
|
|
|
1413
1433
|
*
|
|
1414
1434
|
* @param {Vec4} a the first operand
|
|
1415
1435
|
* @param {Vec4} b the second operand
|
|
1416
|
-
* @param {Vec4} out the receiving vector, defaults to new
|
|
1436
|
+
* @param {Vec4} out the receiving vector, defaults to new vec4()
|
|
1417
1437
|
* @returns {Vec4} out
|
|
1418
1438
|
*/
|
|
1419
|
-
static max(a, b, out =
|
|
1439
|
+
static max(a, b, out = vec4()) {
|
|
1420
1440
|
out[0] = Math.max(a[0], b[0]);
|
|
1421
1441
|
out[1] = Math.max(a[1], b[1]);
|
|
1422
1442
|
out[2] = Math.max(a[2], b[2]);
|
|
@@ -1428,10 +1448,10 @@ class Vec4 extends Float32Array {
|
|
|
1428
1448
|
*
|
|
1429
1449
|
* @param {Vec4} a the first operand
|
|
1430
1450
|
* @param {Vec4} b the second operand
|
|
1431
|
-
* @param {Vec4} out the receiving vector, defaults to new
|
|
1451
|
+
* @param {Vec4} out the receiving vector, defaults to new vec4()
|
|
1432
1452
|
* @returns {Vec4} out
|
|
1433
1453
|
*/
|
|
1434
|
-
static min(a, b, out =
|
|
1454
|
+
static min(a, b, out = vec4()) {
|
|
1435
1455
|
out[0] = Math.min(a[0], b[0]);
|
|
1436
1456
|
out[1] = Math.min(a[1], b[1]);
|
|
1437
1457
|
out[2] = Math.min(a[2], b[2]);
|
|
@@ -1447,7 +1467,7 @@ class Vec4 extends Float32Array {
|
|
|
1447
1467
|
* @param {Vec4} out the receiving vector
|
|
1448
1468
|
* @returns {Vec4} out
|
|
1449
1469
|
*/
|
|
1450
|
-
static clamp(v, min, max, out =
|
|
1470
|
+
static clamp(v, min, max, out = vec4()) {
|
|
1451
1471
|
const minX = typeof min === 'number' ? min : min[0];
|
|
1452
1472
|
const minY = typeof min === 'number' ? min : min[1];
|
|
1453
1473
|
const minZ = typeof min === 'number' ? min : min[2];
|
|
@@ -1471,7 +1491,7 @@ class Vec4 extends Float32Array {
|
|
|
1471
1491
|
* @param {Vec4} out the receiving vector
|
|
1472
1492
|
* @returns {Vec4} out
|
|
1473
1493
|
*/
|
|
1474
|
-
static mix(a, b, t, out =
|
|
1494
|
+
static mix(a, b, t, out = vec4()) {
|
|
1475
1495
|
if (typeof t === 'number') {
|
|
1476
1496
|
out[0] = a[0] + (b[0] - a[0]) * t;
|
|
1477
1497
|
out[1] = a[1] + (b[1] - a[1]) * t;
|
|
@@ -1495,7 +1515,7 @@ class Vec4 extends Float32Array {
|
|
|
1495
1515
|
* @param {Vec4} out the receiving vector
|
|
1496
1516
|
* @returns {Vec4} out
|
|
1497
1517
|
*/
|
|
1498
|
-
static smoothstep(edge0, edge1, v, out =
|
|
1518
|
+
static smoothstep(edge0, edge1, v, out = vec4()) {
|
|
1499
1519
|
const e0x = typeof edge0 === 'number' ? edge0 : edge0[0];
|
|
1500
1520
|
const e0y = typeof edge0 === 'number' ? edge0 : edge0[1];
|
|
1501
1521
|
const e0z = typeof edge0 === 'number' ? edge0 : edge0[2];
|
|
@@ -1522,7 +1542,7 @@ class Vec4 extends Float32Array {
|
|
|
1522
1542
|
* @param {Vec4} out the receiving vector
|
|
1523
1543
|
* @returns {Vec4} out
|
|
1524
1544
|
*/
|
|
1525
|
-
scaleAndAdd(b, scale, out = index.ALWAYS_COPY ?
|
|
1545
|
+
scaleAndAdd(b, scale, out = index.ALWAYS_COPY ? vec4() : this) {
|
|
1526
1546
|
out[0] = this[0] + b[0] * scale;
|
|
1527
1547
|
out[1] = this[1] + b[1] * scale;
|
|
1528
1548
|
out[2] = this[2] + b[2] * scale;
|
|
@@ -1535,7 +1555,7 @@ class Vec4 extends Float32Array {
|
|
|
1535
1555
|
* @param {Vec4} out the receiving vector
|
|
1536
1556
|
* @returns {Vec4} out
|
|
1537
1557
|
*/
|
|
1538
|
-
abs(out = index.ALWAYS_COPY ?
|
|
1558
|
+
abs(out = index.ALWAYS_COPY ? vec4() : this) {
|
|
1539
1559
|
out[0] = Math.abs(this[0]);
|
|
1540
1560
|
out[1] = Math.abs(this[1]);
|
|
1541
1561
|
out[2] = Math.abs(this[2]);
|
|
@@ -1550,7 +1570,7 @@ class Vec4 extends Float32Array {
|
|
|
1550
1570
|
* @param {Vec4} out the receiving vector
|
|
1551
1571
|
* @returns {Vec4} out
|
|
1552
1572
|
*/
|
|
1553
|
-
clamp(min, max, out = index.ALWAYS_COPY ?
|
|
1573
|
+
clamp(min, max, out = index.ALWAYS_COPY ? vec4() : this) {
|
|
1554
1574
|
const minX = typeof min === 'number' ? min : min[0];
|
|
1555
1575
|
const minY = typeof min === 'number' ? min : min[1];
|
|
1556
1576
|
const minZ = typeof min === 'number' ? min : min[2];
|
|
@@ -1573,7 +1593,7 @@ class Vec4 extends Float32Array {
|
|
|
1573
1593
|
* @param {Vec4} out the receiving vector
|
|
1574
1594
|
* @returns {Vec4} out
|
|
1575
1595
|
*/
|
|
1576
|
-
mix(b, t, out = index.ALWAYS_COPY ?
|
|
1596
|
+
mix(b, t, out = index.ALWAYS_COPY ? vec4() : this) {
|
|
1577
1597
|
if (typeof t === 'number') {
|
|
1578
1598
|
out[0] = this[0] + (b[0] - this[0]) * t;
|
|
1579
1599
|
out[1] = this[1] + (b[1] - this[1]) * t;
|
|
@@ -1595,7 +1615,7 @@ class Vec4 extends Float32Array {
|
|
|
1595
1615
|
* @param {Vec4} out the receiving vector
|
|
1596
1616
|
* @returns {Vec4} out
|
|
1597
1617
|
*/
|
|
1598
|
-
step(edge, out = index.ALWAYS_COPY ?
|
|
1618
|
+
step(edge, out = index.ALWAYS_COPY ? vec4() : this) {
|
|
1599
1619
|
if (typeof edge === 'number') {
|
|
1600
1620
|
out[0] = this[0] < edge ? 0 : 1;
|
|
1601
1621
|
out[1] = this[1] < edge ? 0 : 1;
|
|
@@ -1618,7 +1638,7 @@ class Vec4 extends Float32Array {
|
|
|
1618
1638
|
* @param {Vec4} out the receiving vector
|
|
1619
1639
|
* @returns {Vec4} out
|
|
1620
1640
|
*/
|
|
1621
|
-
smoothstep(edge0, edge1, out = index.ALWAYS_COPY ?
|
|
1641
|
+
smoothstep(edge0, edge1, out = index.ALWAYS_COPY ? vec4() : this) {
|
|
1622
1642
|
const e0x = typeof edge0 === 'number' ? edge0 : edge0[0];
|
|
1623
1643
|
const e0y = typeof edge0 === 'number' ? edge0 : edge0[1];
|
|
1624
1644
|
const e0z = typeof edge0 === 'number' ? edge0 : edge0[2];
|
|
@@ -1643,7 +1663,7 @@ class Vec4 extends Float32Array {
|
|
|
1643
1663
|
* @param {Vec4} out the receiving vector
|
|
1644
1664
|
* @returns {Vec4} out
|
|
1645
1665
|
*/
|
|
1646
|
-
fract(out = index.ALWAYS_COPY ?
|
|
1666
|
+
fract(out = index.ALWAYS_COPY ? vec4() : this) {
|
|
1647
1667
|
out[0] = this[0] - Math.floor(this[0]);
|
|
1648
1668
|
out[1] = this[1] - Math.floor(this[1]);
|
|
1649
1669
|
out[2] = this[2] - Math.floor(this[2]);
|
|
@@ -1656,7 +1676,7 @@ class Vec4 extends Float32Array {
|
|
|
1656
1676
|
* @param {Vec4} out the receiving vector
|
|
1657
1677
|
* @returns {Vec4} out
|
|
1658
1678
|
*/
|
|
1659
|
-
sign(out = index.ALWAYS_COPY ?
|
|
1679
|
+
sign(out = index.ALWAYS_COPY ? vec4() : this) {
|
|
1660
1680
|
out[0] = this[0] > 0 ? 1 : this[0] < 0 ? -1 : 0;
|
|
1661
1681
|
out[1] = this[1] > 0 ? 1 : this[1] < 0 ? -1 : 0;
|
|
1662
1682
|
out[2] = this[2] > 0 ? 1 : this[2] < 0 ? -1 : 0;
|
|
@@ -1669,7 +1689,7 @@ class Vec4 extends Float32Array {
|
|
|
1669
1689
|
* @param {Vec4} out the receiving vector
|
|
1670
1690
|
* @returns {Vec4} out
|
|
1671
1691
|
*/
|
|
1672
|
-
saturate(out = index.ALWAYS_COPY ?
|
|
1692
|
+
saturate(out = index.ALWAYS_COPY ? vec4() : this) {
|
|
1673
1693
|
out[0] = Math.min(Math.max(this[0], 0), 1);
|
|
1674
1694
|
out[1] = Math.min(Math.max(this[1], 0), 1);
|
|
1675
1695
|
out[2] = Math.min(Math.max(this[2], 0), 1);
|
|
@@ -1683,7 +1703,7 @@ class Vec4 extends Float32Array {
|
|
|
1683
1703
|
* @param {Vec4} out the receiving vector
|
|
1684
1704
|
* @returns {Vec4} out
|
|
1685
1705
|
*/
|
|
1686
|
-
transformMat4(m, out = index.ALWAYS_COPY ?
|
|
1706
|
+
transformMat4(m, out = index.ALWAYS_COPY ? vec4() : this) {
|
|
1687
1707
|
const x = this[0], y = this[1], z = this[2], w = this[3];
|
|
1688
1708
|
out[0] = m[0] * x + m[4] * y + m[8] * z + m[12] * w;
|
|
1689
1709
|
out[1] = m[1] * x + m[5] * y + m[9] * z + m[13] * w;
|
|
@@ -1698,7 +1718,7 @@ class Vec4 extends Float32Array {
|
|
|
1698
1718
|
* @param {Vec4} out the receiving vector
|
|
1699
1719
|
* @returns {Vec4} out
|
|
1700
1720
|
*/
|
|
1701
|
-
transformQuat(q, out = index.ALWAYS_COPY ?
|
|
1721
|
+
transformQuat(q, out = index.ALWAYS_COPY ? vec4() : this) {
|
|
1702
1722
|
const qx = q[0], qy = q[1], qz = q[2], qw = q[3];
|
|
1703
1723
|
const x = this[0], y = this[1], z = this[2];
|
|
1704
1724
|
let uvx = qy * z - qz * y, uvy = qz * x - qx * z, uvz = qx * y - qy * x;
|
|
@@ -1725,7 +1745,7 @@ class Vec4 extends Float32Array {
|
|
|
1725
1745
|
* @param {Vec4} out the receiving vector
|
|
1726
1746
|
* @returns {Vec4} out
|
|
1727
1747
|
*/
|
|
1728
|
-
static scaleAndAdd(a, b, scale, out =
|
|
1748
|
+
static scaleAndAdd(a, b, scale, out = vec4()) {
|
|
1729
1749
|
out[0] = a[0] + b[0] * scale;
|
|
1730
1750
|
out[1] = a[1] + b[1] * scale;
|
|
1731
1751
|
out[2] = a[2] + b[2] * scale;
|
|
@@ -1749,6 +1769,7 @@ Vec4.prototype.neg = Vec4.prototype.negate;
|
|
|
1749
1769
|
Vec4.prototype.unaryMinus = Vec4.prototype.negate;
|
|
1750
1770
|
Vec4.prototype.sqrLen = Vec4.prototype.squaredLength;
|
|
1751
1771
|
Vec4.prototype.str = Vec4.prototype.toString;
|
|
1772
|
+
Vec4.prototype.normalized = Vec4.prototype.normalize;
|
|
1752
1773
|
Vec4.prototype.transformMat4x4 = Vec4.prototype.transformMat4;
|
|
1753
1774
|
const createVec4 = (...args) => {
|
|
1754
1775
|
const out = new Vec4();
|
|
@@ -1834,12 +1855,12 @@ function defineSwizzles(prototype, N = 4, S = ['xyzw', 'rgba', 'stpq', 'uv']) {
|
|
|
1834
1855
|
* @extends Float32Array
|
|
1835
1856
|
*/
|
|
1836
1857
|
class Vec2 extends Float32Array {
|
|
1837
|
-
static get zero() { return
|
|
1838
|
-
static get Zero() { return
|
|
1839
|
-
static get ZERO() { return
|
|
1840
|
-
static get one() { return
|
|
1841
|
-
static get One() { return
|
|
1842
|
-
static get ONE() { return
|
|
1858
|
+
static get zero() { return vec2(0, 0); }
|
|
1859
|
+
static get Zero() { return vec2(0, 0); }
|
|
1860
|
+
static get ZERO() { return vec2(0, 0); }
|
|
1861
|
+
static get one() { return vec2(1, 1); }
|
|
1862
|
+
static get One() { return vec2(1, 1); }
|
|
1863
|
+
static get ONE() { return vec2(1, 1); }
|
|
1843
1864
|
/**
|
|
1844
1865
|
* Creates a new Vec2 initialized with the given values
|
|
1845
1866
|
*
|
|
@@ -1859,10 +1880,10 @@ class Vec2 extends Float32Array {
|
|
|
1859
1880
|
* Adds two vec2's
|
|
1860
1881
|
*
|
|
1861
1882
|
* @param {Vec2 | Number} b the second operand
|
|
1862
|
-
* @param {Vec2} out the receiving vector, defaults to
|
|
1883
|
+
* @param {Vec2} out the receiving vector, defaults to new vec2()
|
|
1863
1884
|
* @returns {Vec2} out
|
|
1864
1885
|
*/
|
|
1865
|
-
plus(b, out = index.ALWAYS_COPY ?
|
|
1886
|
+
plus(b, out = index.ALWAYS_COPY ? vec2() : this) {
|
|
1866
1887
|
if (typeof b === 'number') {
|
|
1867
1888
|
out[0] = this[0] + b;
|
|
1868
1889
|
out[1] = this[1] + b;
|
|
@@ -1877,10 +1898,10 @@ class Vec2 extends Float32Array {
|
|
|
1877
1898
|
* Subtracts vector b from a vector
|
|
1878
1899
|
*
|
|
1879
1900
|
* @param {Vec2 | Number} b the second operand
|
|
1880
|
-
* @param {Vec2} out the receiving vector, defaults to
|
|
1901
|
+
* @param {Vec2} out the receiving vector, defaults to new vec2()
|
|
1881
1902
|
* @returns {Vec2} out
|
|
1882
1903
|
*/
|
|
1883
|
-
minus(b, out = index.ALWAYS_COPY ?
|
|
1904
|
+
minus(b, out = index.ALWAYS_COPY ? vec2() : this) {
|
|
1884
1905
|
if (typeof b === 'number') {
|
|
1885
1906
|
out[0] = this[0] - b;
|
|
1886
1907
|
out[1] = this[1] - b;
|
|
@@ -1895,10 +1916,10 @@ class Vec2 extends Float32Array {
|
|
|
1895
1916
|
* Multiplies two vec2's component-wise
|
|
1896
1917
|
*
|
|
1897
1918
|
* @param {Vec2 | Number} b the second operand
|
|
1898
|
-
* @param {Vec2} out the receiving vector, defaults to
|
|
1919
|
+
* @param {Vec2} out the receiving vector, defaults to new vec2()
|
|
1899
1920
|
* @returns {Vec2} out
|
|
1900
1921
|
*/
|
|
1901
|
-
mult(b, out = index.ALWAYS_COPY ?
|
|
1922
|
+
mult(b, out = index.ALWAYS_COPY ? vec2() : this) {
|
|
1902
1923
|
if (typeof b === 'number') {
|
|
1903
1924
|
out[0] = this[0] * b;
|
|
1904
1925
|
out[1] = this[1] * b;
|
|
@@ -1913,10 +1934,10 @@ class Vec2 extends Float32Array {
|
|
|
1913
1934
|
* Divides two vec2's component-wise
|
|
1914
1935
|
*
|
|
1915
1936
|
* @param {Vec2 | Number} b the second operand
|
|
1916
|
-
* @param {Vec2} out the receiving vector, defaults to
|
|
1937
|
+
* @param {Vec2} out the receiving vector, defaults to new vec2()
|
|
1917
1938
|
* @returns {Vec2} out
|
|
1918
1939
|
*/
|
|
1919
|
-
div(b, out = index.ALWAYS_COPY ?
|
|
1940
|
+
div(b, out = index.ALWAYS_COPY ? vec2() : this) {
|
|
1920
1941
|
if (typeof b === 'number') {
|
|
1921
1942
|
out[0] = this[0] / b;
|
|
1922
1943
|
out[1] = this[1] / b;
|
|
@@ -1931,10 +1952,10 @@ class Vec2 extends Float32Array {
|
|
|
1931
1952
|
* Divides this vector by argument
|
|
1932
1953
|
*
|
|
1933
1954
|
* @param {Vec2 | Number} a the first operand
|
|
1934
|
-
* @param {Vec2} out the receiving vector, defaults to
|
|
1955
|
+
* @param {Vec2} out the receiving vector, defaults to new vec2()
|
|
1935
1956
|
* @returns {Vec2} out
|
|
1936
1957
|
*/
|
|
1937
|
-
invDiv(a, out = index.ALWAYS_COPY ?
|
|
1958
|
+
invDiv(a, out = index.ALWAYS_COPY ? vec2() : this) {
|
|
1938
1959
|
if (typeof a === 'number') {
|
|
1939
1960
|
out[0] = a / this[0];
|
|
1940
1961
|
out[1] = a / this[1];
|
|
@@ -1949,10 +1970,10 @@ class Vec2 extends Float32Array {
|
|
|
1949
1970
|
* Remainder of this divided by argument
|
|
1950
1971
|
*
|
|
1951
1972
|
* @param {Vec2 | Number} a the first operand
|
|
1952
|
-
* @param {Vec2} out the receiving vector, defaults to
|
|
1973
|
+
* @param {Vec2} out the receiving vector, defaults to new vec2()
|
|
1953
1974
|
* @returns {Vec2} out
|
|
1954
1975
|
*/
|
|
1955
|
-
rem(b, out = index.ALWAYS_COPY ?
|
|
1976
|
+
rem(b, out = index.ALWAYS_COPY ? vec2() : this) {
|
|
1956
1977
|
if (typeof b === 'number') {
|
|
1957
1978
|
out[0] = this[0] % b;
|
|
1958
1979
|
out[1] = this[1] % b;
|
|
@@ -1966,15 +1987,15 @@ class Vec2 extends Float32Array {
|
|
|
1966
1987
|
/**
|
|
1967
1988
|
* Negates the components of a vec2
|
|
1968
1989
|
*
|
|
1969
|
-
* @param {Vec2} out the receiving vector, defaults to
|
|
1990
|
+
* @param {Vec2} out the receiving vector, defaults to new vec2()
|
|
1970
1991
|
* @returns {Vec2} out
|
|
1971
1992
|
*/
|
|
1972
|
-
negate(out = index.ALWAYS_COPY ?
|
|
1993
|
+
negate(out = index.ALWAYS_COPY ? vec2() : this) {
|
|
1973
1994
|
out[0] = -this[0];
|
|
1974
1995
|
out[1] = -this[1];
|
|
1975
1996
|
return out;
|
|
1976
1997
|
}
|
|
1977
|
-
unaryPlus(out = index.ALWAYS_COPY ?
|
|
1998
|
+
unaryPlus(out = index.ALWAYS_COPY ? vec2() : this) {
|
|
1978
1999
|
if (!out.equals(this)) {
|
|
1979
2000
|
out[0] = this[0];
|
|
1980
2001
|
out[1] = this[1];
|
|
@@ -1982,11 +2003,28 @@ class Vec2 extends Float32Array {
|
|
|
1982
2003
|
return out;
|
|
1983
2004
|
}
|
|
1984
2005
|
/**
|
|
1985
|
-
* Normalize a vector to unit length.
|
|
2006
|
+
* Normalize a vector to unit length.
|
|
1986
2007
|
*
|
|
2008
|
+
* @param {Vec2} out the receiving vector, defaults to new vec2()
|
|
1987
2009
|
* @returns {Vec2} this
|
|
1988
2010
|
*/
|
|
1989
|
-
normalize(out =
|
|
2011
|
+
static normalize(v, out = vec2()) {
|
|
2012
|
+
const x = v[0], y = v[1];
|
|
2013
|
+
let len = x * x + y * y;
|
|
2014
|
+
if (len > 0) {
|
|
2015
|
+
len = 1.0 / Math.sqrt(len);
|
|
2016
|
+
}
|
|
2017
|
+
out[0] = x * len;
|
|
2018
|
+
out[1] = y * len;
|
|
2019
|
+
return out;
|
|
2020
|
+
}
|
|
2021
|
+
/**
|
|
2022
|
+
* Normalize a vector to unit length.
|
|
2023
|
+
*
|
|
2024
|
+
* @param {Vec2} out the receiving vector, defaults to new vec2()
|
|
2025
|
+
* @returns {Vec2} this
|
|
2026
|
+
*/
|
|
2027
|
+
normalize(out = index.ALWAYS_COPY ? vec2() : this) {
|
|
1990
2028
|
const x = this[0], y = this[1];
|
|
1991
2029
|
let len = x * x + y * y;
|
|
1992
2030
|
if (len > 0) {
|
|
@@ -2036,10 +2074,10 @@ class Vec2 extends Float32Array {
|
|
|
2036
2074
|
/**
|
|
2037
2075
|
* Math.floor the components of a vec2
|
|
2038
2076
|
*
|
|
2039
|
-
* @param {Vec2} out the receiving vector, defaults to
|
|
2077
|
+
* @param {Vec2} out the receiving vector, defaults to new vec2()
|
|
2040
2078
|
* @returns {Vec2} out
|
|
2041
2079
|
*/
|
|
2042
|
-
floor(out = index.ALWAYS_COPY ?
|
|
2080
|
+
floor(out = index.ALWAYS_COPY ? vec2() : this) {
|
|
2043
2081
|
out[0] = Math.floor(this[0]);
|
|
2044
2082
|
out[1] = Math.floor(this[1]);
|
|
2045
2083
|
return out;
|
|
@@ -2047,10 +2085,10 @@ class Vec2 extends Float32Array {
|
|
|
2047
2085
|
/**
|
|
2048
2086
|
* Math.round the components of a vec2
|
|
2049
2087
|
*
|
|
2050
|
-
* @param {Vec2} out the receiving vector, defaults to
|
|
2088
|
+
* @param {Vec2} out the receiving vector, defaults to new vec2()
|
|
2051
2089
|
* @returns {Vec2} out
|
|
2052
2090
|
*/
|
|
2053
|
-
round(out = index.ALWAYS_COPY ?
|
|
2091
|
+
round(out = index.ALWAYS_COPY ? vec2() : this) {
|
|
2054
2092
|
out[0] = Math.round(this[0]);
|
|
2055
2093
|
out[1] = Math.round(this[1]);
|
|
2056
2094
|
return out;
|
|
@@ -2058,10 +2096,10 @@ class Vec2 extends Float32Array {
|
|
|
2058
2096
|
/**
|
|
2059
2097
|
* Math.ceil the components of a vec2
|
|
2060
2098
|
*
|
|
2061
|
-
* @param {Vec2} out the receiving vector, defaults to
|
|
2099
|
+
* @param {Vec2} out the receiving vector, defaults to new vec2()
|
|
2062
2100
|
* @returns {Vec2} out
|
|
2063
2101
|
*/
|
|
2064
|
-
ceil(out = index.ALWAYS_COPY ?
|
|
2102
|
+
ceil(out = index.ALWAYS_COPY ? vec2() : this) {
|
|
2065
2103
|
out[0] = Math.ceil(this[0]);
|
|
2066
2104
|
out[1] = Math.ceil(this[1]);
|
|
2067
2105
|
return out;
|
|
@@ -2069,10 +2107,10 @@ class Vec2 extends Float32Array {
|
|
|
2069
2107
|
/**
|
|
2070
2108
|
* Returns the inverse of the components (1/x, 1/y)
|
|
2071
2109
|
*
|
|
2072
|
-
* @param {Vec2} out the receiving vector, defaults to
|
|
2110
|
+
* @param {Vec2} out the receiving vector, defaults to new vec2()
|
|
2073
2111
|
* @returns {Vec2} out
|
|
2074
2112
|
*/
|
|
2075
|
-
inverse(out = index.ALWAYS_COPY ?
|
|
2113
|
+
inverse(out = index.ALWAYS_COPY ? vec2() : this) {
|
|
2076
2114
|
out[0] = 1.0 / this[0];
|
|
2077
2115
|
out[1] = 1.0 / this[1];
|
|
2078
2116
|
return out;
|
|
@@ -2082,16 +2120,16 @@ class Vec2 extends Float32Array {
|
|
|
2082
2120
|
*
|
|
2083
2121
|
* @returns {Vec2} a new Vec2
|
|
2084
2122
|
*/
|
|
2085
|
-
clone() { return
|
|
2123
|
+
clone() { return vec2(this[0], this[1]); }
|
|
2086
2124
|
/**
|
|
2087
2125
|
* Rotates a vec2 around an origin point
|
|
2088
2126
|
*
|
|
2089
2127
|
* @param {Number} rad the angle of rotation in radians
|
|
2090
|
-
* @param {Vec2} origin the origin of the rotation, defaults to
|
|
2091
|
-
* @param {Vec2} out the receiving vector, defaults to
|
|
2128
|
+
* @param {Vec2} origin the origin of the rotation, defaults to vec2(0, 0)
|
|
2129
|
+
* @param {Vec2} out the receiving vector, defaults to new vec2()
|
|
2092
2130
|
* @returns {Vec2} out
|
|
2093
2131
|
*/
|
|
2094
|
-
rotate(rad = 0, origin =
|
|
2132
|
+
rotate(rad = 0, origin = vec2.zero, out = index.ALWAYS_COPY ? vec2() : this) {
|
|
2095
2133
|
const p0 = this[0] - origin[0];
|
|
2096
2134
|
const p1 = this[1] - origin[1];
|
|
2097
2135
|
const sinC = Math.sin(rad);
|
|
@@ -2114,7 +2152,7 @@ class Vec2 extends Float32Array {
|
|
|
2114
2152
|
* @param {Number} scale length of the resulting vector, defaults to 1.0
|
|
2115
2153
|
* @returns {Vec2} a new random Vec2
|
|
2116
2154
|
*/
|
|
2117
|
-
static random(scale = 1.0, out =
|
|
2155
|
+
static random(scale = 1.0, out = vec2()) {
|
|
2118
2156
|
const angleR = index.RANDOM() * 2.0 * Math.PI;
|
|
2119
2157
|
out[0] = Math.cos(angleR) * scale;
|
|
2120
2158
|
out[1] = Math.sin(angleR) * scale;
|
|
@@ -2208,7 +2246,7 @@ class Vec2 extends Float32Array {
|
|
|
2208
2246
|
* @param {Number} t interpolation amount, in the range [0-1], between the two inputs
|
|
2209
2247
|
* @returns {Vec2} a new interpolated Vec2
|
|
2210
2248
|
*/
|
|
2211
|
-
static lerp(a, b, t, out =
|
|
2249
|
+
static lerp(a, b, t, out = vec2()) {
|
|
2212
2250
|
const a0 = a[0], a1 = a[1];
|
|
2213
2251
|
out[0] = a0 + (b[0] - a0) * t;
|
|
2214
2252
|
out[1] = a1 + (b[1] - a1) * t;
|
|
@@ -2221,7 +2259,7 @@ class Vec2 extends Float32Array {
|
|
|
2221
2259
|
* @param {Vec2} b the second operand
|
|
2222
2260
|
* @returns {Vec2} a new Vec2 with max components
|
|
2223
2261
|
*/
|
|
2224
|
-
static max(a, b, out =
|
|
2262
|
+
static max(a, b, out = vec2()) {
|
|
2225
2263
|
out[0] = Math.max(a[0], b[0]);
|
|
2226
2264
|
out[1] = Math.max(a[1], b[1]);
|
|
2227
2265
|
return out;
|
|
@@ -2233,7 +2271,7 @@ class Vec2 extends Float32Array {
|
|
|
2233
2271
|
* @param {Vec2} b the second operand
|
|
2234
2272
|
* @returns {Vec2} a new Vec2 with min components
|
|
2235
2273
|
*/
|
|
2236
|
-
static min(a, b, out =
|
|
2274
|
+
static min(a, b, out = vec2()) {
|
|
2237
2275
|
out[0] = Math.min(a[0], b[0]);
|
|
2238
2276
|
out[1] = Math.min(a[1], b[1]);
|
|
2239
2277
|
return out;
|
|
@@ -2246,7 +2284,7 @@ class Vec2 extends Float32Array {
|
|
|
2246
2284
|
* @param {Vec2 | Number} max the upper bound
|
|
2247
2285
|
* @returns {Vec2} a new clamped Vec2
|
|
2248
2286
|
*/
|
|
2249
|
-
static clamp(v, min, max, out =
|
|
2287
|
+
static clamp(v, min, max, out = vec2()) {
|
|
2250
2288
|
if (typeof min === 'number' && typeof max === 'number') {
|
|
2251
2289
|
out[0] = Math.min(Math.max(v[0], min), max);
|
|
2252
2290
|
out[1] = Math.min(Math.max(v[1], min), max);
|
|
@@ -2269,7 +2307,7 @@ class Vec2 extends Float32Array {
|
|
|
2269
2307
|
* @param {Vec2 | Number} t interpolation factor (scalar or per-component)
|
|
2270
2308
|
* @returns {Vec2} a new interpolated Vec2
|
|
2271
2309
|
*/
|
|
2272
|
-
static mix(a, b, t, out =
|
|
2310
|
+
static mix(a, b, t, out = vec2()) {
|
|
2273
2311
|
if (typeof t === 'number') {
|
|
2274
2312
|
out[0] = a[0] + (b[0] - a[0]) * t;
|
|
2275
2313
|
out[1] = a[1] + (b[1] - a[1]) * t;
|
|
@@ -2288,7 +2326,7 @@ class Vec2 extends Float32Array {
|
|
|
2288
2326
|
* @param {Vec2} v the source vector
|
|
2289
2327
|
* @returns {Vec2} a new smoothstepped Vec2
|
|
2290
2328
|
*/
|
|
2291
|
-
static smoothstep(edge0, edge1, v, out =
|
|
2329
|
+
static smoothstep(edge0, edge1, v, out = vec2()) {
|
|
2292
2330
|
const e0x = typeof edge0 === 'number' ? edge0 : edge0[0];
|
|
2293
2331
|
const e0y = typeof edge0 === 'number' ? edge0 : edge0[1];
|
|
2294
2332
|
const e1x = typeof edge1 === 'number' ? edge1 : edge1[0];
|
|
@@ -2304,10 +2342,10 @@ class Vec2 extends Float32Array {
|
|
|
2304
2342
|
*
|
|
2305
2343
|
* @param {Vec2} b the second operand
|
|
2306
2344
|
* @param {Number} scale the amount to scale b by before adding
|
|
2307
|
-
* @param {Vec2} out the receiving vector, defaults to
|
|
2345
|
+
* @param {Vec2} out the receiving vector, defaults to new vec2()
|
|
2308
2346
|
* @returns {Vec2} out
|
|
2309
2347
|
*/
|
|
2310
|
-
scaleAndAdd(b, scale, out = index.ALWAYS_COPY ?
|
|
2348
|
+
scaleAndAdd(b, scale, out = index.ALWAYS_COPY ? vec2() : this) {
|
|
2311
2349
|
out[0] = this[0] + b[0] * scale;
|
|
2312
2350
|
out[1] = this[1] + b[1] * scale;
|
|
2313
2351
|
return out;
|
|
@@ -2315,10 +2353,10 @@ class Vec2 extends Float32Array {
|
|
|
2315
2353
|
/**
|
|
2316
2354
|
* Component-wise absolute value
|
|
2317
2355
|
*
|
|
2318
|
-
* @param {Vec2} out the receiving vector, defaults to
|
|
2356
|
+
* @param {Vec2} out the receiving vector, defaults to new vec2()
|
|
2319
2357
|
* @returns {Vec2} out
|
|
2320
2358
|
*/
|
|
2321
|
-
abs(out = index.ALWAYS_COPY ?
|
|
2359
|
+
abs(out = index.ALWAYS_COPY ? vec2() : this) {
|
|
2322
2360
|
out[0] = Math.abs(this[0]);
|
|
2323
2361
|
out[1] = Math.abs(this[1]);
|
|
2324
2362
|
return out;
|
|
@@ -2326,10 +2364,10 @@ class Vec2 extends Float32Array {
|
|
|
2326
2364
|
/**
|
|
2327
2365
|
* Component-wise sign
|
|
2328
2366
|
*
|
|
2329
|
-
* @param {Vec2} out the receiving vector, defaults to
|
|
2367
|
+
* @param {Vec2} out the receiving vector, defaults to new vec2()
|
|
2330
2368
|
* @returns {Vec2} out
|
|
2331
2369
|
*/
|
|
2332
|
-
sign(out = index.ALWAYS_COPY ?
|
|
2370
|
+
sign(out = index.ALWAYS_COPY ? vec2() : this) {
|
|
2333
2371
|
out[0] = this[0] > 0 ? 1 : this[0] < 0 ? -1 : 0;
|
|
2334
2372
|
out[1] = this[1] > 0 ? 1 : this[1] < 0 ? -1 : 0;
|
|
2335
2373
|
return out;
|
|
@@ -2337,10 +2375,10 @@ class Vec2 extends Float32Array {
|
|
|
2337
2375
|
/**
|
|
2338
2376
|
* Component-wise fractional part (x - floor(x))
|
|
2339
2377
|
*
|
|
2340
|
-
* @param {Vec2} out the receiving vector, defaults to
|
|
2378
|
+
* @param {Vec2} out the receiving vector, defaults to new vec2()
|
|
2341
2379
|
* @returns {Vec2} out
|
|
2342
2380
|
*/
|
|
2343
|
-
fract(out = index.ALWAYS_COPY ?
|
|
2381
|
+
fract(out = index.ALWAYS_COPY ? vec2() : this) {
|
|
2344
2382
|
out[0] = this[0] - Math.floor(this[0]);
|
|
2345
2383
|
out[1] = this[1] - Math.floor(this[1]);
|
|
2346
2384
|
return out;
|
|
@@ -2350,10 +2388,10 @@ class Vec2 extends Float32Array {
|
|
|
2350
2388
|
*
|
|
2351
2389
|
* @param {Vec2 | Number} min the lower bound
|
|
2352
2390
|
* @param {Vec2 | Number} max the upper bound
|
|
2353
|
-
* @param {Vec2} out the receiving vector, defaults to
|
|
2391
|
+
* @param {Vec2} out the receiving vector, defaults to new vec2()
|
|
2354
2392
|
* @returns {Vec2} out
|
|
2355
2393
|
*/
|
|
2356
|
-
clamp(min, max, out = index.ALWAYS_COPY ?
|
|
2394
|
+
clamp(min, max, out = index.ALWAYS_COPY ? vec2() : this) {
|
|
2357
2395
|
if (typeof min === 'number' && typeof max === 'number') {
|
|
2358
2396
|
out[0] = Math.min(Math.max(this[0], min), max);
|
|
2359
2397
|
out[1] = Math.min(Math.max(this[1], min), max);
|
|
@@ -2371,10 +2409,10 @@ class Vec2 extends Float32Array {
|
|
|
2371
2409
|
/**
|
|
2372
2410
|
* Clamp components to [0, 1]
|
|
2373
2411
|
*
|
|
2374
|
-
* @param {Vec2} out the receiving vector, defaults to
|
|
2412
|
+
* @param {Vec2} out the receiving vector, defaults to new vec2()
|
|
2375
2413
|
* @returns {Vec2} out
|
|
2376
2414
|
*/
|
|
2377
|
-
saturate(out = index.ALWAYS_COPY ?
|
|
2415
|
+
saturate(out = index.ALWAYS_COPY ? vec2() : this) {
|
|
2378
2416
|
out[0] = Math.min(Math.max(this[0], 0), 1);
|
|
2379
2417
|
out[1] = Math.min(Math.max(this[1], 0), 1);
|
|
2380
2418
|
return out;
|
|
@@ -2384,10 +2422,10 @@ class Vec2 extends Float32Array {
|
|
|
2384
2422
|
*
|
|
2385
2423
|
* @param {Vec2} b the second operand
|
|
2386
2424
|
* @param {Vec2 | Number} t interpolation factor (scalar or per-component)
|
|
2387
|
-
* @param {Vec2} out the receiving vector, defaults to
|
|
2425
|
+
* @param {Vec2} out the receiving vector, defaults to new vec2()
|
|
2388
2426
|
* @returns {Vec2} out
|
|
2389
2427
|
*/
|
|
2390
|
-
mix(b, t, out = index.ALWAYS_COPY ?
|
|
2428
|
+
mix(b, t, out = index.ALWAYS_COPY ? vec2() : this) {
|
|
2391
2429
|
if (typeof t === 'number') {
|
|
2392
2430
|
out[0] = this[0] + (b[0] - this[0]) * t;
|
|
2393
2431
|
out[1] = this[1] + (b[1] - this[1]) * t;
|
|
@@ -2402,10 +2440,10 @@ class Vec2 extends Float32Array {
|
|
|
2402
2440
|
* Component-wise step function
|
|
2403
2441
|
*
|
|
2404
2442
|
* @param {Vec2 | Number} edge the edge threshold
|
|
2405
|
-
* @param {Vec2} out the receiving vector, defaults to
|
|
2443
|
+
* @param {Vec2} out the receiving vector, defaults to new vec2()
|
|
2406
2444
|
* @returns {Vec2} out
|
|
2407
2445
|
*/
|
|
2408
|
-
step(edge, out = index.ALWAYS_COPY ?
|
|
2446
|
+
step(edge, out = index.ALWAYS_COPY ? vec2() : this) {
|
|
2409
2447
|
if (typeof edge === 'number') {
|
|
2410
2448
|
out[0] = this[0] < edge ? 0 : 1;
|
|
2411
2449
|
out[1] = this[1] < edge ? 0 : 1;
|
|
@@ -2421,10 +2459,10 @@ class Vec2 extends Float32Array {
|
|
|
2421
2459
|
*
|
|
2422
2460
|
* @param {Vec2 | Number} edge0 the lower edge
|
|
2423
2461
|
* @param {Vec2 | Number} edge1 the upper edge
|
|
2424
|
-
* @param {Vec2} out the receiving vector, defaults to
|
|
2462
|
+
* @param {Vec2} out the receiving vector, defaults to new vec2()
|
|
2425
2463
|
* @returns {Vec2} out
|
|
2426
2464
|
*/
|
|
2427
|
-
smoothstep(edge0, edge1, out = index.ALWAYS_COPY ?
|
|
2465
|
+
smoothstep(edge0, edge1, out = index.ALWAYS_COPY ? vec2() : this) {
|
|
2428
2466
|
const e0x = typeof edge0 === 'number' ? edge0 : edge0[0];
|
|
2429
2467
|
const e0y = typeof edge0 === 'number' ? edge0 : edge0[1];
|
|
2430
2468
|
const e1x = typeof edge1 === 'number' ? edge1 : edge1[0];
|
|
@@ -2439,10 +2477,10 @@ class Vec2 extends Float32Array {
|
|
|
2439
2477
|
* Transforms the vec2 with a Mat2 (column-major 2x2)
|
|
2440
2478
|
*
|
|
2441
2479
|
* @param {Mat2} m matrix to transform with
|
|
2442
|
-
* @param {Vec2} out the receiving vector, defaults to
|
|
2480
|
+
* @param {Vec2} out the receiving vector, defaults to new vec2()
|
|
2443
2481
|
* @returns {Vec2} out
|
|
2444
2482
|
*/
|
|
2445
|
-
transformMat2(m, out = index.ALWAYS_COPY ?
|
|
2483
|
+
transformMat2(m, out = index.ALWAYS_COPY ? vec2() : this) {
|
|
2446
2484
|
const x = this[0], y = this[1];
|
|
2447
2485
|
out[0] = m[0] * x + m[2] * y;
|
|
2448
2486
|
out[1] = m[1] * x + m[3] * y;
|
|
@@ -2452,10 +2490,10 @@ class Vec2 extends Float32Array {
|
|
|
2452
2490
|
* Transforms the vec2 with a Mat2x3 (2D affine transform)
|
|
2453
2491
|
*
|
|
2454
2492
|
* @param {Mat2x3} m matrix to transform with
|
|
2455
|
-
* @param {Vec2} out the receiving vector, defaults to
|
|
2493
|
+
* @param {Vec2} out the receiving vector, defaults to new vec2()
|
|
2456
2494
|
* @returns {Vec2} out
|
|
2457
2495
|
*/
|
|
2458
|
-
transformMat2x3(m, out = index.ALWAYS_COPY ?
|
|
2496
|
+
transformMat2x3(m, out = index.ALWAYS_COPY ? vec2() : this) {
|
|
2459
2497
|
const x = this[0], y = this[1];
|
|
2460
2498
|
out[0] = m[0] * x + m[2] * y + m[4];
|
|
2461
2499
|
out[1] = m[1] * x + m[3] * y + m[5];
|
|
@@ -2465,10 +2503,10 @@ class Vec2 extends Float32Array {
|
|
|
2465
2503
|
* Transforms the vec2 with a Mat3 (column-major 3x3)
|
|
2466
2504
|
*
|
|
2467
2505
|
* @param {Mat3} m matrix to transform with
|
|
2468
|
-
* @param {Vec2} out the receiving vector, defaults to
|
|
2506
|
+
* @param {Vec2} out the receiving vector, defaults to new vec2()
|
|
2469
2507
|
* @returns {Vec2} out
|
|
2470
2508
|
*/
|
|
2471
|
-
transformMat3(m, out = index.ALWAYS_COPY ?
|
|
2509
|
+
transformMat3(m, out = index.ALWAYS_COPY ? vec2() : this) {
|
|
2472
2510
|
const x = this[0], y = this[1];
|
|
2473
2511
|
out[0] = m[0] * x + m[3] * y + m[6];
|
|
2474
2512
|
out[1] = m[1] * x + m[4] * y + m[7];
|
|
@@ -2478,10 +2516,10 @@ class Vec2 extends Float32Array {
|
|
|
2478
2516
|
* Transforms the vec2 with a Mat4 (column-major 4x4)
|
|
2479
2517
|
*
|
|
2480
2518
|
* @param {Mat4} m matrix to transform with
|
|
2481
|
-
* @param {Vec2} out the receiving vector, defaults to
|
|
2519
|
+
* @param {Vec2} out the receiving vector, defaults to new vec2()
|
|
2482
2520
|
* @returns {Vec2} out
|
|
2483
2521
|
*/
|
|
2484
|
-
transformMat4(m, out = index.ALWAYS_COPY ?
|
|
2522
|
+
transformMat4(m, out = index.ALWAYS_COPY ? vec2() : this) {
|
|
2485
2523
|
const x = this[0], y = this[1];
|
|
2486
2524
|
out[0] = m[0] * x + m[4] * y + m[12];
|
|
2487
2525
|
out[1] = m[1] * x + m[5] * y + m[13];
|
|
@@ -2496,7 +2534,7 @@ class Vec2 extends Float32Array {
|
|
|
2496
2534
|
* @param {Vec2} out the receiving vector
|
|
2497
2535
|
* @returns {Vec2} out
|
|
2498
2536
|
*/
|
|
2499
|
-
static scaleAndAdd(a, b, scale, out =
|
|
2537
|
+
static scaleAndAdd(a, b, scale, out = vec2()) {
|
|
2500
2538
|
out[0] = a[0] + b[0] * scale;
|
|
2501
2539
|
out[1] = a[1] + b[1] * scale;
|
|
2502
2540
|
return out;
|
|
@@ -2509,7 +2547,7 @@ class Vec2 extends Float32Array {
|
|
|
2509
2547
|
* @param {Vec2} out the receiving vector
|
|
2510
2548
|
* @returns {Vec2} out
|
|
2511
2549
|
*/
|
|
2512
|
-
static reflect(I, N, out =
|
|
2550
|
+
static reflect(I, N, out = vec2()) {
|
|
2513
2551
|
const d = Vec2.dot(N, I);
|
|
2514
2552
|
out[0] = I[0] - 2 * d * N[0];
|
|
2515
2553
|
out[1] = I[1] - 2 * d * N[1];
|
|
@@ -2533,6 +2571,7 @@ Vec2.prototype.unaryMinus = Vec2.prototype.negate;
|
|
|
2533
2571
|
Vec2.prototype.sqrLen = Vec2.prototype.squaredLength;
|
|
2534
2572
|
Vec2.prototype.str = Vec2.prototype.toString;
|
|
2535
2573
|
Vec2.prototype.lerpV = Vec2.prototype.mix;
|
|
2574
|
+
Vec2.prototype.normalized = Vec2.prototype.normalize;
|
|
2536
2575
|
Vec2.prototype.transformMat2x2 = Vec2.prototype.transformMat2;
|
|
2537
2576
|
Vec2.prototype.transformMat2d = Vec2.prototype.transformMat2x3;
|
|
2538
2577
|
Vec2.prototype.transformMat3x3 = Vec2.prototype.transformMat3;
|
|
@@ -2559,9 +2598,9 @@ const vec2 = createVec2;
|
|
|
2559
2598
|
* @extends Float32Array
|
|
2560
2599
|
*/
|
|
2561
2600
|
class Mat3 extends Float32Array {
|
|
2562
|
-
static get identity() { return
|
|
2563
|
-
static get Identity() { return
|
|
2564
|
-
static get IDENTITY() { return
|
|
2601
|
+
static get identity() { return mat3(1, 0, 0, 0, 1, 0, 0, 0, 1); }
|
|
2602
|
+
static get Identity() { return mat3(1, 0, 0, 0, 1, 0, 0, 0, 1); }
|
|
2603
|
+
static get IDENTITY() { return mat3(1, 0, 0, 0, 1, 0, 0, 0, 1); }
|
|
2565
2604
|
/**
|
|
2566
2605
|
* Create a new mat3 with the given values
|
|
2567
2606
|
*
|
|
@@ -2593,15 +2632,15 @@ class Mat3 extends Float32Array {
|
|
|
2593
2632
|
* @returns {Mat3} a new Mat3
|
|
2594
2633
|
*/
|
|
2595
2634
|
clone() {
|
|
2596
|
-
return
|
|
2635
|
+
return mat3(this[0], this[1], this[2], this[3], this[4], this[5], this[6], this[7], this[8]);
|
|
2597
2636
|
}
|
|
2598
2637
|
/**
|
|
2599
2638
|
* Transposes a mat3
|
|
2600
2639
|
*
|
|
2601
|
-
* @param {Mat3} out the receiving matrix, defaults to
|
|
2640
|
+
* @param {Mat3} out the receiving matrix, defaults to new mat3()
|
|
2602
2641
|
* @returns {Mat3} out
|
|
2603
2642
|
*/
|
|
2604
|
-
transpose(out = index.ALWAYS_COPY ?
|
|
2643
|
+
transpose(out = index.ALWAYS_COPY ? mat3() : this) {
|
|
2605
2644
|
if (out.exactEquals(this)) {
|
|
2606
2645
|
const a01 = this[1], a02 = this[2], a12 = this[5];
|
|
2607
2646
|
out[1] = this[3];
|
|
@@ -2627,10 +2666,10 @@ class Mat3 extends Float32Array {
|
|
|
2627
2666
|
/**
|
|
2628
2667
|
* Inverts a mat3
|
|
2629
2668
|
*
|
|
2630
|
-
* @param {Mat3} out the receiving matrix, defaults to
|
|
2669
|
+
* @param {Mat3} out the receiving matrix, defaults to new mat3()
|
|
2631
2670
|
* @returns {Mat3|null} out, or null if not invertible
|
|
2632
2671
|
*/
|
|
2633
|
-
invert(out = index.ALWAYS_COPY ?
|
|
2672
|
+
invert(out = index.ALWAYS_COPY ? mat3() : this) {
|
|
2634
2673
|
const a00 = this[0], a01 = this[1], a02 = this[2];
|
|
2635
2674
|
const a10 = this[3], a11 = this[4], a12 = this[5];
|
|
2636
2675
|
const a20 = this[6], a21 = this[7], a22 = this[8];
|
|
@@ -2655,10 +2694,10 @@ class Mat3 extends Float32Array {
|
|
|
2655
2694
|
/**
|
|
2656
2695
|
* Calculates the adjugate of a mat3
|
|
2657
2696
|
*
|
|
2658
|
-
* @param {Mat3} out the receiving matrix, defaults to
|
|
2697
|
+
* @param {Mat3} out the receiving matrix, defaults to new mat3()
|
|
2659
2698
|
* @returns {Mat3} out
|
|
2660
2699
|
*/
|
|
2661
|
-
adjoint(out = index.ALWAYS_COPY ?
|
|
2700
|
+
adjoint(out = index.ALWAYS_COPY ? mat3() : this) {
|
|
2662
2701
|
const a00 = this[0], a01 = this[1], a02 = this[2];
|
|
2663
2702
|
const a10 = this[3], a11 = this[4], a12 = this[5];
|
|
2664
2703
|
const a20 = this[6], a21 = this[7], a22 = this[8];
|
|
@@ -2684,7 +2723,7 @@ class Mat3 extends Float32Array {
|
|
|
2684
2723
|
const a20 = this[6], a21 = this[7], a22 = this[8];
|
|
2685
2724
|
return a00 * (a22 * a11 - a12 * a21) + a01 * (-a22 * a10 + a12 * a20) + a02 * (a21 * a10 - a11 * a20);
|
|
2686
2725
|
}
|
|
2687
|
-
multiply(b, out = index.ALWAYS_COPY ?
|
|
2726
|
+
multiply(b, out = index.ALWAYS_COPY ? mat3() : this) {
|
|
2688
2727
|
if (b instanceof Vec2)
|
|
2689
2728
|
return b.transformMat3(this);
|
|
2690
2729
|
if (b instanceof Vec3)
|
|
@@ -2710,10 +2749,10 @@ class Mat3 extends Float32Array {
|
|
|
2710
2749
|
* Translates a mat3 by the given vector
|
|
2711
2750
|
*
|
|
2712
2751
|
* @param {Vec2} v vector to translate by
|
|
2713
|
-
* @param {Mat3} out the receiving matrix, defaults to
|
|
2752
|
+
* @param {Mat3} out the receiving matrix, defaults to new mat3()
|
|
2714
2753
|
* @returns {Mat3} out
|
|
2715
2754
|
*/
|
|
2716
|
-
translate(v, out = index.ALWAYS_COPY ?
|
|
2755
|
+
translate(v, out = index.ALWAYS_COPY ? mat3() : this) {
|
|
2717
2756
|
const a00 = this[0], a01 = this[1], a02 = this[2];
|
|
2718
2757
|
const a10 = this[3], a11 = this[4], a12 = this[5];
|
|
2719
2758
|
const a20 = this[6], a21 = this[7], a22 = this[8];
|
|
@@ -2733,10 +2772,10 @@ class Mat3 extends Float32Array {
|
|
|
2733
2772
|
* Rotates a mat3 by the given angle
|
|
2734
2773
|
*
|
|
2735
2774
|
* @param {Number} rad the angle to rotate the matrix by
|
|
2736
|
-
* @param {Mat3} out the receiving matrix, defaults to
|
|
2775
|
+
* @param {Mat3} out the receiving matrix, defaults to new mat3()
|
|
2737
2776
|
* @returns {Mat3} out
|
|
2738
2777
|
*/
|
|
2739
|
-
rotate(rad, out = index.ALWAYS_COPY ?
|
|
2778
|
+
rotate(rad, out = index.ALWAYS_COPY ? mat3() : this) {
|
|
2740
2779
|
const a00 = this[0], a01 = this[1], a02 = this[2];
|
|
2741
2780
|
const a10 = this[3], a11 = this[4], a12 = this[5];
|
|
2742
2781
|
const a20 = this[6], a21 = this[7], a22 = this[8];
|
|
@@ -2756,10 +2795,10 @@ class Mat3 extends Float32Array {
|
|
|
2756
2795
|
* Scales a mat3 by the given vector
|
|
2757
2796
|
*
|
|
2758
2797
|
* @param {Vec2} v the vector to scale by
|
|
2759
|
-
* @param {Mat3} out the receiving matrix, defaults to
|
|
2798
|
+
* @param {Mat3} out the receiving matrix, defaults to new mat3()
|
|
2760
2799
|
* @returns {Mat3} out
|
|
2761
2800
|
*/
|
|
2762
|
-
scale(v, out = index.ALWAYS_COPY ?
|
|
2801
|
+
scale(v, out = index.ALWAYS_COPY ? mat3() : this) {
|
|
2763
2802
|
const x = v[0], y = v[1];
|
|
2764
2803
|
out[0] = x * this[0];
|
|
2765
2804
|
out[1] = x * this[1];
|
|
@@ -2776,10 +2815,10 @@ class Mat3 extends Float32Array {
|
|
|
2776
2815
|
* Creates a matrix from a translation vector
|
|
2777
2816
|
*
|
|
2778
2817
|
* @param {Vec2} v translation vector
|
|
2779
|
-
* @param {Mat3} out the receiving matrix, defaults to
|
|
2818
|
+
* @param {Mat3} out the receiving matrix, defaults to mat3()
|
|
2780
2819
|
* @returns {Mat3} out
|
|
2781
2820
|
*/
|
|
2782
|
-
static fromTranslation(v, out =
|
|
2821
|
+
static fromTranslation(v, out = mat3()) {
|
|
2783
2822
|
out[0] = 1;
|
|
2784
2823
|
out[1] = 0;
|
|
2785
2824
|
out[2] = 0;
|
|
@@ -2795,10 +2834,10 @@ class Mat3 extends Float32Array {
|
|
|
2795
2834
|
* Creates a matrix from a given angle
|
|
2796
2835
|
*
|
|
2797
2836
|
* @param {Number} rad the angle to rotate the matrix by
|
|
2798
|
-
* @param {Mat3} out the receiving matrix, defaults to
|
|
2837
|
+
* @param {Mat3} out the receiving matrix, defaults to mat3()
|
|
2799
2838
|
* @returns {Mat3} out
|
|
2800
2839
|
*/
|
|
2801
|
-
static fromRotation(rad, out =
|
|
2840
|
+
static fromRotation(rad, out = mat3()) {
|
|
2802
2841
|
const s = Math.sin(rad), c = Math.cos(rad);
|
|
2803
2842
|
out[0] = c;
|
|
2804
2843
|
out[1] = s;
|
|
@@ -2815,10 +2854,10 @@ class Mat3 extends Float32Array {
|
|
|
2815
2854
|
* Creates a matrix from a scaling vector
|
|
2816
2855
|
*
|
|
2817
2856
|
* @param {Vec2} v scaling vector
|
|
2818
|
-
* @param {Mat3} out the receiving matrix, defaults to
|
|
2857
|
+
* @param {Mat3} out the receiving matrix, defaults to mat3()
|
|
2819
2858
|
* @returns {Mat3} out
|
|
2820
2859
|
*/
|
|
2821
|
-
static fromScaling(v, out =
|
|
2860
|
+
static fromScaling(v, out = mat3()) {
|
|
2822
2861
|
out[0] = v[0];
|
|
2823
2862
|
out[1] = 0;
|
|
2824
2863
|
out[2] = 0;
|
|
@@ -2834,10 +2873,10 @@ class Mat3 extends Float32Array {
|
|
|
2834
2873
|
* Creates a mat3 from a Mat2x3
|
|
2835
2874
|
*
|
|
2836
2875
|
* @param {Mat2x3} a the Mat2x3 to convert
|
|
2837
|
-
* @param {Mat3} out the receiving matrix, defaults to
|
|
2876
|
+
* @param {Mat3} out the receiving matrix, defaults to mat3()
|
|
2838
2877
|
* @returns {Mat3} out
|
|
2839
2878
|
*/
|
|
2840
|
-
static fromMat2x3(a, out =
|
|
2879
|
+
static fromMat2x3(a, out = mat3()) {
|
|
2841
2880
|
out[0] = a[0];
|
|
2842
2881
|
out[1] = a[1];
|
|
2843
2882
|
out[2] = 0;
|
|
@@ -2853,10 +2892,10 @@ class Mat3 extends Float32Array {
|
|
|
2853
2892
|
* Calculates a mat3 from the given quaternion
|
|
2854
2893
|
*
|
|
2855
2894
|
* @param {Quat} q quaternion to create matrix from
|
|
2856
|
-
* @param {Mat3} out the receiving matrix, defaults to
|
|
2895
|
+
* @param {Mat3} out the receiving matrix, defaults to mat3()
|
|
2857
2896
|
* @returns {Mat3} out
|
|
2858
2897
|
*/
|
|
2859
|
-
static fromQuat(q, out =
|
|
2898
|
+
static fromQuat(q, out = mat3()) {
|
|
2860
2899
|
const x = q[0], y = q[1], z = q[2], w = q[3];
|
|
2861
2900
|
const x2 = x + x, y2 = y + y, z2 = z + z;
|
|
2862
2901
|
const xx = x * x2, yx = y * x2, yy = y * y2;
|
|
@@ -2877,10 +2916,10 @@ class Mat3 extends Float32Array {
|
|
|
2877
2916
|
* Calculates a mat3 normal matrix (transpose inverse) from a mat4
|
|
2878
2917
|
*
|
|
2879
2918
|
* @param {Mat4} a the source mat4 to derive the normal matrix from
|
|
2880
|
-
* @param {Mat3} out the receiving matrix, defaults to
|
|
2919
|
+
* @param {Mat3} out the receiving matrix, defaults to mat3()
|
|
2881
2920
|
* @returns {Mat3|null} out, or null if not invertible
|
|
2882
2921
|
*/
|
|
2883
|
-
static normalFromMat4(a, out =
|
|
2922
|
+
static normalFromMat4(a, out = mat3()) {
|
|
2884
2923
|
const a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3];
|
|
2885
2924
|
const a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7];
|
|
2886
2925
|
const a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11];
|
|
@@ -2916,10 +2955,10 @@ class Mat3 extends Float32Array {
|
|
|
2916
2955
|
* Copies the upper-left 3x3 values of a mat4 into a mat3
|
|
2917
2956
|
*
|
|
2918
2957
|
* @param {Mat4} a the source mat4
|
|
2919
|
-
* @param {Mat3} out the receiving matrix, defaults to
|
|
2958
|
+
* @param {Mat3} out the receiving matrix, defaults to mat3()
|
|
2920
2959
|
* @returns {Mat3} out
|
|
2921
2960
|
*/
|
|
2922
|
-
static fromMat4(a, out =
|
|
2961
|
+
static fromMat4(a, out = mat3()) {
|
|
2923
2962
|
out[0] = a[0];
|
|
2924
2963
|
out[1] = a[1];
|
|
2925
2964
|
out[2] = a[2];
|
|
@@ -2936,10 +2975,10 @@ class Mat3 extends Float32Array {
|
|
|
2936
2975
|
*
|
|
2937
2976
|
* @param {Number} width width of the projection
|
|
2938
2977
|
* @param {Number} height height of the projection
|
|
2939
|
-
* @param {Mat3} out the receiving matrix, defaults to
|
|
2978
|
+
* @param {Mat3} out the receiving matrix, defaults to mat3()
|
|
2940
2979
|
* @returns {Mat3} out
|
|
2941
2980
|
*/
|
|
2942
|
-
static projection(width, height, out =
|
|
2981
|
+
static projection(width, height, out = mat3()) {
|
|
2943
2982
|
out[0] = 2 / width;
|
|
2944
2983
|
out[1] = 0;
|
|
2945
2984
|
out[2] = 0;
|
|
@@ -2965,10 +3004,10 @@ class Mat3 extends Float32Array {
|
|
|
2965
3004
|
* Adds two mat3's
|
|
2966
3005
|
*
|
|
2967
3006
|
* @param {Mat3} b the second operand
|
|
2968
|
-
* @param {Mat3} out the receiving matrix, defaults to
|
|
3007
|
+
* @param {Mat3} out the receiving matrix, defaults to new mat3()
|
|
2969
3008
|
* @returns {Mat3} out
|
|
2970
3009
|
*/
|
|
2971
|
-
plus(b, out = index.ALWAYS_COPY ?
|
|
3010
|
+
plus(b, out = index.ALWAYS_COPY ? mat3() : this) {
|
|
2972
3011
|
out[0] = this[0] + b[0];
|
|
2973
3012
|
out[1] = this[1] + b[1];
|
|
2974
3013
|
out[2] = this[2] + b[2];
|
|
@@ -2984,10 +3023,10 @@ class Mat3 extends Float32Array {
|
|
|
2984
3023
|
* Subtracts matrix b from this
|
|
2985
3024
|
*
|
|
2986
3025
|
* @param {Mat3} b the second operand
|
|
2987
|
-
* @param {Mat3} out the receiving matrix, defaults to
|
|
3026
|
+
* @param {Mat3} out the receiving matrix, defaults to new mat3()
|
|
2988
3027
|
* @returns {Mat3} out
|
|
2989
3028
|
*/
|
|
2990
|
-
minus(b, out = index.ALWAYS_COPY ?
|
|
3029
|
+
minus(b, out = index.ALWAYS_COPY ? mat3() : this) {
|
|
2991
3030
|
out[0] = this[0] - b[0];
|
|
2992
3031
|
out[1] = this[1] - b[1];
|
|
2993
3032
|
out[2] = this[2] - b[2];
|
|
@@ -3003,10 +3042,10 @@ class Mat3 extends Float32Array {
|
|
|
3003
3042
|
* Multiplies each element of a mat3 by a scalar number
|
|
3004
3043
|
*
|
|
3005
3044
|
* @param {Number} b amount to scale the matrix's elements by
|
|
3006
|
-
* @param {Mat3} out the receiving matrix, defaults to
|
|
3045
|
+
* @param {Mat3} out the receiving matrix, defaults to new mat3()
|
|
3007
3046
|
* @returns {Mat3} out
|
|
3008
3047
|
*/
|
|
3009
|
-
scaleScalar(b, out = index.ALWAYS_COPY ?
|
|
3048
|
+
scaleScalar(b, out = index.ALWAYS_COPY ? mat3() : this) {
|
|
3010
3049
|
out[0] = this[0] * b;
|
|
3011
3050
|
out[1] = this[1] * b;
|
|
3012
3051
|
out[2] = this[2] * b;
|
|
@@ -3023,10 +3062,10 @@ class Mat3 extends Float32Array {
|
|
|
3023
3062
|
*
|
|
3024
3063
|
* @param {Mat3} b the second operand
|
|
3025
3064
|
* @param {Number} scale the amount to scale b's elements by before adding
|
|
3026
|
-
* @param {Mat3} out the receiving matrix, defaults to
|
|
3065
|
+
* @param {Mat3} out the receiving matrix, defaults to new mat3()
|
|
3027
3066
|
* @returns {Mat3} out
|
|
3028
3067
|
*/
|
|
3029
|
-
multiplyScalarAndAdd(b, scale, out = index.ALWAYS_COPY ?
|
|
3068
|
+
multiplyScalarAndAdd(b, scale, out = index.ALWAYS_COPY ? mat3() : this) {
|
|
3030
3069
|
out[0] = this[0] + b[0] * scale;
|
|
3031
3070
|
out[1] = this[1] + b[1] * scale;
|
|
3032
3071
|
out[2] = this[2] + b[2] * scale;
|
|
@@ -3086,7 +3125,7 @@ Mat3.prototype.mult = Mat3.prototype.multiply;
|
|
|
3086
3125
|
Mat3.prototype.times = Mat3.prototype.multiply;
|
|
3087
3126
|
Mat3.prototype.str = Mat3.prototype.toString;
|
|
3088
3127
|
Mat3.prototype.multiplyScalar = Mat3.prototype.scaleScalar;
|
|
3089
|
-
const
|
|
3128
|
+
const createMat3 = (...args) => {
|
|
3090
3129
|
const out = new Mat3();
|
|
3091
3130
|
let i = 0;
|
|
3092
3131
|
for (const a of args) {
|
|
@@ -3097,7 +3136,9 @@ const mat3 = Object.assign((...args) => {
|
|
|
3097
3136
|
out[i++] = v;
|
|
3098
3137
|
}
|
|
3099
3138
|
return out;
|
|
3100
|
-
}
|
|
3139
|
+
};
|
|
3140
|
+
Object.setPrototypeOf(createMat3, Mat3);
|
|
3141
|
+
const mat3 = createMat3;
|
|
3101
3142
|
const mat3x3 = mat3;
|
|
3102
3143
|
|
|
3103
3144
|
var _a;
|
|
@@ -3106,9 +3147,9 @@ var _a;
|
|
|
3106
3147
|
* @extends Float32Array
|
|
3107
3148
|
*/
|
|
3108
3149
|
class Mat4 extends Float32Array {
|
|
3109
|
-
static get identity() { return
|
|
3110
|
-
static get Identity() { return
|
|
3111
|
-
static get IDENTITY() { return
|
|
3150
|
+
static get identity() { return mat4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); }
|
|
3151
|
+
static get Identity() { return mat4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); }
|
|
3152
|
+
static get IDENTITY() { return mat4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); }
|
|
3112
3153
|
/**
|
|
3113
3154
|
* Creates a new 4x4 matrix
|
|
3114
3155
|
*
|
|
@@ -3154,15 +3195,15 @@ class Mat4 extends Float32Array {
|
|
|
3154
3195
|
* @returns {Mat4} a new 4x4 matrix
|
|
3155
3196
|
*/
|
|
3156
3197
|
clone() {
|
|
3157
|
-
return
|
|
3198
|
+
return mat4(this[0], this[1], this[2], this[3], this[4], this[5], this[6], this[7], this[8], this[9], this[10], this[11], this[12], this[13], this[14], this[15]);
|
|
3158
3199
|
}
|
|
3159
3200
|
/**
|
|
3160
3201
|
* Transposes a mat4
|
|
3161
3202
|
*
|
|
3162
|
-
* @param {Mat4} out the receiving matrix, defaults to
|
|
3203
|
+
* @param {Mat4} out the receiving matrix, defaults to new mat4()
|
|
3163
3204
|
* @returns {Mat4} out
|
|
3164
3205
|
*/
|
|
3165
|
-
transpose(out = index.ALWAYS_COPY ?
|
|
3206
|
+
transpose(out = index.ALWAYS_COPY ? mat4() : this) {
|
|
3166
3207
|
if (out.exactEquals(this)) {
|
|
3167
3208
|
const a01 = this[1], a02 = this[2], a03 = this[3];
|
|
3168
3209
|
const a12 = this[6], a13 = this[7], a23 = this[11];
|
|
@@ -3202,10 +3243,10 @@ class Mat4 extends Float32Array {
|
|
|
3202
3243
|
/**
|
|
3203
3244
|
* Inverts a mat4
|
|
3204
3245
|
*
|
|
3205
|
-
* @param {Mat4} out the receiving matrix, defaults to
|
|
3246
|
+
* @param {Mat4} out the receiving matrix, defaults to new mat4()
|
|
3206
3247
|
* @returns {Mat4} out
|
|
3207
3248
|
*/
|
|
3208
|
-
invert(out = index.ALWAYS_COPY ?
|
|
3249
|
+
invert(out = index.ALWAYS_COPY ? mat4() : this) {
|
|
3209
3250
|
const a00 = this[0], a01 = this[1], a02 = this[2], a03 = this[3];
|
|
3210
3251
|
const a10 = this[4], a11 = this[5], a12 = this[6], a13 = this[7];
|
|
3211
3252
|
const a20 = this[8], a21 = this[9], a22 = this[10], a23 = this[11];
|
|
@@ -3247,10 +3288,10 @@ class Mat4 extends Float32Array {
|
|
|
3247
3288
|
/**
|
|
3248
3289
|
* Calculates the adjugate of a mat4
|
|
3249
3290
|
*
|
|
3250
|
-
* @param {Mat4} out the receiving matrix, defaults to
|
|
3291
|
+
* @param {Mat4} out the receiving matrix, defaults to new mat4()
|
|
3251
3292
|
* @returns {Mat4} out
|
|
3252
3293
|
*/
|
|
3253
|
-
adjoint(out = index.ALWAYS_COPY ?
|
|
3294
|
+
adjoint(out = index.ALWAYS_COPY ? mat4() : this) {
|
|
3254
3295
|
const a00 = this[0], a01 = this[1], a02 = this[2], a03 = this[3];
|
|
3255
3296
|
const a10 = this[4], a11 = this[5], a12 = this[6], a13 = this[7];
|
|
3256
3297
|
const a20 = this[8], a21 = this[9], a22 = this[10], a23 = this[11];
|
|
@@ -3302,7 +3343,7 @@ class Mat4 extends Float32Array {
|
|
|
3302
3343
|
(a01 * a13 - a03 * a11) * (a20 * a32 - a22 * a30) +
|
|
3303
3344
|
(a02 * a13 - a03 * a12) * (a20 * a31 - a21 * a30));
|
|
3304
3345
|
}
|
|
3305
|
-
multiply(b, out = index.ALWAYS_COPY ?
|
|
3346
|
+
multiply(b, out = index.ALWAYS_COPY ? mat4() : this) {
|
|
3306
3347
|
if (b instanceof Vec2)
|
|
3307
3348
|
return b.transformMat4(this);
|
|
3308
3349
|
if (b instanceof Vec3)
|
|
@@ -3348,10 +3389,10 @@ class Mat4 extends Float32Array {
|
|
|
3348
3389
|
* Translates a mat4 by the given Vec3
|
|
3349
3390
|
*
|
|
3350
3391
|
* @param {Vec3} v vector to translate by
|
|
3351
|
-
* @param {Mat4} out the receiving matrix, defaults to
|
|
3392
|
+
* @param {Mat4} out the receiving matrix, defaults to new mat4()
|
|
3352
3393
|
* @returns {Mat4} out
|
|
3353
3394
|
*/
|
|
3354
|
-
translate(v, out = index.ALWAYS_COPY ?
|
|
3395
|
+
translate(v, out = index.ALWAYS_COPY ? mat4() : this) {
|
|
3355
3396
|
const x = v[0], y = v[1], z = v[2];
|
|
3356
3397
|
if (out.exactEquals(this)) {
|
|
3357
3398
|
out[12] = this[0] * x + this[4] * y + this[8] * z + this[12];
|
|
@@ -3386,10 +3427,10 @@ class Mat4 extends Float32Array {
|
|
|
3386
3427
|
* Scales a mat4 by the dimensions in the given Vec3 not using vectorization
|
|
3387
3428
|
*
|
|
3388
3429
|
* @param {Vec3} v the Vec3 to scale the matrix by
|
|
3389
|
-
* @param {Mat4} out the receiving matrix, defaults to
|
|
3430
|
+
* @param {Mat4} out the receiving matrix, defaults to new mat4()
|
|
3390
3431
|
* @returns {Mat4} out
|
|
3391
3432
|
*/
|
|
3392
|
-
scale(v, out = index.ALWAYS_COPY ?
|
|
3433
|
+
scale(v, out = index.ALWAYS_COPY ? mat4() : this) {
|
|
3393
3434
|
const x = v[0], y = v[1], z = v[2];
|
|
3394
3435
|
out[0] = this[0] * x;
|
|
3395
3436
|
out[1] = this[1] * x;
|
|
@@ -3414,10 +3455,10 @@ class Mat4 extends Float32Array {
|
|
|
3414
3455
|
*
|
|
3415
3456
|
* @param {Number} rad the angle to rotate the matrix by
|
|
3416
3457
|
* @param {Vec3} axis the axis to rotate around
|
|
3417
|
-
* @param {Mat4} out the receiving matrix, defaults to
|
|
3458
|
+
* @param {Mat4} out the receiving matrix, defaults to new mat4()
|
|
3418
3459
|
* @returns {Mat4} out
|
|
3419
3460
|
*/
|
|
3420
|
-
rotate(rad, axis, out = index.ALWAYS_COPY ?
|
|
3461
|
+
rotate(rad, axis, out = index.ALWAYS_COPY ? mat4() : this) {
|
|
3421
3462
|
let x = axis[0], y = axis[1], z = axis[2];
|
|
3422
3463
|
let len = Math.sqrt(x * x + y * y + z * z);
|
|
3423
3464
|
if (len < index.EPSILON)
|
|
@@ -3455,10 +3496,10 @@ class Mat4 extends Float32Array {
|
|
|
3455
3496
|
* Rotates a mat4 by the given angle around the X axis
|
|
3456
3497
|
*
|
|
3457
3498
|
* @param {Number} rad the angle to rotate the matrix by
|
|
3458
|
-
* @param {Mat4} out the receiving matrix, defaults to
|
|
3499
|
+
* @param {Mat4} out the receiving matrix, defaults to new mat4()
|
|
3459
3500
|
* @returns {Mat4} out
|
|
3460
3501
|
*/
|
|
3461
|
-
rotateX(rad, out = index.ALWAYS_COPY ?
|
|
3502
|
+
rotateX(rad, out = index.ALWAYS_COPY ? mat4() : this) {
|
|
3462
3503
|
const s = Math.sin(rad), c = Math.cos(rad);
|
|
3463
3504
|
const a10 = this[4], a11 = this[5], a12 = this[6], a13 = this[7];
|
|
3464
3505
|
const a20 = this[8], a21 = this[9], a22 = this[10], a23 = this[11];
|
|
@@ -3486,10 +3527,10 @@ class Mat4 extends Float32Array {
|
|
|
3486
3527
|
* Rotates a mat4 by the given angle around the Y axis
|
|
3487
3528
|
*
|
|
3488
3529
|
* @param {Number} rad the angle to rotate the matrix by
|
|
3489
|
-
* @param {Mat4} out the receiving matrix, defaults to
|
|
3530
|
+
* @param {Mat4} out the receiving matrix, defaults to new mat4()
|
|
3490
3531
|
* @returns {Mat4} out
|
|
3491
3532
|
*/
|
|
3492
|
-
rotateY(rad, out = index.ALWAYS_COPY ?
|
|
3533
|
+
rotateY(rad, out = index.ALWAYS_COPY ? mat4() : this) {
|
|
3493
3534
|
const s = Math.sin(rad), c = Math.cos(rad);
|
|
3494
3535
|
const a00 = this[0], a01 = this[1], a02 = this[2], a03 = this[3];
|
|
3495
3536
|
const a20 = this[8], a21 = this[9], a22 = this[10], a23 = this[11];
|
|
@@ -3517,10 +3558,10 @@ class Mat4 extends Float32Array {
|
|
|
3517
3558
|
* Rotates a mat4 by the given angle around the Z axis
|
|
3518
3559
|
*
|
|
3519
3560
|
* @param {Number} rad the angle to rotate the matrix by
|
|
3520
|
-
* @param {Mat4} out the receiving matrix, defaults to
|
|
3561
|
+
* @param {Mat4} out the receiving matrix, defaults to new mat4()
|
|
3521
3562
|
* @returns {Mat4} out
|
|
3522
3563
|
*/
|
|
3523
|
-
rotateZ(rad, out = index.ALWAYS_COPY ?
|
|
3564
|
+
rotateZ(rad, out = index.ALWAYS_COPY ? mat4() : this) {
|
|
3524
3565
|
const s = Math.sin(rad), c = Math.cos(rad);
|
|
3525
3566
|
const a00 = this[0], a01 = this[1], a02 = this[2], a03 = this[3];
|
|
3526
3567
|
const a10 = this[4], a11 = this[5], a12 = this[6], a13 = this[7];
|
|
@@ -3676,10 +3717,10 @@ class Mat4 extends Float32Array {
|
|
|
3676
3717
|
* Creates a matrix from a vector translation
|
|
3677
3718
|
*
|
|
3678
3719
|
* @param {Vec3} v translation vector
|
|
3679
|
-
* @param {Mat4} out the receiving matrix, defaults to
|
|
3720
|
+
* @param {Mat4} out the receiving matrix, defaults to mat4()
|
|
3680
3721
|
* @returns {Mat4} out
|
|
3681
3722
|
*/
|
|
3682
|
-
static fromTranslation(v, out =
|
|
3723
|
+
static fromTranslation(v, out = mat4()) {
|
|
3683
3724
|
out[0] = out[5] = out[10] = out[15] = 1;
|
|
3684
3725
|
out[1] = out[2] = out[3] = out[4] = out[6] = out[7] = out[8] = out[9] = out[11] = 0;
|
|
3685
3726
|
out[12] = v[0];
|
|
@@ -3691,10 +3732,10 @@ class Mat4 extends Float32Array {
|
|
|
3691
3732
|
* Creates a matrix from a vector scaling
|
|
3692
3733
|
*
|
|
3693
3734
|
* @param {Vec3} v scaling vector
|
|
3694
|
-
* @param {Mat4} out the receiving matrix, defaults to
|
|
3735
|
+
* @param {Mat4} out the receiving matrix, defaults to mat4()
|
|
3695
3736
|
* @returns {Mat4} out
|
|
3696
3737
|
*/
|
|
3697
|
-
static fromScaling(v, out =
|
|
3738
|
+
static fromScaling(v, out = mat4()) {
|
|
3698
3739
|
out[0] = v[0];
|
|
3699
3740
|
out[5] = v[1];
|
|
3700
3741
|
out[10] = v[2];
|
|
@@ -3707,10 +3748,10 @@ class Mat4 extends Float32Array {
|
|
|
3707
3748
|
*
|
|
3708
3749
|
* @param {Number} rad the angle to rotate the matrix by
|
|
3709
3750
|
* @param {Vec3} axis the axis to rotate around
|
|
3710
|
-
* @param {Mat4} out the receiving matrix, defaults to
|
|
3751
|
+
* @param {Mat4} out the receiving matrix, defaults to mat4()
|
|
3711
3752
|
* @returns {Mat4} out
|
|
3712
3753
|
*/
|
|
3713
|
-
static fromRotation(rad, axis, out =
|
|
3754
|
+
static fromRotation(rad, axis, out = mat4()) {
|
|
3714
3755
|
let x = axis[0], y = axis[1], z = axis[2];
|
|
3715
3756
|
let len = Math.sqrt(x * x + y * y + z * z);
|
|
3716
3757
|
if (len < index.EPSILON)
|
|
@@ -3740,10 +3781,10 @@ class Mat4 extends Float32Array {
|
|
|
3740
3781
|
* Creates a matrix from the given angle around the X axis
|
|
3741
3782
|
*
|
|
3742
3783
|
* @param {Number} rad the angle to rotate the matrix by
|
|
3743
|
-
* @param {Mat4} out the receiving matrix, defaults to
|
|
3784
|
+
* @param {Mat4} out the receiving matrix, defaults to mat4()
|
|
3744
3785
|
* @returns {Mat4} out
|
|
3745
3786
|
*/
|
|
3746
|
-
static fromXRotation(rad, out =
|
|
3787
|
+
static fromXRotation(rad, out = mat4()) {
|
|
3747
3788
|
const s = Math.sin(rad), c = Math.cos(rad);
|
|
3748
3789
|
out[0] = 1;
|
|
3749
3790
|
out[1] = out[2] = out[3] = out[4] = out[7] = out[8] = out[11] = out[12] = out[13] = out[14] = 0;
|
|
@@ -3758,10 +3799,10 @@ class Mat4 extends Float32Array {
|
|
|
3758
3799
|
* Creates a matrix from the given angle around the Y axis
|
|
3759
3800
|
*
|
|
3760
3801
|
* @param {Number} rad the angle to rotate the matrix by
|
|
3761
|
-
* @param {Mat4} out the receiving matrix, defaults to
|
|
3802
|
+
* @param {Mat4} out the receiving matrix, defaults to mat4()
|
|
3762
3803
|
* @returns {Mat4} out
|
|
3763
3804
|
*/
|
|
3764
|
-
static fromYRotation(rad, out =
|
|
3805
|
+
static fromYRotation(rad, out = mat4()) {
|
|
3765
3806
|
const s = Math.sin(rad), c = Math.cos(rad);
|
|
3766
3807
|
out[0] = c;
|
|
3767
3808
|
out[1] = out[3] = out[4] = out[6] = out[7] = out[9] = out[11] = out[12] = out[13] = out[14] = 0;
|
|
@@ -3775,10 +3816,10 @@ class Mat4 extends Float32Array {
|
|
|
3775
3816
|
* Creates a matrix from the given angle around the Z axis
|
|
3776
3817
|
*
|
|
3777
3818
|
* @param {Number} rad the angle to rotate the matrix by
|
|
3778
|
-
* @param {Mat4} out the receiving matrix, defaults to
|
|
3819
|
+
* @param {Mat4} out the receiving matrix, defaults to mat4()
|
|
3779
3820
|
* @returns {Mat4} out
|
|
3780
3821
|
*/
|
|
3781
|
-
static fromZRotation(rad, out =
|
|
3822
|
+
static fromZRotation(rad, out = mat4()) {
|
|
3782
3823
|
const s = Math.sin(rad), c = Math.cos(rad);
|
|
3783
3824
|
out[0] = c;
|
|
3784
3825
|
out[1] = s;
|
|
@@ -3793,10 +3834,10 @@ class Mat4 extends Float32Array {
|
|
|
3793
3834
|
*
|
|
3794
3835
|
* @param {Quat} q rotation quaternion
|
|
3795
3836
|
* @param {Vec3} v translation vector
|
|
3796
|
-
* @param {Mat4} out the receiving matrix, defaults to
|
|
3837
|
+
* @param {Mat4} out the receiving matrix, defaults to mat4()
|
|
3797
3838
|
* @returns {Mat4} out
|
|
3798
3839
|
*/
|
|
3799
|
-
static fromRotationTranslation(q, v, out =
|
|
3840
|
+
static fromRotationTranslation(q, v, out = mat4()) {
|
|
3800
3841
|
const x = q[0], y = q[1], z = q[2], w = q[3];
|
|
3801
3842
|
const x2 = x + x, y2 = y + y, z2 = z + z;
|
|
3802
3843
|
const xx = x * x2, xy = x * y2, xz = x * z2;
|
|
@@ -3824,10 +3865,10 @@ class Mat4 extends Float32Array {
|
|
|
3824
3865
|
* @param {Quat} q rotation quaternion
|
|
3825
3866
|
* @param {Vec3} v translation vector
|
|
3826
3867
|
* @param {Vec3} s scaling vector
|
|
3827
|
-
* @param {Mat4} out the receiving matrix, defaults to
|
|
3868
|
+
* @param {Mat4} out the receiving matrix, defaults to mat4()
|
|
3828
3869
|
* @returns {Mat4} out
|
|
3829
3870
|
*/
|
|
3830
|
-
static fromRotationTranslationScale(q, v, s, out =
|
|
3871
|
+
static fromRotationTranslationScale(q, v, s, out = mat4()) {
|
|
3831
3872
|
const x = q[0], y = q[1], z = q[2], w = q[3];
|
|
3832
3873
|
const x2 = x + x, y2 = y + y, z2 = z + z;
|
|
3833
3874
|
const xx = x * x2, xy = x * y2, xz = x * z2;
|
|
@@ -3857,10 +3898,10 @@ class Mat4 extends Float32Array {
|
|
|
3857
3898
|
* @param {Vec3} v translation vector
|
|
3858
3899
|
* @param {Vec3} s scaling vector
|
|
3859
3900
|
* @param {Vec3} o the origin vector
|
|
3860
|
-
* @param {Mat4} out the receiving matrix, defaults to
|
|
3901
|
+
* @param {Mat4} out the receiving matrix, defaults to mat4()
|
|
3861
3902
|
* @returns {Mat4} out
|
|
3862
3903
|
*/
|
|
3863
|
-
static fromRotationTranslationScaleOrigin(q, v, s, o, out =
|
|
3904
|
+
static fromRotationTranslationScaleOrigin(q, v, s, o, out = mat4()) {
|
|
3864
3905
|
const x = q[0], y = q[1], z = q[2], w = q[3];
|
|
3865
3906
|
const x2 = x + x, y2 = y + y, z2 = z + z;
|
|
3866
3907
|
const xx = x * x2, xy = x * y2, xz = x * z2;
|
|
@@ -3897,10 +3938,10 @@ class Mat4 extends Float32Array {
|
|
|
3897
3938
|
* Calculates a 4x4 matrix from the given quaternion
|
|
3898
3939
|
*
|
|
3899
3940
|
* @param {Quat} q quaternion to create matrix from
|
|
3900
|
-
* @param {Mat4} out the receiving matrix, defaults to
|
|
3941
|
+
* @param {Mat4} out the receiving matrix, defaults to mat4()
|
|
3901
3942
|
* @returns {Mat4} out
|
|
3902
3943
|
*/
|
|
3903
|
-
static fromQuat(q, out =
|
|
3944
|
+
static fromQuat(q, out = mat4()) {
|
|
3904
3945
|
const x = q[0], y = q[1], z = q[2], w = q[3];
|
|
3905
3946
|
const x2 = x + x, y2 = y + y, z2 = z + z;
|
|
3906
3947
|
const xx = x * x2, yx = y * x2, yy = y * y2;
|
|
@@ -3928,10 +3969,10 @@ class Mat4 extends Float32Array {
|
|
|
3928
3969
|
* @param {Number} top top bound of the frustum
|
|
3929
3970
|
* @param {Number} near near bound of the frustum
|
|
3930
3971
|
* @param {Number} far far bound of the frustum
|
|
3931
|
-
* @param {Mat4} out the receiving matrix, defaults to
|
|
3972
|
+
* @param {Mat4} out the receiving matrix, defaults to mat4()
|
|
3932
3973
|
* @returns {Mat4} out
|
|
3933
3974
|
*/
|
|
3934
|
-
static frustum(left, right, bottom, top, near, far, out =
|
|
3975
|
+
static frustum(left, right, bottom, top, near, far, out = mat4()) {
|
|
3935
3976
|
const rl = 1 / (right - left);
|
|
3936
3977
|
const tb = 1 / (top - bottom);
|
|
3937
3978
|
const nf = 1 / (near - far);
|
|
@@ -3955,10 +3996,10 @@ class Mat4 extends Float32Array {
|
|
|
3955
3996
|
* @param {Number} aspect aspect ratio, typically viewport width / height
|
|
3956
3997
|
* @param {Number} near near bound of the frustum
|
|
3957
3998
|
* @param {Number | null} far far bound of the frustum, can be null or Infinity
|
|
3958
|
-
* @param {Mat4} out the receiving matrix, defaults to
|
|
3999
|
+
* @param {Mat4} out the receiving matrix, defaults to mat4()
|
|
3959
4000
|
* @returns {Mat4} out
|
|
3960
4001
|
*/
|
|
3961
|
-
static perspectiveNO(fovy, aspect, near, far, out =
|
|
4002
|
+
static perspectiveNO(fovy, aspect, near, far, out = mat4()) {
|
|
3962
4003
|
const f = 1.0 / Math.tan(fovy / 2);
|
|
3963
4004
|
const lh = index.LEFT_HANDED;
|
|
3964
4005
|
out[0] = f / aspect;
|
|
@@ -3985,10 +4026,10 @@ class Mat4 extends Float32Array {
|
|
|
3985
4026
|
* @param {Number} aspect aspect ratio, typically viewport width / height
|
|
3986
4027
|
* @param {Number} near near bound of the frustum
|
|
3987
4028
|
* @param {Number | null} far far bound of the frustum, can be null or Infinity
|
|
3988
|
-
* @param {Mat4} out the receiving matrix, defaults to
|
|
4029
|
+
* @param {Mat4} out the receiving matrix, defaults to mat4()
|
|
3989
4030
|
* @returns {Mat4} out
|
|
3990
4031
|
*/
|
|
3991
|
-
static perspectiveZO(fovy, aspect, near, far, out =
|
|
4032
|
+
static perspectiveZO(fovy, aspect, near, far, out = mat4()) {
|
|
3992
4033
|
const f = 1.0 / Math.tan(fovy / 2);
|
|
3993
4034
|
const lh = index.LEFT_HANDED;
|
|
3994
4035
|
out[0] = f / aspect;
|
|
@@ -4022,10 +4063,10 @@ class Mat4 extends Float32Array {
|
|
|
4022
4063
|
* @param {Object} fov object containing upDegrees, downDegrees, leftDegrees, rightDegrees
|
|
4023
4064
|
* @param {Number} near near bound of the frustum
|
|
4024
4065
|
* @param {Number} far far bound of the frustum
|
|
4025
|
-
* @param {Mat4} out the receiving matrix, defaults to
|
|
4066
|
+
* @param {Mat4} out the receiving matrix, defaults to mat4()
|
|
4026
4067
|
* @returns {Mat4} out
|
|
4027
4068
|
*/
|
|
4028
|
-
static perspectiveFromFieldOfView(fov, near, far, out =
|
|
4069
|
+
static perspectiveFromFieldOfView(fov, near, far, out = mat4()) {
|
|
4029
4070
|
const upTan = Math.tan((fov.upDegrees * Math.PI) / 180.0);
|
|
4030
4071
|
const downTan = Math.tan((fov.downDegrees * Math.PI) / 180.0);
|
|
4031
4072
|
const leftTan = Math.tan((fov.leftDegrees * Math.PI) / 180.0);
|
|
@@ -4062,10 +4103,10 @@ class Mat4 extends Float32Array {
|
|
|
4062
4103
|
* @param {Number} top top bound of the frustum
|
|
4063
4104
|
* @param {Number} near near bound of the frustum
|
|
4064
4105
|
* @param {Number} far far bound of the frustum
|
|
4065
|
-
* @param {Mat4} out the receiving matrix, defaults to
|
|
4106
|
+
* @param {Mat4} out the receiving matrix, defaults to mat4()
|
|
4066
4107
|
* @returns {Mat4} out
|
|
4067
4108
|
*/
|
|
4068
|
-
static orthoNO(left, right, bottom, top, near, far, out =
|
|
4109
|
+
static orthoNO(left, right, bottom, top, near, far, out = mat4()) {
|
|
4069
4110
|
const lr = 1 / (left - right);
|
|
4070
4111
|
const bt = 1 / (bottom - top);
|
|
4071
4112
|
const nf = 1 / (near - far);
|
|
@@ -4099,10 +4140,10 @@ class Mat4 extends Float32Array {
|
|
|
4099
4140
|
* @param {Number} top top bound of the frustum
|
|
4100
4141
|
* @param {Number} near near bound of the frustum
|
|
4101
4142
|
* @param {Number} far far bound of the frustum
|
|
4102
|
-
* @param {Mat4} out the receiving matrix, defaults to
|
|
4143
|
+
* @param {Mat4} out the receiving matrix, defaults to mat4()
|
|
4103
4144
|
* @returns {Mat4} out
|
|
4104
4145
|
*/
|
|
4105
|
-
static orthoZO(left, right, bottom, top, near, far, out =
|
|
4146
|
+
static orthoZO(left, right, bottom, top, near, far, out = mat4()) {
|
|
4106
4147
|
const lr = 1 / (left - right);
|
|
4107
4148
|
const bt = 1 / (bottom - top);
|
|
4108
4149
|
const nf = 1 / (near - far);
|
|
@@ -4132,10 +4173,10 @@ class Mat4 extends Float32Array {
|
|
|
4132
4173
|
* @param {Vec3} eye position of the viewer
|
|
4133
4174
|
* @param {Vec3} center point the viewer is looking at
|
|
4134
4175
|
* @param {Vec3} up vector pointing up
|
|
4135
|
-
* @param {Mat4} out the receiving matrix, defaults to
|
|
4176
|
+
* @param {Mat4} out the receiving matrix, defaults to mat4()
|
|
4136
4177
|
* @returns {Mat4} out
|
|
4137
4178
|
*/
|
|
4138
|
-
static lookAt(eye, center, up, out =
|
|
4179
|
+
static lookAt(eye, center, up, out = mat4()) {
|
|
4139
4180
|
let x0, x1, x2, y0, y1, y2, z0, z1, z2, len;
|
|
4140
4181
|
const eyex = eye[0], eyey = eye[1], eyez = eye[2];
|
|
4141
4182
|
const upx = up[0], upy = up[1], upz = up[2];
|
|
@@ -4227,10 +4268,10 @@ class Mat4 extends Float32Array {
|
|
|
4227
4268
|
* @param {Vec3} eye position of the viewer
|
|
4228
4269
|
* @param {Vec3} target point the viewer is looking at
|
|
4229
4270
|
* @param {Vec3} up vector pointing up
|
|
4230
|
-
* @param {Mat4} out the receiving matrix, defaults to
|
|
4271
|
+
* @param {Mat4} out the receiving matrix, defaults to mat4()
|
|
4231
4272
|
* @returns {Mat4} out
|
|
4232
4273
|
*/
|
|
4233
|
-
static targetTo(eye, target, up, out =
|
|
4274
|
+
static targetTo(eye, target, up, out = mat4()) {
|
|
4234
4275
|
const eyex = eye[0], eyey = eye[1], eyez = eye[2];
|
|
4235
4276
|
const upx = up[0], upy = up[1], upz = up[2];
|
|
4236
4277
|
let z0, z1, z2;
|
|
@@ -4289,7 +4330,7 @@ class Mat4 extends Float32Array {
|
|
|
4289
4330
|
* @param {Mat4} out the receiving matrix, defaults to a new Mat4
|
|
4290
4331
|
* @returns {Mat4} out
|
|
4291
4332
|
*/
|
|
4292
|
-
static infinitePerspective(fovy, aspect, near, out =
|
|
4333
|
+
static infinitePerspective(fovy, aspect, near, out = mat4()) {
|
|
4293
4334
|
const f = 1.0 / Math.tan(fovy / 2);
|
|
4294
4335
|
const lh = index.LEFT_HANDED;
|
|
4295
4336
|
out[0] = f / aspect;
|
|
@@ -4346,7 +4387,7 @@ class Mat4 extends Float32Array {
|
|
|
4346
4387
|
const a10 = model[4], a11 = model[5], a12 = model[6], a13 = model[7];
|
|
4347
4388
|
const a20 = model[8], a21 = model[9], a22 = model[10], a23 = model[11];
|
|
4348
4389
|
const a30 = model[12], a31 = model[13], a32 = model[14], a33 = model[15];
|
|
4349
|
-
const pm =
|
|
4390
|
+
const pm = mat4();
|
|
4350
4391
|
let b0 = proj[0], b1 = proj[1], b2 = proj[2], b3 = proj[3];
|
|
4351
4392
|
pm[0] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
|
|
4352
4393
|
pm[1] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
|
|
@@ -4404,10 +4445,10 @@ class Mat4 extends Float32Array {
|
|
|
4404
4445
|
* Adds two mat4's
|
|
4405
4446
|
*
|
|
4406
4447
|
* @param {Mat4} b the second operand
|
|
4407
|
-
* @param {Mat4} out the receiving matrix, defaults to
|
|
4448
|
+
* @param {Mat4} out the receiving matrix, defaults to new mat4()
|
|
4408
4449
|
* @returns {Mat4} out
|
|
4409
4450
|
*/
|
|
4410
|
-
plus(b, out = index.ALWAYS_COPY ?
|
|
4451
|
+
plus(b, out = index.ALWAYS_COPY ? mat4() : this) {
|
|
4411
4452
|
out[0] = this[0] + b[0];
|
|
4412
4453
|
out[1] = this[1] + b[1];
|
|
4413
4454
|
out[2] = this[2] + b[2];
|
|
@@ -4430,10 +4471,10 @@ class Mat4 extends Float32Array {
|
|
|
4430
4471
|
* Subtracts matrix b from a mat4
|
|
4431
4472
|
*
|
|
4432
4473
|
* @param {Mat4} b the second operand
|
|
4433
|
-
* @param {Mat4} out the receiving matrix, defaults to
|
|
4474
|
+
* @param {Mat4} out the receiving matrix, defaults to new mat4()
|
|
4434
4475
|
* @returns {Mat4} out
|
|
4435
4476
|
*/
|
|
4436
|
-
minus(b, out = index.ALWAYS_COPY ?
|
|
4477
|
+
minus(b, out = index.ALWAYS_COPY ? mat4() : this) {
|
|
4437
4478
|
out[0] = this[0] - b[0];
|
|
4438
4479
|
out[1] = this[1] - b[1];
|
|
4439
4480
|
out[2] = this[2] - b[2];
|
|
@@ -4456,10 +4497,10 @@ class Mat4 extends Float32Array {
|
|
|
4456
4497
|
* Multiplies each element of a mat4 by a scalar number
|
|
4457
4498
|
*
|
|
4458
4499
|
* @param {Number} b amount to scale the matrix's elements by
|
|
4459
|
-
* @param {Mat4} out the receiving matrix, defaults to
|
|
4500
|
+
* @param {Mat4} out the receiving matrix, defaults to new mat4()
|
|
4460
4501
|
* @returns {Mat4} out
|
|
4461
4502
|
*/
|
|
4462
|
-
scaleScalar(b, out = index.ALWAYS_COPY ?
|
|
4503
|
+
scaleScalar(b, out = index.ALWAYS_COPY ? mat4() : this) {
|
|
4463
4504
|
out[0] = this[0] * b;
|
|
4464
4505
|
out[1] = this[1] * b;
|
|
4465
4506
|
out[2] = this[2] * b;
|
|
@@ -4483,10 +4524,10 @@ class Mat4 extends Float32Array {
|
|
|
4483
4524
|
*
|
|
4484
4525
|
* @param {Mat4} b the second operand
|
|
4485
4526
|
* @param {Number} scale the amount to scale b's elements by before adding
|
|
4486
|
-
* @param {Mat4} out the receiving matrix, defaults to
|
|
4527
|
+
* @param {Mat4} out the receiving matrix, defaults to new mat4()
|
|
4487
4528
|
* @returns {Mat4} out
|
|
4488
4529
|
*/
|
|
4489
|
-
multiplyScalarAndAdd(b, scale, out = index.ALWAYS_COPY ?
|
|
4530
|
+
multiplyScalarAndAdd(b, scale, out = index.ALWAYS_COPY ? mat4() : this) {
|
|
4490
4531
|
out[0] = this[0] + b[0] * scale;
|
|
4491
4532
|
out[1] = this[1] + b[1] * scale;
|
|
4492
4533
|
out[2] = this[2] + b[2] * scale;
|
|
@@ -4550,7 +4591,7 @@ Mat4.prototype.mult = Mat4.prototype.multiply;
|
|
|
4550
4591
|
Mat4.prototype.times = Mat4.prototype.multiply;
|
|
4551
4592
|
Mat4.prototype.str = Mat4.prototype.toString;
|
|
4552
4593
|
Mat4.prototype.multiplyScalar = Mat4.prototype.scaleScalar;
|
|
4553
|
-
const
|
|
4594
|
+
const createMat4 = (...args) => {
|
|
4554
4595
|
const out = new Mat4();
|
|
4555
4596
|
let i = 0;
|
|
4556
4597
|
for (const a of args) {
|
|
@@ -4561,7 +4602,9 @@ const mat4 = Object.assign((...args) => {
|
|
|
4561
4602
|
out[i++] = v;
|
|
4562
4603
|
}
|
|
4563
4604
|
return out;
|
|
4564
|
-
}
|
|
4605
|
+
};
|
|
4606
|
+
Object.setPrototypeOf(createMat4, Mat4);
|
|
4607
|
+
const mat4 = createMat4;
|
|
4565
4608
|
const mat4x4 = mat4;
|
|
4566
4609
|
|
|
4567
4610
|
/**
|
|
@@ -4569,9 +4612,9 @@ const mat4x4 = mat4;
|
|
|
4569
4612
|
* @extends Vec4
|
|
4570
4613
|
*/
|
|
4571
4614
|
class Quat extends Float32Array {
|
|
4572
|
-
static get identity() { return
|
|
4573
|
-
static get Identity() { return
|
|
4574
|
-
static get IDENTITY() { return
|
|
4615
|
+
static get identity() { return quat(0, 0, 0, 1); }
|
|
4616
|
+
static get Identity() { return quat(0, 0, 0, 1); }
|
|
4617
|
+
static get IDENTITY() { return quat(0, 0, 0, 1); }
|
|
4575
4618
|
/**
|
|
4576
4619
|
* Creates a new quaternion
|
|
4577
4620
|
*
|
|
@@ -4591,10 +4634,10 @@ class Quat extends Float32Array {
|
|
|
4591
4634
|
* Calculates the Hamilton product of two quaternions
|
|
4592
4635
|
*
|
|
4593
4636
|
* @param {Quat} b the second operand
|
|
4594
|
-
* @param {Quat} out the receiving quaternion, defaults to
|
|
4637
|
+
* @param {Quat} out the receiving quaternion, defaults to new quat()
|
|
4595
4638
|
* @returns {Quat} out
|
|
4596
4639
|
*/
|
|
4597
|
-
multiply(b, out = index.ALWAYS_COPY ?
|
|
4640
|
+
multiply(b, out = index.ALWAYS_COPY ? quat() : this) {
|
|
4598
4641
|
if (typeof b === 'number') {
|
|
4599
4642
|
out[0] = this[0] * b;
|
|
4600
4643
|
out[1] = this[1] * b;
|
|
@@ -4632,7 +4675,7 @@ class Quat extends Float32Array {
|
|
|
4632
4675
|
*
|
|
4633
4676
|
* @param {Vec3} axis the axis around which to rotate
|
|
4634
4677
|
* @param {Number} rad the angle in radians
|
|
4635
|
-
* @param {Quat} out the receiving quaternion, defaults to
|
|
4678
|
+
* @param {Quat} out the receiving quaternion, defaults to new quat()
|
|
4636
4679
|
* @returns {Quat} out
|
|
4637
4680
|
*/
|
|
4638
4681
|
setAxisAngle(axis, rad, out = index.ALWAYS_COPY ? quat() : this) {
|
|
@@ -4687,7 +4730,7 @@ class Quat extends Float32Array {
|
|
|
4687
4730
|
* Rotates a quaternion by the given angle about the X axis
|
|
4688
4731
|
*
|
|
4689
4732
|
* @param {Number} rad angle in radians to rotate
|
|
4690
|
-
* @param {Quat} out the receiving quaternion, defaults to
|
|
4733
|
+
* @param {Quat} out the receiving quaternion, defaults to new quat()
|
|
4691
4734
|
* @returns {Quat} out
|
|
4692
4735
|
*/
|
|
4693
4736
|
rotateX(rad, out = index.ALWAYS_COPY ? quat() : this) {
|
|
@@ -4704,7 +4747,7 @@ class Quat extends Float32Array {
|
|
|
4704
4747
|
* Rotates a quaternion by the given angle about the Y axis
|
|
4705
4748
|
*
|
|
4706
4749
|
* @param {Number} rad angle in radians to rotate
|
|
4707
|
-
* @param {Quat} out the receiving quaternion, defaults to
|
|
4750
|
+
* @param {Quat} out the receiving quaternion, defaults to new quat()
|
|
4708
4751
|
* @returns {Quat} out
|
|
4709
4752
|
*/
|
|
4710
4753
|
rotateY(rad, out = index.ALWAYS_COPY ? quat() : this) {
|
|
@@ -4721,7 +4764,7 @@ class Quat extends Float32Array {
|
|
|
4721
4764
|
* Rotates a quaternion by the given angle about the Z axis
|
|
4722
4765
|
*
|
|
4723
4766
|
* @param {Number} rad angle in radians to rotate
|
|
4724
|
-
* @param {Quat} out the receiving quaternion, defaults to
|
|
4767
|
+
* @param {Quat} out the receiving quaternion, defaults to new quat()
|
|
4725
4768
|
* @returns {Quat} out
|
|
4726
4769
|
*/
|
|
4727
4770
|
rotateZ(rad, out = index.ALWAYS_COPY ? quat() : this) {
|
|
@@ -4764,7 +4807,7 @@ class Quat extends Float32Array {
|
|
|
4764
4807
|
/**
|
|
4765
4808
|
* Calculates the exponential of the unit quaternion
|
|
4766
4809
|
*
|
|
4767
|
-
* @param {Quat} out the receiving quaternion, defaults to
|
|
4810
|
+
* @param {Quat} out the receiving quaternion, defaults to new quat()
|
|
4768
4811
|
* @returns {Quat} out
|
|
4769
4812
|
*/
|
|
4770
4813
|
exp(out = index.ALWAYS_COPY ? quat() : this) {
|
|
@@ -4798,7 +4841,7 @@ class Quat extends Float32Array {
|
|
|
4798
4841
|
/**
|
|
4799
4842
|
* Calculates the natural logarithm of the unit quaternion
|
|
4800
4843
|
*
|
|
4801
|
-
* @param {Quat} out the receiving quaternion, defaults to
|
|
4844
|
+
* @param {Quat} out the receiving quaternion, defaults to new quat()
|
|
4802
4845
|
* @returns {Quat} out
|
|
4803
4846
|
*/
|
|
4804
4847
|
ln(out = index.ALWAYS_COPY ? quat() : this) {
|
|
@@ -4872,7 +4915,7 @@ class Quat extends Float32Array {
|
|
|
4872
4915
|
*
|
|
4873
4916
|
* @param {Quat} b the second operand
|
|
4874
4917
|
* @param {Number} t interpolation amount, in the range [0-1], between the two inputs
|
|
4875
|
-
* @param {Quat} out the receiving quaternion, defaults to
|
|
4918
|
+
* @param {Quat} out the receiving quaternion, defaults to new quat()
|
|
4876
4919
|
* @returns {Quat} out
|
|
4877
4920
|
*/
|
|
4878
4921
|
slerp(b, t, out = index.ALWAYS_COPY ? quat() : this) {
|
|
@@ -4951,7 +4994,7 @@ class Quat extends Float32Array {
|
|
|
4951
4994
|
/**
|
|
4952
4995
|
* Calculates the inverse of a quaternion
|
|
4953
4996
|
*
|
|
4954
|
-
* @param {Quat} out the receiving quaternion, defaults to
|
|
4997
|
+
* @param {Quat} out the receiving quaternion, defaults to new quat()
|
|
4955
4998
|
* @returns {Quat} out
|
|
4956
4999
|
*/
|
|
4957
5000
|
invert(out = index.ALWAYS_COPY ? quat() : this) {
|
|
@@ -4982,7 +5025,7 @@ class Quat extends Float32Array {
|
|
|
4982
5025
|
/**
|
|
4983
5026
|
* Calculates the conjugate of a quaternion
|
|
4984
5027
|
*
|
|
4985
|
-
* @param {Quat} out the receiving quaternion, defaults to
|
|
5028
|
+
* @param {Quat} out the receiving quaternion, defaults to new quat()
|
|
4986
5029
|
* @returns {Quat} out
|
|
4987
5030
|
*/
|
|
4988
5031
|
conjugate(out = index.ALWAYS_COPY ? quat() : this) {
|
|
@@ -5203,11 +5246,12 @@ class Quat extends Float32Array {
|
|
|
5203
5246
|
/**
|
|
5204
5247
|
* Normalizes a quaternion
|
|
5205
5248
|
*
|
|
5206
|
-
* @param {Quat}
|
|
5249
|
+
* @param {Quat} q the quaternion to normalize
|
|
5250
|
+
* @param {Quat} out the receiving vector, defaults to new quat()
|
|
5207
5251
|
* @returns {Quat} out
|
|
5208
5252
|
*/
|
|
5209
|
-
normalize(out =
|
|
5210
|
-
const x =
|
|
5253
|
+
static normalize(q, out = quat()) {
|
|
5254
|
+
const x = q[0], y = q[1], z = q[2], w = q[3];
|
|
5211
5255
|
let len = x * x + y * y + z * z + w * w;
|
|
5212
5256
|
if (len > 0) {
|
|
5213
5257
|
len = 1.0 / Math.sqrt(len);
|
|
@@ -5218,6 +5262,15 @@ class Quat extends Float32Array {
|
|
|
5218
5262
|
out[3] = w * len;
|
|
5219
5263
|
return out;
|
|
5220
5264
|
}
|
|
5265
|
+
/**
|
|
5266
|
+
* Normalizes a quaternion
|
|
5267
|
+
*
|
|
5268
|
+
* @param {Quat} out the receiving vector, defaults to new quat()
|
|
5269
|
+
* @returns {Quat} out
|
|
5270
|
+
*/
|
|
5271
|
+
normalize(out = index.ALWAYS_COPY ? quat() : this) {
|
|
5272
|
+
return Quat.normalize(this, out);
|
|
5273
|
+
}
|
|
5221
5274
|
/**
|
|
5222
5275
|
* Creates a quaternion that looks along the given direction vector
|
|
5223
5276
|
*
|
|
@@ -5226,7 +5279,7 @@ class Quat extends Float32Array {
|
|
|
5226
5279
|
* @param {Quat} out the receiving quaternion, defaults to quat()
|
|
5227
5280
|
* @returns {Quat} out
|
|
5228
5281
|
*/
|
|
5229
|
-
static quatLookAt(direction, up, out =
|
|
5282
|
+
static quatLookAt(direction, up, out = quat()) {
|
|
5230
5283
|
const f = vec3(direction[0], direction[1], direction[2]).normalize();
|
|
5231
5284
|
const s = Vec3.cross(f, up).normalize();
|
|
5232
5285
|
const u = Vec3.cross(s, f);
|
|
@@ -5346,7 +5399,10 @@ Quat.prototype.mul = Quat.prototype.multiply;
|
|
|
5346
5399
|
Quat.prototype.scale = Quat.prototype.multiply;
|
|
5347
5400
|
Quat.prototype.times = Quat.prototype.multiply;
|
|
5348
5401
|
Quat.prototype.str = Quat.prototype.toString;
|
|
5349
|
-
|
|
5402
|
+
Quat.prototype.normalized = Quat.prototype.normalize;
|
|
5403
|
+
const createQuat = (x = 0, y = 0, z = 0, w = 1) => new Quat(x, y, z, w);
|
|
5404
|
+
Object.setPrototypeOf(createQuat, Quat);
|
|
5405
|
+
const quat = createQuat;
|
|
5350
5406
|
|
|
5351
5407
|
/**
|
|
5352
5408
|
* Dual Quaternion for rigid body transformations (rotation + translation)
|
|
@@ -5354,9 +5410,9 @@ const quat = Object.assign((x = 0, y = 0, z = 0, w = 1) => new Quat(x, y, z, w),
|
|
|
5354
5410
|
* @extends Float32Array
|
|
5355
5411
|
*/
|
|
5356
5412
|
class Quat2 extends Float32Array {
|
|
5357
|
-
static get identity() { return
|
|
5358
|
-
static get Identity() { return
|
|
5359
|
-
static get IDENTITY() { return
|
|
5413
|
+
static get identity() { return quat2(0, 0, 0, 1, 0, 0, 0, 0); }
|
|
5414
|
+
static get Identity() { return quat2(0, 0, 0, 1, 0, 0, 0, 0); }
|
|
5415
|
+
static get IDENTITY() { return quat2(0, 0, 0, 1, 0, 0, 0, 0); }
|
|
5360
5416
|
/**
|
|
5361
5417
|
* Creates a new dual quaternion
|
|
5362
5418
|
*
|
|
@@ -5375,11 +5431,11 @@ class Quat2 extends Float32Array {
|
|
|
5375
5431
|
* Multiply two dual quaternions
|
|
5376
5432
|
*
|
|
5377
5433
|
* @param {Quat2} b the second operand
|
|
5378
|
-
* @param {Quat2} out the receiving dual quaternion, defaults to
|
|
5434
|
+
* @param {Quat2} out the receiving dual quaternion, defaults to new quat2()
|
|
5379
5435
|
* @returns {Quat2} out
|
|
5380
5436
|
*/
|
|
5381
5437
|
// @ts-ignore
|
|
5382
|
-
this.multiply = (b, out = index.ALWAYS_COPY ?
|
|
5438
|
+
this.multiply = (b, out = index.ALWAYS_COPY ? quat2() : this) => {
|
|
5383
5439
|
const ax0 = this[0], ay0 = this[1], az0 = this[2], aw0 = this[3];
|
|
5384
5440
|
const bx1 = b[4], by1 = b[5], bz1 = b[6], bw1 = b[7];
|
|
5385
5441
|
const ax1 = this[4], ay1 = this[5], az1 = this[6], aw1 = this[7];
|
|
@@ -5481,7 +5537,7 @@ class Quat2 extends Float32Array {
|
|
|
5481
5537
|
* @param {Quat2} out the receiving dual quaternion, defaults to quat2()
|
|
5482
5538
|
* @returns {Quat2} out
|
|
5483
5539
|
*/
|
|
5484
|
-
static fromRotationTranslation(q, t, out =
|
|
5540
|
+
static fromRotationTranslation(q, t, out = quat2()) {
|
|
5485
5541
|
const ax = t[0] * 0.5, ay = t[1] * 0.5, az = t[2] * 0.5;
|
|
5486
5542
|
const bx = q[0], by = q[1], bz = q[2], bw = q[3];
|
|
5487
5543
|
out[0] = bx;
|
|
@@ -5501,7 +5557,7 @@ class Quat2 extends Float32Array {
|
|
|
5501
5557
|
* @param {Quat2} out the receiving dual quaternion, defaults to quat2()
|
|
5502
5558
|
* @returns {Quat2} out
|
|
5503
5559
|
*/
|
|
5504
|
-
static fromTranslation(t, out =
|
|
5560
|
+
static fromTranslation(t, out = quat2()) {
|
|
5505
5561
|
out[0] = 0;
|
|
5506
5562
|
out[1] = 0;
|
|
5507
5563
|
out[2] = 0;
|
|
@@ -5519,7 +5575,7 @@ class Quat2 extends Float32Array {
|
|
|
5519
5575
|
* @param {Quat2} out the receiving dual quaternion, defaults to quat2()
|
|
5520
5576
|
* @returns {Quat2} out
|
|
5521
5577
|
*/
|
|
5522
|
-
static fromRotation(q, out =
|
|
5578
|
+
static fromRotation(q, out = quat2()) {
|
|
5523
5579
|
out[0] = q[0];
|
|
5524
5580
|
out[1] = q[1];
|
|
5525
5581
|
out[2] = q[2];
|
|
@@ -5537,7 +5593,7 @@ class Quat2 extends Float32Array {
|
|
|
5537
5593
|
* @param {Quat2} out the receiving dual quaternion, defaults to quat2()
|
|
5538
5594
|
* @returns {Quat2} out
|
|
5539
5595
|
*/
|
|
5540
|
-
static fromMat4(m, out =
|
|
5596
|
+
static fromMat4(m, out = quat2()) {
|
|
5541
5597
|
const r = m.getRotation();
|
|
5542
5598
|
const t = m.getTranslation();
|
|
5543
5599
|
return Quat2.fromRotationTranslation(r, t, out);
|
|
@@ -5548,16 +5604,16 @@ class Quat2 extends Float32Array {
|
|
|
5548
5604
|
* @returns {Quat2} a new dual quaternion
|
|
5549
5605
|
*/
|
|
5550
5606
|
clone() {
|
|
5551
|
-
return
|
|
5607
|
+
return quat2(this[0], this[1], this[2], this[3], this[4], this[5], this[6], this[7]);
|
|
5552
5608
|
}
|
|
5553
5609
|
/**
|
|
5554
5610
|
* Translate by a Vec3
|
|
5555
5611
|
*
|
|
5556
5612
|
* @param {Vec3} v the translation vector
|
|
5557
|
-
* @param {Quat2} out the receiving dual quaternion, defaults to
|
|
5613
|
+
* @param {Quat2} out the receiving dual quaternion, defaults to new quat2()
|
|
5558
5614
|
* @returns {Quat2} out
|
|
5559
5615
|
*/
|
|
5560
|
-
translate(v, out = index.ALWAYS_COPY ?
|
|
5616
|
+
translate(v, out = index.ALWAYS_COPY ? quat2() : this) {
|
|
5561
5617
|
const ax1 = this[0], ay1 = this[1], az1 = this[2], aw1 = this[3];
|
|
5562
5618
|
const bx1 = v[0] * 0.5, by1 = v[1] * 0.5, bz1 = v[2] * 0.5;
|
|
5563
5619
|
const ax2 = this[4], ay2 = this[5], az2 = this[6], aw2 = this[7];
|
|
@@ -5574,10 +5630,10 @@ class Quat2 extends Float32Array {
|
|
|
5574
5630
|
/**
|
|
5575
5631
|
* Calculates the conjugate of a dual quaternion
|
|
5576
5632
|
*
|
|
5577
|
-
* @param {Quat2} out the receiving dual quaternion, defaults to
|
|
5633
|
+
* @param {Quat2} out the receiving dual quaternion, defaults to new quat2()
|
|
5578
5634
|
* @returns {Quat2} out
|
|
5579
5635
|
*/
|
|
5580
|
-
conjugate(out = index.ALWAYS_COPY ?
|
|
5636
|
+
conjugate(out = index.ALWAYS_COPY ? quat2() : this) {
|
|
5581
5637
|
out[0] = -this[0];
|
|
5582
5638
|
out[1] = -this[1];
|
|
5583
5639
|
out[2] = -this[2];
|
|
@@ -5591,10 +5647,10 @@ class Quat2 extends Float32Array {
|
|
|
5591
5647
|
/**
|
|
5592
5648
|
* Calculates the inverse of a dual quaternion
|
|
5593
5649
|
*
|
|
5594
|
-
* @param {Quat2} out the receiving dual quaternion, defaults to
|
|
5650
|
+
* @param {Quat2} out the receiving dual quaternion, defaults to new quat2()
|
|
5595
5651
|
* @returns {Quat2} out
|
|
5596
5652
|
*/
|
|
5597
|
-
invert(out = index.ALWAYS_COPY ?
|
|
5653
|
+
invert(out = index.ALWAYS_COPY ? quat2() : this) {
|
|
5598
5654
|
const sqlen = this.squaredLength();
|
|
5599
5655
|
out[0] = -this[0] / sqlen;
|
|
5600
5656
|
out[1] = -this[1] / sqlen;
|
|
@@ -5626,16 +5682,17 @@ class Quat2 extends Float32Array {
|
|
|
5626
5682
|
/**
|
|
5627
5683
|
* Normalize the dual quaternion
|
|
5628
5684
|
*
|
|
5629
|
-
* @param {Quat2}
|
|
5685
|
+
* @param {Quat2} q the quaternion to normalize
|
|
5686
|
+
* @param {Quat2} out the receiving dual quaternion, defaults to new quat2()
|
|
5630
5687
|
* @returns {Quat2} out
|
|
5631
5688
|
*/
|
|
5632
|
-
normalize(out =
|
|
5633
|
-
let magnitude =
|
|
5689
|
+
static normalize(q, out = quat2()) {
|
|
5690
|
+
let magnitude = q.squaredLength();
|
|
5634
5691
|
if (magnitude > 0) {
|
|
5635
5692
|
magnitude = Math.sqrt(magnitude);
|
|
5636
|
-
const a0 =
|
|
5637
|
-
const a2 =
|
|
5638
|
-
const b0 =
|
|
5693
|
+
const a0 = q[0] / magnitude, a1 = q[1] / magnitude;
|
|
5694
|
+
const a2 = q[2] / magnitude, a3 = q[3] / magnitude;
|
|
5695
|
+
const b0 = q[4], b1 = q[5], b2 = q[6], b3 = q[7];
|
|
5639
5696
|
const a_dot_b = a0 * b0 + a1 * b1 + a2 * b2 + a3 * b3;
|
|
5640
5697
|
out[0] = a0;
|
|
5641
5698
|
out[1] = a1;
|
|
@@ -5648,6 +5705,15 @@ class Quat2 extends Float32Array {
|
|
|
5648
5705
|
}
|
|
5649
5706
|
return out;
|
|
5650
5707
|
}
|
|
5708
|
+
/**
|
|
5709
|
+
* Normalize the dual quaternion
|
|
5710
|
+
*
|
|
5711
|
+
* @param {Quat2} out the receiving dual quaternion, defaults to new quat2()
|
|
5712
|
+
* @returns {Quat2} out
|
|
5713
|
+
*/
|
|
5714
|
+
normalize(out = index.ALWAYS_COPY ? quat2() : this) {
|
|
5715
|
+
return Quat2.normalize(this, out);
|
|
5716
|
+
}
|
|
5651
5717
|
/**
|
|
5652
5718
|
* Dot product of the real parts of two dual quaternions
|
|
5653
5719
|
*
|
|
@@ -5667,7 +5733,7 @@ class Quat2 extends Float32Array {
|
|
|
5667
5733
|
* @param {Quat2} out the receiving dual quaternion, defaults to quat2()
|
|
5668
5734
|
* @returns {Quat2} out
|
|
5669
5735
|
*/
|
|
5670
|
-
static lerp(a, b, t, out =
|
|
5736
|
+
static lerp(a, b, t, out = quat2()) {
|
|
5671
5737
|
const mt = 1 - t;
|
|
5672
5738
|
if (Quat2.dot(a, b) < 0)
|
|
5673
5739
|
t = -t;
|
|
@@ -5685,10 +5751,10 @@ class Quat2 extends Float32Array {
|
|
|
5685
5751
|
* Adds two dual quaternions
|
|
5686
5752
|
*
|
|
5687
5753
|
* @param {Quat2} b the second operand
|
|
5688
|
-
* @param {Quat2} out the receiving dual quaternion, defaults to
|
|
5754
|
+
* @param {Quat2} out the receiving dual quaternion, defaults to new quat2()
|
|
5689
5755
|
* @returns {Quat2} out
|
|
5690
5756
|
*/
|
|
5691
|
-
plus(b, out = index.ALWAYS_COPY ?
|
|
5757
|
+
plus(b, out = index.ALWAYS_COPY ? quat2() : this) {
|
|
5692
5758
|
out[0] = this[0] + b[0];
|
|
5693
5759
|
out[1] = this[1] + b[1];
|
|
5694
5760
|
out[2] = this[2] + b[2];
|
|
@@ -5703,10 +5769,10 @@ class Quat2 extends Float32Array {
|
|
|
5703
5769
|
* Scales a dual quaternion by a scalar
|
|
5704
5770
|
*
|
|
5705
5771
|
* @param {Number} s the scalar to scale by
|
|
5706
|
-
* @param {Quat2} out the receiving dual quaternion, defaults to
|
|
5772
|
+
* @param {Quat2} out the receiving dual quaternion, defaults to new quat2()
|
|
5707
5773
|
* @returns {Quat2} out
|
|
5708
5774
|
*/
|
|
5709
|
-
scale(s, out = index.ALWAYS_COPY ?
|
|
5775
|
+
scale(s, out = index.ALWAYS_COPY ? quat2() : this) {
|
|
5710
5776
|
out[0] = this[0] * s;
|
|
5711
5777
|
out[1] = this[1] * s;
|
|
5712
5778
|
out[2] = this[2] * s;
|
|
@@ -5768,17 +5834,20 @@ class Quat2 extends Float32Array {
|
|
|
5768
5834
|
}
|
|
5769
5835
|
// @aliases
|
|
5770
5836
|
Quat2.prototype.sqrLen = Quat2.prototype.squaredLength;
|
|
5837
|
+
Quat2.prototype.normalized = Quat2.prototype.normalize;
|
|
5771
5838
|
Quat2.prototype.str = Quat2.prototype.toString;
|
|
5772
5839
|
Quat2.prototype.add = Quat2.prototype.plus;
|
|
5773
|
-
const
|
|
5840
|
+
const createQuat2 = (x1 = 0, y1 = 0, z1 = 0, w1 = 1, x2 = 0, y2 = 0, z2 = 0, w2 = 0) => new Quat2(x1, y1, z1, w1, x2, y2, z2, w2);
|
|
5841
|
+
Object.setPrototypeOf(createQuat2, Quat2);
|
|
5842
|
+
const quat2 = createQuat2;
|
|
5774
5843
|
|
|
5775
5844
|
/** 2x2 Matrix in column-major order
|
|
5776
5845
|
* @extends Float32Array
|
|
5777
5846
|
*/
|
|
5778
5847
|
class Mat2 extends Float32Array {
|
|
5779
|
-
static get identity() { return
|
|
5780
|
-
static get Identity() { return
|
|
5781
|
-
static get IDENTITY() { return
|
|
5848
|
+
static get identity() { return mat2(1, 0, 0, 1); }
|
|
5849
|
+
static get Identity() { return mat2(1, 0, 0, 1); }
|
|
5850
|
+
static get IDENTITY() { return mat2(1, 0, 0, 1); }
|
|
5782
5851
|
/**
|
|
5783
5852
|
* Creates a new Mat2
|
|
5784
5853
|
*
|
|
@@ -5800,15 +5869,15 @@ class Mat2 extends Float32Array {
|
|
|
5800
5869
|
* @returns {Mat2} a new Mat2
|
|
5801
5870
|
*/
|
|
5802
5871
|
clone() {
|
|
5803
|
-
return
|
|
5872
|
+
return mat2(this[0], this[1], this[2], this[3]);
|
|
5804
5873
|
}
|
|
5805
5874
|
/**
|
|
5806
5875
|
* Transposes a mat2
|
|
5807
5876
|
*
|
|
5808
|
-
* @param {Mat2} out the receiving matrix, defaults to
|
|
5877
|
+
* @param {Mat2} out the receiving matrix, defaults to new mat2()
|
|
5809
5878
|
* @returns {Mat2} out
|
|
5810
5879
|
*/
|
|
5811
|
-
transpose(out = index.ALWAYS_COPY ?
|
|
5880
|
+
transpose(out = index.ALWAYS_COPY ? mat2() : this) {
|
|
5812
5881
|
if (out.exactEquals(this)) {
|
|
5813
5882
|
const tmp = out[1];
|
|
5814
5883
|
out[1] = out[2];
|
|
@@ -5825,10 +5894,10 @@ class Mat2 extends Float32Array {
|
|
|
5825
5894
|
/**
|
|
5826
5895
|
* Inverts a mat2
|
|
5827
5896
|
*
|
|
5828
|
-
* @param {Mat2} out the receiving matrix, defaults to
|
|
5897
|
+
* @param {Mat2} out the receiving matrix, defaults to new mat2()
|
|
5829
5898
|
* @returns {Mat2} out or null if the matrix is not invertible
|
|
5830
5899
|
*/
|
|
5831
|
-
invert(out = index.ALWAYS_COPY ?
|
|
5900
|
+
invert(out = index.ALWAYS_COPY ? mat2() : this) {
|
|
5832
5901
|
const a0 = this[0], a1 = this[1], a2 = this[2], a3 = this[3];
|
|
5833
5902
|
// Calculate the determinant
|
|
5834
5903
|
let det = a0 * a3 - a2 * a1;
|
|
@@ -5844,10 +5913,10 @@ class Mat2 extends Float32Array {
|
|
|
5844
5913
|
/**
|
|
5845
5914
|
* Calculates the adjugate of a mat2
|
|
5846
5915
|
*
|
|
5847
|
-
* @param {Mat2} out the receiving matrix, defaults to
|
|
5916
|
+
* @param {Mat2} out the receiving matrix, defaults to new mat2()
|
|
5848
5917
|
* @returns {Mat2} out
|
|
5849
5918
|
*/
|
|
5850
|
-
adjoint(out = index.ALWAYS_COPY ?
|
|
5919
|
+
adjoint(out = index.ALWAYS_COPY ? mat2() : this) {
|
|
5851
5920
|
let a0 = this[0];
|
|
5852
5921
|
out[0] = this[3];
|
|
5853
5922
|
out[1] = -this[1];
|
|
@@ -5867,10 +5936,10 @@ class Mat2 extends Float32Array {
|
|
|
5867
5936
|
* Rotates a mat2 by the given angle
|
|
5868
5937
|
*
|
|
5869
5938
|
* @param {Number} rad the angle to rotate the matrix by
|
|
5870
|
-
* @param {Mat2} out the receiving matrix, defaults to
|
|
5939
|
+
* @param {Mat2} out the receiving matrix, defaults to new mat2()
|
|
5871
5940
|
* @returns {Mat2} out
|
|
5872
5941
|
*/
|
|
5873
|
-
rotate(rad, out = index.ALWAYS_COPY ?
|
|
5942
|
+
rotate(rad, out = index.ALWAYS_COPY ? mat2() : this) {
|
|
5874
5943
|
const a0 = this[0], a1 = this[1], a2 = this[2], a3 = this[3];
|
|
5875
5944
|
const s = Math.sin(rad), c = Math.cos(rad);
|
|
5876
5945
|
out[0] = a0 * c + a2 * s;
|
|
@@ -5883,10 +5952,10 @@ class Mat2 extends Float32Array {
|
|
|
5883
5952
|
* Scales a mat2 by the dimensions in the given Vec2
|
|
5884
5953
|
*
|
|
5885
5954
|
* @param {Vec2} v the Vec2 to scale the matrix by
|
|
5886
|
-
* @param {Mat2} out the receiving matrix, defaults to
|
|
5955
|
+
* @param {Mat2} out the receiving matrix, defaults to new mat2()
|
|
5887
5956
|
* @returns {Mat2} out
|
|
5888
5957
|
*/
|
|
5889
|
-
scale(v, out = index.ALWAYS_COPY ?
|
|
5958
|
+
scale(v, out = index.ALWAYS_COPY ? mat2() : this) {
|
|
5890
5959
|
const v0 = v[0], v1 = v[1];
|
|
5891
5960
|
out[0] = this[0] * v0;
|
|
5892
5961
|
out[1] = this[1] * v0;
|
|
@@ -5898,10 +5967,10 @@ class Mat2 extends Float32Array {
|
|
|
5898
5967
|
* Creates a Mat2 from a given angle
|
|
5899
5968
|
*
|
|
5900
5969
|
* @param {Number} rad the angle to rotate the matrix by
|
|
5901
|
-
* @param {Mat2} out the receiving matrix, defaults to
|
|
5970
|
+
* @param {Mat2} out the receiving matrix, defaults to mat2()
|
|
5902
5971
|
* @returns {Mat2} out
|
|
5903
5972
|
*/
|
|
5904
|
-
static fromRotation(rad, out =
|
|
5973
|
+
static fromRotation(rad, out = mat2()) {
|
|
5905
5974
|
const s = Math.sin(rad), c = Math.cos(rad);
|
|
5906
5975
|
out[0] = c;
|
|
5907
5976
|
out[1] = s;
|
|
@@ -5913,10 +5982,10 @@ class Mat2 extends Float32Array {
|
|
|
5913
5982
|
* Creates a Mat2 from a scaling vector
|
|
5914
5983
|
*
|
|
5915
5984
|
* @param {Vec2} v scaling vector
|
|
5916
|
-
* @param {Mat2} out the receiving matrix, defaults to
|
|
5985
|
+
* @param {Mat2} out the receiving matrix, defaults to mat2()
|
|
5917
5986
|
* @returns {Mat2} out
|
|
5918
5987
|
*/
|
|
5919
|
-
static fromScaling(v, out =
|
|
5988
|
+
static fromScaling(v, out = mat2()) {
|
|
5920
5989
|
out[0] = v[0];
|
|
5921
5990
|
out[1] = out[2] = 0;
|
|
5922
5991
|
out[3] = v[1];
|
|
@@ -5944,7 +6013,7 @@ class Mat2 extends Float32Array {
|
|
|
5944
6013
|
* @param {Mat2} D the diagonal matrix
|
|
5945
6014
|
* @param {Mat2} U the upper triangular matrix
|
|
5946
6015
|
*/
|
|
5947
|
-
LDU(L =
|
|
6016
|
+
LDU(L = mat2(), D = mat2(), U = mat2()) {
|
|
5948
6017
|
L[2] = this[2] / this[0];
|
|
5949
6018
|
U[0] = this[0];
|
|
5950
6019
|
U[1] = this[1];
|
|
@@ -5955,10 +6024,10 @@ class Mat2 extends Float32Array {
|
|
|
5955
6024
|
* Adds two Mat2's
|
|
5956
6025
|
*
|
|
5957
6026
|
* @param {Mat2} b the second operand
|
|
5958
|
-
* @param {Mat2} out the receiving matrix, defaults to
|
|
6027
|
+
* @param {Mat2} out the receiving matrix, defaults to new mat2()
|
|
5959
6028
|
* @returns {Mat2} out
|
|
5960
6029
|
*/
|
|
5961
|
-
plus(b, out = index.ALWAYS_COPY ?
|
|
6030
|
+
plus(b, out = index.ALWAYS_COPY ? mat2() : this) {
|
|
5962
6031
|
out[0] = this[0] + b[0];
|
|
5963
6032
|
out[1] = this[1] + b[1];
|
|
5964
6033
|
out[2] = this[2] + b[2];
|
|
@@ -5969,17 +6038,17 @@ class Mat2 extends Float32Array {
|
|
|
5969
6038
|
* Subtracts matrix b from a mat2
|
|
5970
6039
|
*
|
|
5971
6040
|
* @param {Mat2} b the second operand
|
|
5972
|
-
* @param {Mat2} out the receiving matrix, defaults to
|
|
6041
|
+
* @param {Mat2} out the receiving matrix, defaults to new mat2()
|
|
5973
6042
|
* @returns {Mat2} out
|
|
5974
6043
|
*/
|
|
5975
|
-
minus(b, out = index.ALWAYS_COPY ?
|
|
6044
|
+
minus(b, out = index.ALWAYS_COPY ? mat2() : this) {
|
|
5976
6045
|
out[0] = this[0] - b[0];
|
|
5977
6046
|
out[1] = this[1] - b[1];
|
|
5978
6047
|
out[2] = this[2] - b[2];
|
|
5979
6048
|
out[3] = this[3] - b[3];
|
|
5980
6049
|
return out;
|
|
5981
6050
|
}
|
|
5982
|
-
multiply(b, out = index.ALWAYS_COPY ?
|
|
6051
|
+
multiply(b, out = index.ALWAYS_COPY ? mat2() : this) {
|
|
5983
6052
|
if (b instanceof Vec2)
|
|
5984
6053
|
return b.transformMat2(this);
|
|
5985
6054
|
const a0 = this[0], a1 = this[1], a2 = this[2], a3 = this[3];
|
|
@@ -6013,10 +6082,10 @@ class Mat2 extends Float32Array {
|
|
|
6013
6082
|
* Multiplies each element of a mat2 by a scalar value
|
|
6014
6083
|
*
|
|
6015
6084
|
* @param {Number} b amount to scale the matrix's elements by
|
|
6016
|
-
* @param {Mat2} out the receiving matrix, defaults to
|
|
6085
|
+
* @param {Mat2} out the receiving matrix, defaults to new mat2()
|
|
6017
6086
|
* @returns {Mat2} out
|
|
6018
6087
|
*/
|
|
6019
|
-
scaleScalar(b, out = index.ALWAYS_COPY ?
|
|
6088
|
+
scaleScalar(b, out = index.ALWAYS_COPY ? mat2() : this) {
|
|
6020
6089
|
out[0] = this[0] * b;
|
|
6021
6090
|
out[1] = this[1] * b;
|
|
6022
6091
|
out[2] = this[2] * b;
|
|
@@ -6053,9 +6122,9 @@ const mat2x2 = mat2;
|
|
|
6053
6122
|
* @extends Float32Array
|
|
6054
6123
|
*/
|
|
6055
6124
|
class Mat2x3 extends Float32Array {
|
|
6056
|
-
static get identity() { return
|
|
6057
|
-
static get Identity() { return
|
|
6058
|
-
static get IDENTITY() { return
|
|
6125
|
+
static get identity() { return mat2x3(1, 0, 0, 1, 0, 0); }
|
|
6126
|
+
static get Identity() { return mat2x3(1, 0, 0, 1, 0, 0); }
|
|
6127
|
+
static get IDENTITY() { return mat2x3(1, 0, 0, 1, 0, 0); }
|
|
6059
6128
|
/**
|
|
6060
6129
|
* Creates a new Mat2x3
|
|
6061
6130
|
*
|
|
@@ -6078,10 +6147,10 @@ class Mat2x3 extends Float32Array {
|
|
|
6078
6147
|
/**
|
|
6079
6148
|
* Inverts a mat2x3
|
|
6080
6149
|
*
|
|
6081
|
-
* @param {Mat2x3} out the receiving matrix, defaults to
|
|
6150
|
+
* @param {Mat2x3} out the receiving matrix, defaults to new mat2x3()
|
|
6082
6151
|
* @returns {Mat2x3} out or null if the matrix is not invertible
|
|
6083
6152
|
*/
|
|
6084
|
-
invert(out = index.ALWAYS_COPY ?
|
|
6153
|
+
invert(out = index.ALWAYS_COPY ? mat2x3() : this) {
|
|
6085
6154
|
const aa = this[0], ab = this[1], ac = this[2], ad = this[3];
|
|
6086
6155
|
const atx = this[4], aty = this[5];
|
|
6087
6156
|
let det = aa * ad - ab * ac;
|
|
@@ -6108,10 +6177,10 @@ class Mat2x3 extends Float32Array {
|
|
|
6108
6177
|
* Rotates a mat2x3 by the given angle
|
|
6109
6178
|
*
|
|
6110
6179
|
* @param {Number} rad the angle to rotate the matrix by
|
|
6111
|
-
* @param {Mat2x3} out the receiving matrix, defaults to
|
|
6180
|
+
* @param {Mat2x3} out the receiving matrix, defaults to new mat2x3()
|
|
6112
6181
|
* @returns {Mat2x3} out
|
|
6113
6182
|
*/
|
|
6114
|
-
rotate(rad, out = index.ALWAYS_COPY ?
|
|
6183
|
+
rotate(rad, out = index.ALWAYS_COPY ? mat2x3() : this) {
|
|
6115
6184
|
const a0 = this[0], a1 = this[1], a2 = this[2], a3 = this[3], a4 = this[4], a5 = this[5];
|
|
6116
6185
|
const s = Math.sin(rad);
|
|
6117
6186
|
const c = Math.cos(rad);
|
|
@@ -6127,10 +6196,10 @@ class Mat2x3 extends Float32Array {
|
|
|
6127
6196
|
* Scales a mat2x3 by the dimensions in the given Vec2
|
|
6128
6197
|
*
|
|
6129
6198
|
* @param {Vec2} v the Vec2 to scale the matrix by
|
|
6130
|
-
* @param {Mat2x3} out the receiving matrix, defaults to
|
|
6199
|
+
* @param {Mat2x3} out the receiving matrix, defaults to new mat2x3()
|
|
6131
6200
|
* @returns {Mat2x3} out
|
|
6132
6201
|
*/
|
|
6133
|
-
scale(v, out = index.ALWAYS_COPY ?
|
|
6202
|
+
scale(v, out = index.ALWAYS_COPY ? mat2x3() : this) {
|
|
6134
6203
|
const a0 = this[0], a1 = this[1], a2 = this[2], a3 = this[3], a4 = this[4], a5 = this[5];
|
|
6135
6204
|
const v0 = v[0], v1 = v[1];
|
|
6136
6205
|
out[0] = a0 * v0;
|
|
@@ -6145,10 +6214,10 @@ class Mat2x3 extends Float32Array {
|
|
|
6145
6214
|
* Translates a mat2x3 by the dimensions in the given Vec2
|
|
6146
6215
|
*
|
|
6147
6216
|
* @param {Vec2} v the Vec2 to translate the matrix by
|
|
6148
|
-
* @param {Mat2x3} out the receiving matrix, defaults to
|
|
6217
|
+
* @param {Mat2x3} out the receiving matrix, defaults to new mat2x3()
|
|
6149
6218
|
* @returns {Mat2x3} out
|
|
6150
6219
|
*/
|
|
6151
|
-
translate(v, out = index.ALWAYS_COPY ?
|
|
6220
|
+
translate(v, out = index.ALWAYS_COPY ? mat2x3() : this) {
|
|
6152
6221
|
const a0 = this[0], a1 = this[1], a2 = this[2], a3 = this[3], a4 = this[4], a5 = this[5];
|
|
6153
6222
|
const v0 = v[0], v1 = v[1];
|
|
6154
6223
|
out[0] = a0;
|
|
@@ -6163,10 +6232,10 @@ class Mat2x3 extends Float32Array {
|
|
|
6163
6232
|
* Creates a Mat2x3 from a given angle
|
|
6164
6233
|
*
|
|
6165
6234
|
* @param {Number} rad the angle to rotate the matrix by
|
|
6166
|
-
* @param {Mat2x3} out the receiving matrix, defaults to
|
|
6235
|
+
* @param {Mat2x3} out the receiving matrix, defaults to mat2x3()
|
|
6167
6236
|
* @returns {Mat2x3} out
|
|
6168
6237
|
*/
|
|
6169
|
-
static fromRotation(rad, out =
|
|
6238
|
+
static fromRotation(rad, out = mat2x3()) {
|
|
6170
6239
|
const s = Math.sin(rad), c = Math.cos(rad);
|
|
6171
6240
|
out[0] = c;
|
|
6172
6241
|
out[1] = s;
|
|
@@ -6179,10 +6248,10 @@ class Mat2x3 extends Float32Array {
|
|
|
6179
6248
|
* Creates a Mat2x3 from a scaling vector
|
|
6180
6249
|
*
|
|
6181
6250
|
* @param {Vec2} v scaling vector
|
|
6182
|
-
* @param {Mat2x3} out the receiving matrix, defaults to
|
|
6251
|
+
* @param {Mat2x3} out the receiving matrix, defaults to mat2x3()
|
|
6183
6252
|
* @returns {Mat2x3} out
|
|
6184
6253
|
*/
|
|
6185
|
-
static fromScaling(v, out =
|
|
6254
|
+
static fromScaling(v, out = mat2x3()) {
|
|
6186
6255
|
out[0] = v[0];
|
|
6187
6256
|
out[1] = out[2] = 0;
|
|
6188
6257
|
out[3] = v[1];
|
|
@@ -6193,10 +6262,10 @@ class Mat2x3 extends Float32Array {
|
|
|
6193
6262
|
* Creates a Mat2x3 from a translation vector
|
|
6194
6263
|
*
|
|
6195
6264
|
* @param {Vec2} v translation vector
|
|
6196
|
-
* @param {Mat2x3} out the receiving matrix, defaults to
|
|
6265
|
+
* @param {Mat2x3} out the receiving matrix, defaults to mat2x3()
|
|
6197
6266
|
* @returns {Mat2x3} out
|
|
6198
6267
|
*/
|
|
6199
|
-
static fromTranslation(v, out =
|
|
6268
|
+
static fromTranslation(v, out = mat2x3()) {
|
|
6200
6269
|
out[0] = out[3] = 1;
|
|
6201
6270
|
out[1] = out[2] = 0;
|
|
6202
6271
|
out[4] = v[0];
|
|
@@ -6223,10 +6292,10 @@ class Mat2x3 extends Float32Array {
|
|
|
6223
6292
|
* Adds two Mat2x3's
|
|
6224
6293
|
*
|
|
6225
6294
|
* @param {Mat2x3} b the second operand
|
|
6226
|
-
* @param {Mat2x3} out the receiving matrix, defaults to
|
|
6295
|
+
* @param {Mat2x3} out the receiving matrix, defaults to new mat2x3()
|
|
6227
6296
|
* @returns {Mat2x3} out
|
|
6228
6297
|
*/
|
|
6229
|
-
plus(b, out = index.ALWAYS_COPY ?
|
|
6298
|
+
plus(b, out = index.ALWAYS_COPY ? mat2x3() : this) {
|
|
6230
6299
|
out[0] = this[0] + b[0];
|
|
6231
6300
|
out[1] = this[1] + b[1];
|
|
6232
6301
|
out[2] = this[2] + b[2];
|
|
@@ -6239,10 +6308,10 @@ class Mat2x3 extends Float32Array {
|
|
|
6239
6308
|
* Subtracts matrix b from a mat2x3
|
|
6240
6309
|
*
|
|
6241
6310
|
* @param {Mat2x3} b the second operand
|
|
6242
|
-
* @param {Mat2x3} out the receiving matrix, defaults to
|
|
6311
|
+
* @param {Mat2x3} out the receiving matrix, defaults to new mat2x3()
|
|
6243
6312
|
* @returns {Mat2x3} out
|
|
6244
6313
|
*/
|
|
6245
|
-
minus(b, out = index.ALWAYS_COPY ?
|
|
6314
|
+
minus(b, out = index.ALWAYS_COPY ? mat2x3() : this) {
|
|
6246
6315
|
out[0] = this[0] - b[0];
|
|
6247
6316
|
out[1] = this[1] - b[1];
|
|
6248
6317
|
out[2] = this[2] - b[2];
|
|
@@ -6251,7 +6320,7 @@ class Mat2x3 extends Float32Array {
|
|
|
6251
6320
|
out[5] = this[5] - b[5];
|
|
6252
6321
|
return out;
|
|
6253
6322
|
}
|
|
6254
|
-
multiply(b, out = index.ALWAYS_COPY ?
|
|
6323
|
+
multiply(b, out = index.ALWAYS_COPY ? mat2x3() : this) {
|
|
6255
6324
|
if (b instanceof Vec2)
|
|
6256
6325
|
return b.transformMat2x3(this);
|
|
6257
6326
|
const a0 = this[0], a1 = this[1], a2 = this[2], a3 = this[3], a4 = this[4], a5 = this[5];
|
|
@@ -6288,10 +6357,10 @@ class Mat2x3 extends Float32Array {
|
|
|
6288
6357
|
* Multiplies each element of a mat2x3 by a scalar value
|
|
6289
6358
|
*
|
|
6290
6359
|
* @param {Number} b amount to scale the matrix's elements by
|
|
6291
|
-
* @param {Mat2x3} out the receiving matrix, defaults to
|
|
6360
|
+
* @param {Mat2x3} out the receiving matrix, defaults to new mat2x3()
|
|
6292
6361
|
* @returns {Mat2x3} out
|
|
6293
6362
|
*/
|
|
6294
|
-
scaleScalar(b, out = index.ALWAYS_COPY ?
|
|
6363
|
+
scaleScalar(b, out = index.ALWAYS_COPY ? mat2x3() : this) {
|
|
6295
6364
|
out[0] = this[0] * b;
|
|
6296
6365
|
out[1] = this[1] * b;
|
|
6297
6366
|
out[2] = this[2] * b;
|
|
@@ -6306,7 +6375,7 @@ class Mat2x3 extends Float32Array {
|
|
|
6306
6375
|
* @returns {Mat2x3} a new Mat2x3
|
|
6307
6376
|
*/
|
|
6308
6377
|
clone() {
|
|
6309
|
-
return
|
|
6378
|
+
return mat2x3(this[0], this[1], this[2], this[3], this[4], this[5]);
|
|
6310
6379
|
}
|
|
6311
6380
|
}
|
|
6312
6381
|
// @aliases
|
|
@@ -6318,7 +6387,20 @@ Mat2x3.prototype.mult = Mat2x3.prototype.multiply;
|
|
|
6318
6387
|
Mat2x3.prototype.times = Mat2x3.prototype.multiply;
|
|
6319
6388
|
Mat2x3.prototype.str = Mat2x3.prototype.toString;
|
|
6320
6389
|
Mat2x3.prototype.multiplyScalar = Mat2x3.prototype.scaleScalar;
|
|
6321
|
-
const
|
|
6390
|
+
const createMat2x3 = (...args) => {
|
|
6391
|
+
const out = new Mat2x3();
|
|
6392
|
+
let i = 0;
|
|
6393
|
+
for (const a of args) {
|
|
6394
|
+
if (typeof a === 'number')
|
|
6395
|
+
out[i++] = a;
|
|
6396
|
+
else
|
|
6397
|
+
for (const v of a)
|
|
6398
|
+
out[i++] = v;
|
|
6399
|
+
}
|
|
6400
|
+
return out;
|
|
6401
|
+
};
|
|
6402
|
+
Object.setPrototypeOf(createMat2x3, Mat2x3);
|
|
6403
|
+
const mat2x3 = createMat2x3;
|
|
6322
6404
|
const mat2d = mat2x3;
|
|
6323
6405
|
|
|
6324
6406
|
function makeArr(a) {
|