@lakuna/umath 1.3.5 → 1.3.6
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/LICENSE +1 -1
- package/dist/algorithms/combinations.d.ts +7 -0
- package/dist/algorithms/combinations.d.ts.map +1 -1
- package/dist/algorithms/combinations.js +7 -0
- package/dist/algorithms/combinations.js.map +1 -1
- package/dist/algorithms/degreesToRadians.d.ts +7 -0
- package/dist/algorithms/degreesToRadians.d.ts.map +1 -1
- package/dist/algorithms/degreesToRadians.js +7 -0
- package/dist/algorithms/degreesToRadians.js.map +1 -1
- package/dist/algorithms/factorial.d.ts +6 -0
- package/dist/algorithms/factorial.d.ts.map +1 -1
- package/dist/algorithms/factorial.js +8 -1
- package/dist/algorithms/factorial.js.map +1 -1
- package/dist/algorithms/fibonacci.d.ts +6 -1
- package/dist/algorithms/fibonacci.d.ts.map +1 -1
- package/dist/algorithms/fibonacci.js +5 -0
- package/dist/algorithms/fibonacci.js.map +1 -1
- package/dist/algorithms/greatestCommonDivisor.d.ts +14 -0
- package/dist/algorithms/greatestCommonDivisor.d.ts.map +1 -1
- package/dist/algorithms/greatestCommonDivisor.js +2 -0
- package/dist/algorithms/greatestCommonDivisor.js.map +1 -1
- package/dist/algorithms/hypergeometricPmf.d.ts +9 -0
- package/dist/algorithms/hypergeometricPmf.d.ts.map +1 -1
- package/dist/algorithms/hypergeometricPmf.js +9 -0
- package/dist/algorithms/hypergeometricPmf.js.map +1 -1
- package/dist/algorithms/isPrime.d.ts +6 -0
- package/dist/algorithms/isPrime.d.ts.map +1 -1
- package/dist/algorithms/isPrime.js +7 -0
- package/dist/algorithms/isPrime.js.map +1 -1
- package/dist/algorithms/permutations.d.ts +7 -0
- package/dist/algorithms/permutations.d.ts.map +1 -1
- package/dist/algorithms/permutations.js +7 -0
- package/dist/algorithms/permutations.js.map +1 -1
- package/dist/algorithms/primeFactorization.d.ts +6 -0
- package/dist/algorithms/primeFactorization.d.ts.map +1 -1
- package/dist/algorithms/primeFactorization.js +6 -0
- package/dist/algorithms/primeFactorization.js.map +1 -1
- package/dist/algorithms/radiansToDegrees.d.ts +7 -0
- package/dist/algorithms/radiansToDegrees.d.ts.map +1 -1
- package/dist/algorithms/radiansToDegrees.js +7 -0
- package/dist/algorithms/radiansToDegrees.js.map +1 -1
- package/dist/algorithms/summation.d.ts +8 -0
- package/dist/algorithms/summation.d.ts.map +1 -1
- package/dist/algorithms/summation.js +9 -0
- package/dist/algorithms/summation.js.map +1 -1
- package/dist/linalg/DualQuaternion.d.ts +410 -27
- package/dist/linalg/DualQuaternion.d.ts.map +1 -1
- package/dist/linalg/DualQuaternion.js +429 -54
- package/dist/linalg/DualQuaternion.js.map +1 -1
- package/dist/linalg/Matrix.d.ts +67 -0
- package/dist/linalg/Matrix.d.ts.map +1 -1
- package/dist/linalg/Matrix2.d.ts +309 -20
- package/dist/linalg/Matrix2.d.ts.map +1 -1
- package/dist/linalg/Matrix2.js +321 -40
- package/dist/linalg/Matrix2.js.map +1 -1
- package/dist/linalg/Matrix3.d.ts +424 -26
- package/dist/linalg/Matrix3.d.ts.map +1 -1
- package/dist/linalg/Matrix3.js +437 -52
- package/dist/linalg/Matrix3.js.map +1 -1
- package/dist/linalg/Matrix4.d.ts +766 -42
- package/dist/linalg/Matrix4.d.ts.map +1 -1
- package/dist/linalg/Matrix4.js +789 -84
- package/dist/linalg/Matrix4.js.map +1 -1
- package/dist/linalg/Quaternion.d.ts +359 -21
- package/dist/linalg/Quaternion.d.ts.map +1 -1
- package/dist/linalg/Quaternion.js +380 -42
- package/dist/linalg/Quaternion.js.map +1 -1
- package/dist/linalg/SlowMatrix.d.ts +70 -0
- package/dist/linalg/SlowMatrix.d.ts.map +1 -1
- package/dist/linalg/SlowMatrix.js +71 -0
- package/dist/linalg/SlowMatrix.js.map +1 -1
- package/dist/linalg/SlowSquareMatrix.d.ts +55 -0
- package/dist/linalg/SlowSquareMatrix.d.ts.map +1 -1
- package/dist/linalg/SlowSquareMatrix.js +58 -0
- package/dist/linalg/SlowSquareMatrix.js.map +1 -1
- package/dist/linalg/SquareMatrix.d.ts +23 -0
- package/dist/linalg/SquareMatrix.d.ts.map +1 -1
- package/dist/linalg/Vector.d.ts +123 -0
- package/dist/linalg/Vector.d.ts.map +1 -1
- package/dist/linalg/Vector2.d.ts +450 -33
- package/dist/linalg/Vector2.d.ts.map +1 -1
- package/dist/linalg/Vector2.js +480 -66
- package/dist/linalg/Vector2.js.map +1 -1
- package/dist/linalg/Vector3.d.ts +542 -38
- package/dist/linalg/Vector3.d.ts.map +1 -1
- package/dist/linalg/Vector3.js +579 -76
- package/dist/linalg/Vector3.js.map +1 -1
- package/dist/linalg/Vector4.d.ts +416 -30
- package/dist/linalg/Vector4.d.ts.map +1 -1
- package/dist/linalg/Vector4.js +441 -60
- package/dist/linalg/Vector4.js.map +1 -1
- package/dist/types/AxisAngle.d.ts +3 -0
- package/dist/types/AxisAngle.d.ts.map +1 -1
- package/dist/types/FieldOfView.d.ts +5 -0
- package/dist/types/FieldOfView.d.ts.map +1 -1
- package/dist/utility/BigNumber.d.ts +36 -0
- package/dist/utility/BigNumber.d.ts.map +1 -1
- package/dist/utility/BigNumber.js +42 -0
- package/dist/utility/BigNumber.js.map +1 -1
- package/dist/utility/MagnitudeError.d.ts +5 -0
- package/dist/utility/MagnitudeError.d.ts.map +1 -1
- package/dist/utility/MagnitudeError.js +5 -0
- package/dist/utility/MagnitudeError.js.map +1 -1
- package/dist/utility/MatrixSizeError.d.ts +5 -0
- package/dist/utility/MatrixSizeError.d.ts.map +1 -1
- package/dist/utility/MatrixSizeError.js +5 -0
- package/dist/utility/MatrixSizeError.js.map +1 -1
- package/dist/utility/PartialMatrixError.d.ts +5 -0
- package/dist/utility/PartialMatrixError.d.ts.map +1 -1
- package/dist/utility/PartialMatrixError.js +5 -0
- package/dist/utility/PartialMatrixError.js.map +1 -1
- package/dist/utility/SingularMatrixError.d.ts +8 -0
- package/dist/utility/SingularMatrixError.d.ts.map +1 -1
- package/dist/utility/SingularMatrixError.js +8 -0
- package/dist/utility/SingularMatrixError.js.map +1 -1
- package/dist/utility/epsilon.d.ts +1 -0
- package/dist/utility/epsilon.d.ts.map +1 -1
- package/dist/utility/epsilon.js +1 -0
- package/dist/utility/epsilon.js.map +1 -1
- package/package.json +1 -1
- package/src/algorithms/combinations.ts +1 -1
- package/src/algorithms/degreesToRadians.ts +1 -1
- package/src/algorithms/factorial.ts +1 -1
- package/src/algorithms/fibonacci.ts +1 -1
- package/src/algorithms/hypergeometricPmf.ts +1 -1
- package/src/algorithms/isPrime.ts +1 -1
- package/src/algorithms/permutations.ts +1 -1
- package/src/algorithms/primeFactorization.ts +1 -1
- package/src/algorithms/radiansToDegrees.ts +1 -1
- package/src/algorithms/summation.ts +1 -1
- package/src/linalg/DualQuaternion.ts +114 -108
- package/src/linalg/Matrix2.ts +82 -69
- package/src/linalg/Matrix3.ts +106 -93
- package/src/linalg/Matrix4.ts +170 -154
- package/src/linalg/Quaternion.ts +95 -91
- package/src/linalg/SlowMatrix.ts +13 -13
- package/src/linalg/SlowSquareMatrix.ts +11 -11
- package/src/linalg/Vector2.ts +129 -115
- package/src/linalg/Vector3.ts +151 -134
- package/src/linalg/Vector4.ts +120 -103
- package/src/utility/BigNumber.ts +7 -7
package/src/linalg/Matrix4.ts
CHANGED
|
@@ -66,9 +66,9 @@ export interface Matrix4Like extends MatrixLike {
|
|
|
66
66
|
* Create a 4x4 matrix-like object.
|
|
67
67
|
* @returns A 4x4 matrix-like object.
|
|
68
68
|
*/
|
|
69
|
-
export
|
|
69
|
+
export const createMatrix4Like = () => {
|
|
70
70
|
return new Float32Array(16) as unknown as Matrix4Like;
|
|
71
|
-
}
|
|
71
|
+
};
|
|
72
72
|
|
|
73
73
|
/**
|
|
74
74
|
* Create a transformation matrix that represents a translation by the given vector.
|
|
@@ -77,10 +77,10 @@ export function createMatrix4Like() {
|
|
|
77
77
|
* @returns The transformation matrix.
|
|
78
78
|
* @see [Transformation matrix](https://en.wikipedia.org/wiki/Transformation_matrix)
|
|
79
79
|
*/
|
|
80
|
-
export
|
|
80
|
+
export const fromTranslation = <T extends Matrix4Like>(
|
|
81
81
|
vector: Vector3Like,
|
|
82
82
|
out: T
|
|
83
|
-
) {
|
|
83
|
+
): T => {
|
|
84
84
|
out[0] = 1;
|
|
85
85
|
out[1] = 0;
|
|
86
86
|
out[2] = 0;
|
|
@@ -98,7 +98,7 @@ export function fromTranslation<T extends Matrix4Like>(
|
|
|
98
98
|
out[14] = vector[2];
|
|
99
99
|
out[15] = 1;
|
|
100
100
|
return out;
|
|
101
|
-
}
|
|
101
|
+
};
|
|
102
102
|
|
|
103
103
|
/**
|
|
104
104
|
* Create a transformation matrix that represents a scaling by the given vector.
|
|
@@ -107,10 +107,10 @@ export function fromTranslation<T extends Matrix4Like>(
|
|
|
107
107
|
* @returns The transformation matrix.
|
|
108
108
|
* @see [Transformation matrix](https://en.wikipedia.org/wiki/Transformation_matrix)
|
|
109
109
|
*/
|
|
110
|
-
export
|
|
110
|
+
export const fromScaling = <T extends Matrix4Like>(
|
|
111
111
|
vector: Vector3Like,
|
|
112
112
|
out: T
|
|
113
|
-
) {
|
|
113
|
+
): T => {
|
|
114
114
|
out[0] = vector[0];
|
|
115
115
|
out[1] = 0;
|
|
116
116
|
out[2] = 0;
|
|
@@ -128,7 +128,7 @@ export function fromScaling<T extends Matrix4Like>(
|
|
|
128
128
|
out[14] = 0;
|
|
129
129
|
out[15] = 1;
|
|
130
130
|
return out;
|
|
131
|
-
}
|
|
131
|
+
};
|
|
132
132
|
|
|
133
133
|
/**
|
|
134
134
|
* Reset a matrix to identity.
|
|
@@ -136,7 +136,7 @@ export function fromScaling<T extends Matrix4Like>(
|
|
|
136
136
|
* @returns The matrix.
|
|
137
137
|
* @see [Identity matrix](https://en.wikipedia.org/wiki/Identity_matrix)
|
|
138
138
|
*/
|
|
139
|
-
export
|
|
139
|
+
export const identity = <T extends Matrix4Like>(out: T): T => {
|
|
140
140
|
out[0] = 1;
|
|
141
141
|
out[1] = 0;
|
|
142
142
|
out[2] = 0;
|
|
@@ -154,7 +154,7 @@ export function identity<T extends Matrix4Like>(out: T) {
|
|
|
154
154
|
out[14] = 0;
|
|
155
155
|
out[15] = 1;
|
|
156
156
|
return out;
|
|
157
|
-
}
|
|
157
|
+
};
|
|
158
158
|
|
|
159
159
|
/**
|
|
160
160
|
* Create a transformation matrix that represents a rotation by the given angle around the Z-axis.
|
|
@@ -164,11 +164,11 @@ export function identity<T extends Matrix4Like>(out: T) {
|
|
|
164
164
|
* @returns The transformation matrix.
|
|
165
165
|
* @see [Rotation matrix](https://en.wikipedia.org/wiki/Rotation_matrix)
|
|
166
166
|
*/
|
|
167
|
-
export
|
|
167
|
+
export const fromRotation = <T extends Matrix4Like>(
|
|
168
168
|
r: number,
|
|
169
169
|
axis: Vector3Like,
|
|
170
170
|
out: T
|
|
171
|
-
) {
|
|
171
|
+
): T => {
|
|
172
172
|
let x = axis[0];
|
|
173
173
|
let y = axis[1];
|
|
174
174
|
let z = axis[2];
|
|
@@ -204,7 +204,7 @@ export function fromRotation<T extends Matrix4Like>(
|
|
|
204
204
|
out[14] = 0;
|
|
205
205
|
out[15] = 1;
|
|
206
206
|
return out;
|
|
207
|
-
}
|
|
207
|
+
};
|
|
208
208
|
|
|
209
209
|
/**
|
|
210
210
|
* Create a transformation matrix that represents a rotation by the given angle around the X-axis.
|
|
@@ -213,7 +213,7 @@ export function fromRotation<T extends Matrix4Like>(
|
|
|
213
213
|
* @returns The transformation matrix.
|
|
214
214
|
* @see [Rotation matrix](https://en.wikipedia.org/wiki/Rotation_matrix)
|
|
215
215
|
*/
|
|
216
|
-
export
|
|
216
|
+
export const fromXRotation = <T extends Matrix4Like>(r: number, out: T): T => {
|
|
217
217
|
const s = Math.sin(r);
|
|
218
218
|
const c = Math.cos(r);
|
|
219
219
|
|
|
@@ -234,7 +234,7 @@ export function fromXRotation<T extends Matrix4Like>(r: number, out: T) {
|
|
|
234
234
|
out[14] = 0;
|
|
235
235
|
out[15] = 1;
|
|
236
236
|
return out;
|
|
237
|
-
}
|
|
237
|
+
};
|
|
238
238
|
|
|
239
239
|
/**
|
|
240
240
|
* Create a transformation matrix that represents a rotation by the given angle around the Y-axis.
|
|
@@ -243,7 +243,7 @@ export function fromXRotation<T extends Matrix4Like>(r: number, out: T) {
|
|
|
243
243
|
* @returns The transformation matrix.
|
|
244
244
|
* @see [Rotation matrix](https://en.wikipedia.org/wiki/Rotation_matrix)
|
|
245
245
|
*/
|
|
246
|
-
export
|
|
246
|
+
export const fromYRotation = <T extends Matrix4Like>(r: number, out: T): T => {
|
|
247
247
|
const s = Math.sin(r);
|
|
248
248
|
const c = Math.cos(r);
|
|
249
249
|
|
|
@@ -264,7 +264,7 @@ export function fromYRotation<T extends Matrix4Like>(r: number, out: T) {
|
|
|
264
264
|
out[14] = 0;
|
|
265
265
|
out[15] = 1;
|
|
266
266
|
return out;
|
|
267
|
-
}
|
|
267
|
+
};
|
|
268
268
|
|
|
269
269
|
/**
|
|
270
270
|
* Create a transformation matrix that represents a rotation by the given angle around the Z-axis.
|
|
@@ -273,7 +273,7 @@ export function fromYRotation<T extends Matrix4Like>(r: number, out: T) {
|
|
|
273
273
|
* @returns The transformation matrix.
|
|
274
274
|
* @see [Rotation matrix](https://en.wikipedia.org/wiki/Rotation_matrix)
|
|
275
275
|
*/
|
|
276
|
-
export
|
|
276
|
+
export const fromZRotation = <T extends Matrix4Like>(r: number, out: T): T => {
|
|
277
277
|
const s = Math.sin(r);
|
|
278
278
|
const c = Math.cos(r);
|
|
279
279
|
|
|
@@ -294,7 +294,7 @@ export function fromZRotation<T extends Matrix4Like>(r: number, out: T) {
|
|
|
294
294
|
out[14] = 0;
|
|
295
295
|
out[15] = 1;
|
|
296
296
|
return out;
|
|
297
|
-
}
|
|
297
|
+
};
|
|
298
298
|
|
|
299
299
|
/**
|
|
300
300
|
* Create a transformation matrix from the given rotation and translation.
|
|
@@ -306,11 +306,11 @@ export function fromZRotation<T extends Matrix4Like>(r: number, out: T) {
|
|
|
306
306
|
* @see [Rotation matrix](https://en.wikipedia.org/wiki/Rotation_matrix)
|
|
307
307
|
* @see [Transformation matrix](https://en.wikipedia.org/wiki/Transformation_matrix)
|
|
308
308
|
*/
|
|
309
|
-
export
|
|
309
|
+
export const fromRotationTranslation = <T extends Matrix4Like>(
|
|
310
310
|
rotation: QuaternionLike,
|
|
311
311
|
translation: Vector3Like,
|
|
312
312
|
out: T
|
|
313
|
-
) {
|
|
313
|
+
): T => {
|
|
314
314
|
const x = rotation[0];
|
|
315
315
|
const y = rotation[1];
|
|
316
316
|
const z = rotation[2];
|
|
@@ -346,7 +346,7 @@ export function fromRotationTranslation<T extends Matrix4Like>(
|
|
|
346
346
|
out[14] = translation[2];
|
|
347
347
|
out[15] = 1;
|
|
348
348
|
return out;
|
|
349
|
-
}
|
|
349
|
+
};
|
|
350
350
|
|
|
351
351
|
/**
|
|
352
352
|
* Create a transformation matrix from the given rotation, translation, and scale.
|
|
@@ -359,12 +359,12 @@ export function fromRotationTranslation<T extends Matrix4Like>(
|
|
|
359
359
|
* @see [Rotation matrix](https://en.wikipedia.org/wiki/Rotation_matrix)
|
|
360
360
|
* @see [Transformation matrix](https://en.wikipedia.org/wiki/Transformation_matrix)
|
|
361
361
|
*/
|
|
362
|
-
export
|
|
362
|
+
export const fromRotationTranslationScale = <T extends Matrix4Like>(
|
|
363
363
|
rotation: QuaternionLike,
|
|
364
364
|
translation: Vector3Like,
|
|
365
365
|
scaling: Vector3Like,
|
|
366
366
|
out: T
|
|
367
|
-
) {
|
|
367
|
+
): T => {
|
|
368
368
|
const x = rotation[0];
|
|
369
369
|
const y = rotation[1];
|
|
370
370
|
const z = rotation[2];
|
|
@@ -404,7 +404,7 @@ export function fromRotationTranslationScale<T extends Matrix4Like>(
|
|
|
404
404
|
out[14] = translation[2];
|
|
405
405
|
out[15] = 1;
|
|
406
406
|
return out;
|
|
407
|
-
}
|
|
407
|
+
};
|
|
408
408
|
|
|
409
409
|
/**
|
|
410
410
|
* Create a transformation matrix from the given rotation, translation, and scale around the given origin.
|
|
@@ -418,13 +418,13 @@ export function fromRotationTranslationScale<T extends Matrix4Like>(
|
|
|
418
418
|
* @see [Rotation matrix](https://en.wikipedia.org/wiki/Rotation_matrix)
|
|
419
419
|
* @see [Transformation matrix](https://en.wikipedia.org/wiki/Transformation_matrix)
|
|
420
420
|
*/
|
|
421
|
-
export
|
|
421
|
+
export const fromRotationTranslationScaleOrigin = <T extends Matrix4Like>(
|
|
422
422
|
rotation: QuaternionLike,
|
|
423
423
|
translation: Vector3Like,
|
|
424
424
|
scaling: Vector3Like,
|
|
425
425
|
origin: Vector3Like,
|
|
426
426
|
out: T
|
|
427
|
-
) {
|
|
427
|
+
): T => {
|
|
428
428
|
const x = rotation[0];
|
|
429
429
|
const y = rotation[1];
|
|
430
430
|
const z = rotation[2];
|
|
@@ -477,7 +477,7 @@ export function fromRotationTranslationScaleOrigin<T extends Matrix4Like>(
|
|
|
477
477
|
out[14] = translation[2] + oz - (out2 * ox + out6 * oy + out10 * oz);
|
|
478
478
|
out[15] = 1;
|
|
479
479
|
return out;
|
|
480
|
-
}
|
|
480
|
+
};
|
|
481
481
|
|
|
482
482
|
// Used to store intermediary values in some functions.
|
|
483
483
|
const intermediary = createVector3Like();
|
|
@@ -491,10 +491,10 @@ const intermediary = createVector3Like();
|
|
|
491
491
|
* @see [Rotation matrix](https://en.wikipedia.org/wiki/Rotation_matrix)
|
|
492
492
|
* @see [Transformation matrix](https://en.wikipedia.org/wiki/Transformation_matrix)
|
|
493
493
|
*/
|
|
494
|
-
export
|
|
494
|
+
export const fromDualQuaternion = <T extends Matrix4Like>(
|
|
495
495
|
quaternion: DualQuaternionLike,
|
|
496
496
|
out: T
|
|
497
|
-
) {
|
|
497
|
+
): T => {
|
|
498
498
|
const bx = -quaternion[0];
|
|
499
499
|
const by = -quaternion[1];
|
|
500
500
|
const bz = -quaternion[2];
|
|
@@ -516,7 +516,7 @@ export function fromDualQuaternion<T extends Matrix4Like>(
|
|
|
516
516
|
}
|
|
517
517
|
|
|
518
518
|
return fromRotationTranslation(quaternion, intermediary, out);
|
|
519
|
-
}
|
|
519
|
+
};
|
|
520
520
|
|
|
521
521
|
/**
|
|
522
522
|
* Generate a frustum matrix with the given bounds.
|
|
@@ -531,7 +531,7 @@ export function fromDualQuaternion<T extends Matrix4Like>(
|
|
|
531
531
|
* @see [Camera matrix](https://en.wikipedia.org/wiki/Camera_matrix)
|
|
532
532
|
* @see [3D projection](https://en.wikipedia.org/wiki/3D_projection)
|
|
533
533
|
*/
|
|
534
|
-
export
|
|
534
|
+
export const frustum = <T extends Matrix4Like>(
|
|
535
535
|
left: number,
|
|
536
536
|
right: number,
|
|
537
537
|
bottom: number,
|
|
@@ -539,7 +539,7 @@ export function frustum<T extends Matrix4Like>(
|
|
|
539
539
|
near: number,
|
|
540
540
|
far: number,
|
|
541
541
|
out: T
|
|
542
|
-
) {
|
|
542
|
+
): T => {
|
|
543
543
|
const rl = 1 / (right - left);
|
|
544
544
|
const tb = 1 / (top - bottom);
|
|
545
545
|
const nf = 1 / (near - far);
|
|
@@ -561,7 +561,7 @@ export function frustum<T extends Matrix4Like>(
|
|
|
561
561
|
out[14] = far * near * 2 * nf;
|
|
562
562
|
out[15] = 0;
|
|
563
563
|
return out;
|
|
564
|
-
}
|
|
564
|
+
};
|
|
565
565
|
|
|
566
566
|
/**
|
|
567
567
|
* Create a perspective projection matrix with the given bounds.
|
|
@@ -574,13 +574,13 @@ export function frustum<T extends Matrix4Like>(
|
|
|
574
574
|
* @see [Camera matrix](https://en.wikipedia.org/wiki/Camera_matrix)
|
|
575
575
|
* @see [3D projection](https://en.wikipedia.org/wiki/3D_projection)
|
|
576
576
|
*/
|
|
577
|
-
export
|
|
577
|
+
export const perspective = <T extends Matrix4Like>(
|
|
578
578
|
fov: number,
|
|
579
579
|
aspect: number,
|
|
580
580
|
near: number,
|
|
581
581
|
far: number,
|
|
582
582
|
out: T
|
|
583
|
-
) {
|
|
583
|
+
): T => {
|
|
584
584
|
const f = 1 / Math.tan(fov / 2);
|
|
585
585
|
|
|
586
586
|
out[0] = f / aspect;
|
|
@@ -608,7 +608,7 @@ export function perspective<T extends Matrix4Like>(
|
|
|
608
608
|
}
|
|
609
609
|
|
|
610
610
|
return out;
|
|
611
|
-
}
|
|
611
|
+
};
|
|
612
612
|
|
|
613
613
|
/**
|
|
614
614
|
* Create a perspective projection matrix from a field of view. Useful for generating projection matrices to be used with the WebXR API.
|
|
@@ -621,12 +621,12 @@ export function perspective<T extends Matrix4Like>(
|
|
|
621
621
|
* @see [Camera matrix](https://en.wikipedia.org/wiki/Camera_matrix)
|
|
622
622
|
* @see [3D projection](https://en.wikipedia.org/wiki/3D_projection)
|
|
623
623
|
*/
|
|
624
|
-
export
|
|
624
|
+
export const perspectiveFromFieldOfView = <T extends Matrix4Like>(
|
|
625
625
|
fov: FieldOfView,
|
|
626
626
|
near: number,
|
|
627
627
|
far: number,
|
|
628
628
|
out: T
|
|
629
|
-
) {
|
|
629
|
+
): T => {
|
|
630
630
|
const upTan = Math.tan((fov.upDegrees * Math.PI) / 180);
|
|
631
631
|
const downTan = Math.tan((fov.downDegrees * Math.PI) / 180);
|
|
632
632
|
const leftTan = Math.tan((fov.leftDegrees * Math.PI) / 180);
|
|
@@ -651,7 +651,7 @@ export function perspectiveFromFieldOfView<T extends Matrix4Like>(
|
|
|
651
651
|
out[14] = (far * near) / (near - far);
|
|
652
652
|
out[15] = 0;
|
|
653
653
|
return out;
|
|
654
|
-
}
|
|
654
|
+
};
|
|
655
655
|
|
|
656
656
|
/**
|
|
657
657
|
* Generate an orthogonal projection matrix with the given bounds.
|
|
@@ -666,7 +666,7 @@ export function perspectiveFromFieldOfView<T extends Matrix4Like>(
|
|
|
666
666
|
* @see [Camera matrix](https://en.wikipedia.org/wiki/Camera_matrix)
|
|
667
667
|
* @see [3D projection](https://en.wikipedia.org/wiki/3D_projection)
|
|
668
668
|
*/
|
|
669
|
-
export
|
|
669
|
+
export const ortho = <T extends Matrix4Like>(
|
|
670
670
|
left: number,
|
|
671
671
|
right: number,
|
|
672
672
|
bottom: number,
|
|
@@ -674,7 +674,7 @@ export function ortho<T extends Matrix4Like>(
|
|
|
674
674
|
near: number,
|
|
675
675
|
far: number,
|
|
676
676
|
out: T
|
|
677
|
-
) {
|
|
677
|
+
): T => {
|
|
678
678
|
const lr = 1 / (left - right);
|
|
679
679
|
const bt = 1 / (bottom - top);
|
|
680
680
|
const nf = 1 / (near - far);
|
|
@@ -696,7 +696,7 @@ export function ortho<T extends Matrix4Like>(
|
|
|
696
696
|
out[14] = (far + near) * nf;
|
|
697
697
|
out[15] = 1;
|
|
698
698
|
return out;
|
|
699
|
-
}
|
|
699
|
+
};
|
|
700
700
|
|
|
701
701
|
/**
|
|
702
702
|
* Generate a look-at matrix. If you want a matrix that actually makes an object look at another object, use `targetTo` instead.
|
|
@@ -707,12 +707,12 @@ export function ortho<T extends Matrix4Like>(
|
|
|
707
707
|
* @returns The look-at matrix.
|
|
708
708
|
* @see [Transformation matrix](https://en.wikipedia.org/wiki/Transformation_matrix)
|
|
709
709
|
*/
|
|
710
|
-
export
|
|
710
|
+
export const lookAt = <T extends Matrix4Like>(
|
|
711
711
|
eye: Vector3Like,
|
|
712
712
|
center: Vector3Like,
|
|
713
713
|
up: Vector3Like,
|
|
714
714
|
out: T
|
|
715
|
-
) {
|
|
715
|
+
): T => {
|
|
716
716
|
const eyex = eye[0];
|
|
717
717
|
const eyey = eye[1];
|
|
718
718
|
const eyez = eye[2];
|
|
@@ -788,7 +788,7 @@ export function lookAt<T extends Matrix4Like>(
|
|
|
788
788
|
out[14] = -(z0 * eyex + z1 * eyey + z2 * eyez);
|
|
789
789
|
out[15] = 1;
|
|
790
790
|
return out;
|
|
791
|
-
}
|
|
791
|
+
};
|
|
792
792
|
|
|
793
793
|
/**
|
|
794
794
|
* Create a matrix that makes something look at something else.
|
|
@@ -799,12 +799,12 @@ export function lookAt<T extends Matrix4Like>(
|
|
|
799
799
|
* @returns The transformation matrix.
|
|
800
800
|
* @see [Transformation matrix](https://en.wikipedia.org/wiki/Transformation_matrix)
|
|
801
801
|
*/
|
|
802
|
-
export
|
|
802
|
+
export const targetTo = <T extends Matrix4Like>(
|
|
803
803
|
eye: Vector3Like,
|
|
804
804
|
target: Vector3Like,
|
|
805
805
|
up: Vector3Like,
|
|
806
806
|
out: T
|
|
807
|
-
) {
|
|
807
|
+
): T => {
|
|
808
808
|
const eyex = eye[0];
|
|
809
809
|
const eyey = eye[1];
|
|
810
810
|
const eyez = eye[2];
|
|
@@ -852,7 +852,7 @@ export function targetTo<T extends Matrix4Like>(
|
|
|
852
852
|
out[14] = eyez;
|
|
853
853
|
out[15] = 1;
|
|
854
854
|
return out;
|
|
855
|
-
}
|
|
855
|
+
};
|
|
856
856
|
|
|
857
857
|
/**
|
|
858
858
|
* Add two matrices.
|
|
@@ -862,11 +862,11 @@ export function targetTo<T extends Matrix4Like>(
|
|
|
862
862
|
* @returns The sum.
|
|
863
863
|
* @see [Matrix addition](https://en.wikipedia.org/wiki/Matrix_addition)
|
|
864
864
|
*/
|
|
865
|
-
export
|
|
865
|
+
export const add = <T extends Matrix4Like>(
|
|
866
866
|
a: Matrix4Like,
|
|
867
867
|
b: Matrix4Like,
|
|
868
868
|
out: T
|
|
869
|
-
) {
|
|
869
|
+
): T => {
|
|
870
870
|
out[0] = a[0] + b[0];
|
|
871
871
|
out[1] = a[1] + b[1];
|
|
872
872
|
out[2] = a[2] + b[2];
|
|
@@ -884,7 +884,7 @@ export function add<T extends Matrix4Like>(
|
|
|
884
884
|
out[14] = a[14] + b[14];
|
|
885
885
|
out[15] = a[15] + b[15];
|
|
886
886
|
return out;
|
|
887
|
-
}
|
|
887
|
+
};
|
|
888
888
|
|
|
889
889
|
/**
|
|
890
890
|
* Create a two-by-two matrix with the given values.
|
|
@@ -907,7 +907,7 @@ export function add<T extends Matrix4Like>(
|
|
|
907
907
|
* @param out - The matrix to store the result in.
|
|
908
908
|
* @returns The matrix.
|
|
909
909
|
*/
|
|
910
|
-
export
|
|
910
|
+
export const fromValues = <T extends Matrix4Like>(
|
|
911
911
|
c0r0: number,
|
|
912
912
|
c0r1: number,
|
|
913
913
|
c0r2: number,
|
|
@@ -925,7 +925,7 @@ export function fromValues<T extends Matrix4Like>(
|
|
|
925
925
|
c3r2: number,
|
|
926
926
|
c3r3: number,
|
|
927
927
|
out: T
|
|
928
|
-
) {
|
|
928
|
+
): T => {
|
|
929
929
|
out[0] = c0r0;
|
|
930
930
|
out[1] = c0r1;
|
|
931
931
|
out[2] = c0r2;
|
|
@@ -943,7 +943,7 @@ export function fromValues<T extends Matrix4Like>(
|
|
|
943
943
|
out[14] = c3r2;
|
|
944
944
|
out[15] = c3r3;
|
|
945
945
|
return out;
|
|
946
|
-
}
|
|
946
|
+
};
|
|
947
947
|
|
|
948
948
|
/**
|
|
949
949
|
* Determine whether or not two matrices are roughly equivalent.
|
|
@@ -951,7 +951,7 @@ export function fromValues<T extends Matrix4Like>(
|
|
|
951
951
|
* @param b - The second matrix.
|
|
952
952
|
* @returns Whether or not the matrices are equivalent.
|
|
953
953
|
*/
|
|
954
|
-
export
|
|
954
|
+
export const equals = (a: Matrix4Like, b: Matrix4Like): boolean => {
|
|
955
955
|
const a0 = a[0];
|
|
956
956
|
const a1 = a[1];
|
|
957
957
|
const a2 = a[2];
|
|
@@ -1009,7 +1009,7 @@ export function equals(a: Matrix4Like, b: Matrix4Like) {
|
|
|
1009
1009
|
epsilon * Math.max(1, Math.abs(a14), Math.abs(b14)) &&
|
|
1010
1010
|
Math.abs(a15 - b15) <= epsilon * Math.max(1, Math.abs(a15), Math.abs(b15))
|
|
1011
1011
|
);
|
|
1012
|
-
}
|
|
1012
|
+
};
|
|
1013
1013
|
|
|
1014
1014
|
/**
|
|
1015
1015
|
* Determine whether or not two matrices are exactly equivalent.
|
|
@@ -1017,7 +1017,7 @@ export function equals(a: Matrix4Like, b: Matrix4Like) {
|
|
|
1017
1017
|
* @param b - The second matrix.
|
|
1018
1018
|
* @returns Whether the matrices are equivalent.
|
|
1019
1019
|
*/
|
|
1020
|
-
export
|
|
1020
|
+
export const exactEquals = (a: Matrix4Like, b: Matrix4Like): boolean => {
|
|
1021
1021
|
return (
|
|
1022
1022
|
a[0] === b[0] &&
|
|
1023
1023
|
a[1] === b[1] &&
|
|
@@ -1036,7 +1036,7 @@ export function exactEquals(a: Matrix4Like, b: Matrix4Like) {
|
|
|
1036
1036
|
a[14] === b[14] &&
|
|
1037
1037
|
a[15] === b[15]
|
|
1038
1038
|
);
|
|
1039
|
-
}
|
|
1039
|
+
};
|
|
1040
1040
|
|
|
1041
1041
|
/**
|
|
1042
1042
|
* Calculate the adjugate of a matrix.
|
|
@@ -1045,7 +1045,10 @@ export function exactEquals(a: Matrix4Like, b: Matrix4Like) {
|
|
|
1045
1045
|
* @returns The adjugate of the matrix.
|
|
1046
1046
|
* @see [Adjugate matrix](https://en.wikipedia.org/wiki/Adjugate_matrix)
|
|
1047
1047
|
*/
|
|
1048
|
-
export
|
|
1048
|
+
export const adjoint = <T extends Matrix4Like>(
|
|
1049
|
+
matrix: Matrix4Like,
|
|
1050
|
+
out: T
|
|
1051
|
+
): T => {
|
|
1049
1052
|
const a00 = matrix[0];
|
|
1050
1053
|
const a01 = matrix[1];
|
|
1051
1054
|
const a02 = matrix[2];
|
|
@@ -1136,7 +1139,7 @@ export function adjoint<T extends Matrix4Like>(matrix: Matrix4Like, out: T) {
|
|
|
1136
1139
|
a10 * (a01 * a22 - a02 * a21) +
|
|
1137
1140
|
a20 * (a01 * a12 - a02 * a11);
|
|
1138
1141
|
return out;
|
|
1139
|
-
}
|
|
1142
|
+
};
|
|
1140
1143
|
|
|
1141
1144
|
/**
|
|
1142
1145
|
* Copy the values of one matrix into another.
|
|
@@ -1144,7 +1147,7 @@ export function adjoint<T extends Matrix4Like>(matrix: Matrix4Like, out: T) {
|
|
|
1144
1147
|
* @param out - The matrix to store the result in.
|
|
1145
1148
|
* @returns This matrix.
|
|
1146
1149
|
*/
|
|
1147
|
-
export
|
|
1150
|
+
export const copy = <T extends Matrix4Like>(matrix: Matrix4Like, out: T): T => {
|
|
1148
1151
|
out[0] = matrix[0];
|
|
1149
1152
|
out[1] = matrix[1];
|
|
1150
1153
|
out[2] = matrix[2];
|
|
@@ -1162,7 +1165,7 @@ export function copy<T extends Matrix4Like>(matrix: Matrix4Like, out: T) {
|
|
|
1162
1165
|
out[14] = matrix[14];
|
|
1163
1166
|
out[15] = matrix[15];
|
|
1164
1167
|
return out;
|
|
1165
|
-
}
|
|
1168
|
+
};
|
|
1166
1169
|
|
|
1167
1170
|
/**
|
|
1168
1171
|
* Calculate the Frobenius norm of a matrix.
|
|
@@ -1170,7 +1173,7 @@ export function copy<T extends Matrix4Like>(matrix: Matrix4Like, out: T) {
|
|
|
1170
1173
|
* @returns The Frobenius norm.
|
|
1171
1174
|
* @see [Matrix norm](https://en.wikipedia.org/wiki/Matrix_norm)
|
|
1172
1175
|
*/
|
|
1173
|
-
export
|
|
1176
|
+
export const frob = (matrix: Matrix4Like): number => {
|
|
1174
1177
|
return Math.hypot(
|
|
1175
1178
|
matrix[0],
|
|
1176
1179
|
matrix[1],
|
|
@@ -1189,7 +1192,7 @@ export function frob(matrix: Matrix4Like) {
|
|
|
1189
1192
|
matrix[14],
|
|
1190
1193
|
matrix[15]
|
|
1191
1194
|
);
|
|
1192
|
-
}
|
|
1195
|
+
};
|
|
1193
1196
|
|
|
1194
1197
|
/**
|
|
1195
1198
|
* Multiply two matrices.
|
|
@@ -1199,11 +1202,11 @@ export function frob(matrix: Matrix4Like) {
|
|
|
1199
1202
|
* @returns The product.
|
|
1200
1203
|
* @see [Matrix multiplication](https://en.wikipedia.org/wiki/Matrix_multiplication)
|
|
1201
1204
|
*/
|
|
1202
|
-
export
|
|
1205
|
+
export const multiply = <T extends Matrix4Like>(
|
|
1203
1206
|
a: Matrix4Like,
|
|
1204
1207
|
b: Matrix4Like,
|
|
1205
1208
|
out: T
|
|
1206
|
-
) {
|
|
1209
|
+
): T => {
|
|
1207
1210
|
const a00 = a[0];
|
|
1208
1211
|
const a01 = a[1];
|
|
1209
1212
|
const a02 = a[2];
|
|
@@ -1254,7 +1257,7 @@ export function multiply<T extends Matrix4Like>(
|
|
|
1254
1257
|
out[14] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
|
|
1255
1258
|
out[15] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
|
|
1256
1259
|
return out;
|
|
1257
|
-
}
|
|
1260
|
+
};
|
|
1258
1261
|
|
|
1259
1262
|
/**
|
|
1260
1263
|
* Multiply a matrix by a scalar value.
|
|
@@ -1264,11 +1267,11 @@ export function multiply<T extends Matrix4Like>(
|
|
|
1264
1267
|
* @returns The product.
|
|
1265
1268
|
* @see [Matrix multiplication](https://en.wikipedia.org/wiki/Matrix_multiplication)
|
|
1266
1269
|
*/
|
|
1267
|
-
export
|
|
1270
|
+
export const multiplyScalar = <T extends Matrix4Like>(
|
|
1268
1271
|
matrix: Matrix4Like,
|
|
1269
1272
|
scalar: number,
|
|
1270
1273
|
out: T
|
|
1271
|
-
) {
|
|
1274
|
+
): T => {
|
|
1272
1275
|
out[0] = matrix[0] * scalar;
|
|
1273
1276
|
out[1] = matrix[1] * scalar;
|
|
1274
1277
|
out[2] = matrix[2] * scalar;
|
|
@@ -1286,7 +1289,7 @@ export function multiplyScalar<T extends Matrix4Like>(
|
|
|
1286
1289
|
out[14] = matrix[14] * scalar;
|
|
1287
1290
|
out[15] = matrix[15] * scalar;
|
|
1288
1291
|
return out;
|
|
1289
|
-
}
|
|
1292
|
+
};
|
|
1290
1293
|
|
|
1291
1294
|
/**
|
|
1292
1295
|
* Add a matrix to another after multiplying the other by a scalar.
|
|
@@ -1298,12 +1301,12 @@ export function multiplyScalar<T extends Matrix4Like>(
|
|
|
1298
1301
|
* @see [Matrix addition](https://en.wikipedia.org/wiki/Matrix_addition)
|
|
1299
1302
|
* @see [Matrix multiplication](https://en.wikipedia.org/wiki/Matrix_multiplication)
|
|
1300
1303
|
*/
|
|
1301
|
-
export
|
|
1304
|
+
export const multiplyScalarAndAdd = <T extends Matrix4Like>(
|
|
1302
1305
|
a: Matrix4Like,
|
|
1303
1306
|
b: Matrix4Like,
|
|
1304
1307
|
scalar: number,
|
|
1305
1308
|
out: T
|
|
1306
|
-
) {
|
|
1309
|
+
): T => {
|
|
1307
1310
|
out[0] = a[0] + b[0] * scalar;
|
|
1308
1311
|
out[1] = a[1] + b[1] * scalar;
|
|
1309
1312
|
out[2] = a[2] + b[2] * scalar;
|
|
@@ -1321,7 +1324,7 @@ export function multiplyScalarAndAdd<T extends Matrix4Like>(
|
|
|
1321
1324
|
out[14] = a[14] + b[14] * scalar;
|
|
1322
1325
|
out[15] = a[15] + b[15] * scalar;
|
|
1323
1326
|
return out;
|
|
1324
|
-
}
|
|
1327
|
+
};
|
|
1325
1328
|
|
|
1326
1329
|
/**
|
|
1327
1330
|
* Subtract two matrices.
|
|
@@ -1331,11 +1334,11 @@ export function multiplyScalarAndAdd<T extends Matrix4Like>(
|
|
|
1331
1334
|
* @returns The difference.
|
|
1332
1335
|
* @see [Matrix addition](https://en.wikipedia.org/wiki/Matrix_addition)
|
|
1333
1336
|
*/
|
|
1334
|
-
export
|
|
1337
|
+
export const subtract = <T extends Matrix4Like>(
|
|
1335
1338
|
a: Matrix4Like,
|
|
1336
1339
|
b: Matrix4Like,
|
|
1337
1340
|
out: T
|
|
1338
|
-
) {
|
|
1341
|
+
): T => {
|
|
1339
1342
|
out[0] = a[0] - b[0];
|
|
1340
1343
|
out[1] = a[1] - b[1];
|
|
1341
1344
|
out[2] = a[2] - b[2];
|
|
@@ -1353,7 +1356,7 @@ export function subtract<T extends Matrix4Like>(
|
|
|
1353
1356
|
out[14] = a[14] - b[14];
|
|
1354
1357
|
out[15] = a[15] - b[15];
|
|
1355
1358
|
return out;
|
|
1356
|
-
}
|
|
1359
|
+
};
|
|
1357
1360
|
|
|
1358
1361
|
/**
|
|
1359
1362
|
* Transpose a matrix.
|
|
@@ -1362,7 +1365,10 @@ export function subtract<T extends Matrix4Like>(
|
|
|
1362
1365
|
* @returns The transpose.
|
|
1363
1366
|
* @see [Transpose](https://en.wikipedia.org/wiki/Transpose)
|
|
1364
1367
|
*/
|
|
1365
|
-
export
|
|
1368
|
+
export const transpose = <T extends Matrix4Like>(
|
|
1369
|
+
matrix: Matrix4Like,
|
|
1370
|
+
out: T
|
|
1371
|
+
): T => {
|
|
1366
1372
|
if (out === matrix) {
|
|
1367
1373
|
const a01 = matrix[1];
|
|
1368
1374
|
const a02 = matrix[2];
|
|
@@ -1402,7 +1408,7 @@ export function transpose<T extends Matrix4Like>(matrix: Matrix4Like, out: T) {
|
|
|
1402
1408
|
}
|
|
1403
1409
|
|
|
1404
1410
|
return out;
|
|
1405
|
-
}
|
|
1411
|
+
};
|
|
1406
1412
|
|
|
1407
1413
|
/**
|
|
1408
1414
|
* Calculate the determinant of a matrix.
|
|
@@ -1410,7 +1416,7 @@ export function transpose<T extends Matrix4Like>(matrix: Matrix4Like, out: T) {
|
|
|
1410
1416
|
* @returns The determinant.
|
|
1411
1417
|
* @see [Determinant](https://en.wikipedia.org/wiki/Determinant)
|
|
1412
1418
|
*/
|
|
1413
|
-
export
|
|
1419
|
+
export const determinant = (matrix: Matrix4Like): number => {
|
|
1414
1420
|
const a00 = matrix[0];
|
|
1415
1421
|
const a01 = matrix[1];
|
|
1416
1422
|
const a02 = matrix[2];
|
|
@@ -1442,7 +1448,7 @@ export function determinant(matrix: Matrix4Like) {
|
|
|
1442
1448
|
const b11 = a22 * a33 - a23 * a32;
|
|
1443
1449
|
|
|
1444
1450
|
return b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
|
|
1445
|
-
}
|
|
1451
|
+
};
|
|
1446
1452
|
|
|
1447
1453
|
/**
|
|
1448
1454
|
* Invert a matrix.
|
|
@@ -1451,7 +1457,10 @@ export function determinant(matrix: Matrix4Like) {
|
|
|
1451
1457
|
* @returns The inverted matrix.
|
|
1452
1458
|
* @see [Invertible matrix](https://en.wikipedia.org/wiki/Invertible_matrix)
|
|
1453
1459
|
*/
|
|
1454
|
-
export
|
|
1460
|
+
export const invert = <T extends Matrix4Like>(
|
|
1461
|
+
matrix: Matrix4Like,
|
|
1462
|
+
out: T
|
|
1463
|
+
): T => {
|
|
1455
1464
|
const a00 = matrix[0];
|
|
1456
1465
|
const a01 = matrix[1];
|
|
1457
1466
|
const a02 = matrix[2];
|
|
@@ -1506,7 +1515,7 @@ export function invert<T extends Matrix4Like>(matrix: Matrix4Like, out: T) {
|
|
|
1506
1515
|
out[14] = (a31 * b01 - a30 * b03 - a32 * b00) * det;
|
|
1507
1516
|
out[15] = (a20 * b03 - a21 * b01 + a22 * b00) * det;
|
|
1508
1517
|
return out;
|
|
1509
|
-
}
|
|
1518
|
+
};
|
|
1510
1519
|
|
|
1511
1520
|
/**
|
|
1512
1521
|
* Scale a matrix by the given vector.
|
|
@@ -1516,11 +1525,11 @@ export function invert<T extends Matrix4Like>(matrix: Matrix4Like, out: T) {
|
|
|
1516
1525
|
* @returns The scaled matrix.
|
|
1517
1526
|
* @see [Transformation matrix](https://en.wikipedia.org/wiki/Transformation_matrix)
|
|
1518
1527
|
*/
|
|
1519
|
-
export
|
|
1528
|
+
export const scale = <T extends Matrix4Like>(
|
|
1520
1529
|
matrix: Matrix4Like,
|
|
1521
1530
|
vector: Vector3Like,
|
|
1522
1531
|
out: T
|
|
1523
|
-
) {
|
|
1532
|
+
): T => {
|
|
1524
1533
|
const x = vector[0];
|
|
1525
1534
|
const y = vector[1];
|
|
1526
1535
|
const z = vector[2];
|
|
@@ -1542,7 +1551,7 @@ export function scale<T extends Matrix4Like>(
|
|
|
1542
1551
|
out[14] = matrix[14];
|
|
1543
1552
|
out[15] = matrix[15];
|
|
1544
1553
|
return out;
|
|
1545
|
-
}
|
|
1554
|
+
};
|
|
1546
1555
|
|
|
1547
1556
|
/**
|
|
1548
1557
|
* Translate a matrix by the given vector.
|
|
@@ -1552,11 +1561,11 @@ export function scale<T extends Matrix4Like>(
|
|
|
1552
1561
|
* @returns The translated matrix.
|
|
1553
1562
|
* @see [Transformation matrix](https://en.wikipedia.org/wiki/Transformation_matrix)
|
|
1554
1563
|
*/
|
|
1555
|
-
export
|
|
1564
|
+
export const translate = <T extends Matrix4Like>(
|
|
1556
1565
|
matrix: Matrix4Like,
|
|
1557
1566
|
vector: Vector3Like,
|
|
1558
1567
|
out: T
|
|
1559
|
-
) {
|
|
1568
|
+
): T => {
|
|
1560
1569
|
const x = vector[0];
|
|
1561
1570
|
const y = vector[1];
|
|
1562
1571
|
const z = vector[2];
|
|
@@ -1599,7 +1608,7 @@ export function translate<T extends Matrix4Like>(
|
|
|
1599
1608
|
}
|
|
1600
1609
|
|
|
1601
1610
|
return out;
|
|
1602
|
-
}
|
|
1611
|
+
};
|
|
1603
1612
|
|
|
1604
1613
|
/**
|
|
1605
1614
|
* Rotate a matrix by the given angle around the given axis.
|
|
@@ -1610,12 +1619,12 @@ export function translate<T extends Matrix4Like>(
|
|
|
1610
1619
|
* @returns The rotated matrix.
|
|
1611
1620
|
* @see [Rotation matrix](https://en.wikipedia.org/wiki/Rotation_matrix)
|
|
1612
1621
|
*/
|
|
1613
|
-
export
|
|
1622
|
+
export const rotate = <T extends Matrix4Like>(
|
|
1614
1623
|
matrix: Matrix4Like,
|
|
1615
1624
|
radians: number,
|
|
1616
1625
|
axis: Vector3Like,
|
|
1617
1626
|
out: T
|
|
1618
|
-
) {
|
|
1627
|
+
): T => {
|
|
1619
1628
|
let x = axis[0];
|
|
1620
1629
|
let y = axis[1];
|
|
1621
1630
|
let z = axis[2];
|
|
@@ -1676,7 +1685,7 @@ export function rotate<T extends Matrix4Like>(
|
|
|
1676
1685
|
out[15] = matrix[15];
|
|
1677
1686
|
}
|
|
1678
1687
|
return out;
|
|
1679
|
-
}
|
|
1688
|
+
};
|
|
1680
1689
|
|
|
1681
1690
|
/**
|
|
1682
1691
|
* Rotate a matrix by the given angle around the X-axis.
|
|
@@ -1686,11 +1695,11 @@ export function rotate<T extends Matrix4Like>(
|
|
|
1686
1695
|
* @returns The rotated matrix.
|
|
1687
1696
|
* @see [Rotation matrix](https://en.wikipedia.org/wiki/Rotation_matrix)
|
|
1688
1697
|
*/
|
|
1689
|
-
export
|
|
1698
|
+
export const rotateX = <T extends Matrix4Like>(
|
|
1690
1699
|
matrix: Matrix4Like,
|
|
1691
1700
|
r: number,
|
|
1692
1701
|
out: T
|
|
1693
|
-
) {
|
|
1702
|
+
): T => {
|
|
1694
1703
|
const s = Math.sin(r);
|
|
1695
1704
|
const c = Math.cos(r);
|
|
1696
1705
|
|
|
@@ -1723,7 +1732,7 @@ export function rotateX<T extends Matrix4Like>(
|
|
|
1723
1732
|
out[10] = a22 * c - a12 * s;
|
|
1724
1733
|
out[11] = a23 * c - a13 * s;
|
|
1725
1734
|
return out;
|
|
1726
|
-
}
|
|
1735
|
+
};
|
|
1727
1736
|
|
|
1728
1737
|
/**
|
|
1729
1738
|
* Rotate a matrix by the given angle around the Y-axis.
|
|
@@ -1733,11 +1742,11 @@ export function rotateX<T extends Matrix4Like>(
|
|
|
1733
1742
|
* @returns The rotated matrix.
|
|
1734
1743
|
* @see [Rotation matrix](https://en.wikipedia.org/wiki/Rotation_matrix)
|
|
1735
1744
|
*/
|
|
1736
|
-
export
|
|
1745
|
+
export const rotateY = <T extends Matrix4Like>(
|
|
1737
1746
|
matrix: Matrix4Like,
|
|
1738
1747
|
r: number,
|
|
1739
1748
|
out: T
|
|
1740
|
-
) {
|
|
1749
|
+
): T => {
|
|
1741
1750
|
const s = Math.sin(r);
|
|
1742
1751
|
const c = Math.cos(r);
|
|
1743
1752
|
|
|
@@ -1770,7 +1779,7 @@ export function rotateY<T extends Matrix4Like>(
|
|
|
1770
1779
|
out[10] = a02 * s + a22 * c;
|
|
1771
1780
|
out[11] = a03 * s + a23 * c;
|
|
1772
1781
|
return out;
|
|
1773
|
-
}
|
|
1782
|
+
};
|
|
1774
1783
|
|
|
1775
1784
|
/**
|
|
1776
1785
|
* Rotate a matrix by the given angle around the Z-axis.
|
|
@@ -1780,11 +1789,11 @@ export function rotateY<T extends Matrix4Like>(
|
|
|
1780
1789
|
* @returns The rotated matrix.
|
|
1781
1790
|
* @see [Rotation matrix](https://en.wikipedia.org/wiki/Rotation_matrix)
|
|
1782
1791
|
*/
|
|
1783
|
-
export
|
|
1792
|
+
export const rotateZ = <T extends Matrix4Like>(
|
|
1784
1793
|
matrix: Matrix4Like,
|
|
1785
1794
|
r: number,
|
|
1786
1795
|
out: T
|
|
1787
|
-
) {
|
|
1796
|
+
): T => {
|
|
1788
1797
|
const s = Math.sin(r);
|
|
1789
1798
|
const c = Math.cos(r);
|
|
1790
1799
|
|
|
@@ -1817,7 +1826,7 @@ export function rotateZ<T extends Matrix4Like>(
|
|
|
1817
1826
|
out[6] = a12 * c - a02 * s;
|
|
1818
1827
|
out[7] = a13 * c - a03 * s;
|
|
1819
1828
|
return out;
|
|
1820
|
-
}
|
|
1829
|
+
};
|
|
1821
1830
|
|
|
1822
1831
|
/**
|
|
1823
1832
|
* Get the translation vector component of a transformation matrix.
|
|
@@ -1826,15 +1835,15 @@ export function rotateZ<T extends Matrix4Like>(
|
|
|
1826
1835
|
* @returns The translation vector.
|
|
1827
1836
|
* @see [Transformation matrix](https://en.wikipedia.org/wiki/Transformation_matrix)
|
|
1828
1837
|
*/
|
|
1829
|
-
export
|
|
1838
|
+
export const getTranslation = <T extends Vector3Like>(
|
|
1830
1839
|
matrix: Matrix4Like,
|
|
1831
1840
|
out: T
|
|
1832
|
-
) {
|
|
1841
|
+
): T => {
|
|
1833
1842
|
out[0] = matrix[12];
|
|
1834
1843
|
out[1] = matrix[13];
|
|
1835
1844
|
out[2] = matrix[14];
|
|
1836
1845
|
return out;
|
|
1837
|
-
}
|
|
1846
|
+
};
|
|
1838
1847
|
|
|
1839
1848
|
/**
|
|
1840
1849
|
* Set the translation vector component of a transformation matrix.
|
|
@@ -1844,11 +1853,11 @@ export function getTranslation<T extends Vector3Like>(
|
|
|
1844
1853
|
* @returns The transformation matrix.
|
|
1845
1854
|
* @see [Transformation matrix](https://en.wikipedia.org/wiki/Transformation_matrix)
|
|
1846
1855
|
*/
|
|
1847
|
-
export
|
|
1856
|
+
export const setTranslation = <T extends Matrix4Like>(
|
|
1848
1857
|
matrix: Matrix4Like,
|
|
1849
1858
|
translation: Vector3Like,
|
|
1850
1859
|
out: T
|
|
1851
|
-
) {
|
|
1860
|
+
): T => {
|
|
1852
1861
|
if (out !== matrix) {
|
|
1853
1862
|
out[0] = matrix[0];
|
|
1854
1863
|
out[1] = matrix[1];
|
|
@@ -1869,7 +1878,7 @@ export function setTranslation<T extends Matrix4Like>(
|
|
|
1869
1878
|
out[13] = translation[1];
|
|
1870
1879
|
out[14] = translation[2];
|
|
1871
1880
|
return out;
|
|
1872
|
-
}
|
|
1881
|
+
};
|
|
1873
1882
|
|
|
1874
1883
|
/**
|
|
1875
1884
|
* Get the scaling factor of a transformation matrix.
|
|
@@ -1878,7 +1887,10 @@ export function setTranslation<T extends Matrix4Like>(
|
|
|
1878
1887
|
* @returns The scaling vector.
|
|
1879
1888
|
* @see [Transformation matrix](https://en.wikipedia.org/wiki/Transformation_matrix)
|
|
1880
1889
|
*/
|
|
1881
|
-
export
|
|
1890
|
+
export const getScaling = <T extends Vector3Like>(
|
|
1891
|
+
matrix: Matrix4Like,
|
|
1892
|
+
out: T
|
|
1893
|
+
): T => {
|
|
1882
1894
|
const m11 = matrix[0];
|
|
1883
1895
|
const m12 = matrix[1];
|
|
1884
1896
|
const m13 = matrix[2];
|
|
@@ -1893,7 +1905,7 @@ export function getScaling<T extends Vector3Like>(matrix: Matrix4Like, out: T) {
|
|
|
1893
1905
|
out[1] = Math.hypot(m21, m22, m23);
|
|
1894
1906
|
out[2] = Math.hypot(m31, m32, m33);
|
|
1895
1907
|
return out;
|
|
1896
|
-
}
|
|
1908
|
+
};
|
|
1897
1909
|
|
|
1898
1910
|
/**
|
|
1899
1911
|
* Get the rotational component of a transformation matrix.
|
|
@@ -1902,10 +1914,10 @@ export function getScaling<T extends Vector3Like>(matrix: Matrix4Like, out: T) {
|
|
|
1902
1914
|
* @returns The rotation.
|
|
1903
1915
|
* @see [Rotation matrix](https://en.wikipedia.org/wiki/Rotation_matrix)
|
|
1904
1916
|
*/
|
|
1905
|
-
export
|
|
1917
|
+
export const getRotation = <T extends QuaternionLike>(
|
|
1906
1918
|
matrix: Matrix4Like,
|
|
1907
1919
|
out: T
|
|
1908
|
-
) {
|
|
1920
|
+
): T => {
|
|
1909
1921
|
const scaling = getScaling(matrix, createVector3Like());
|
|
1910
1922
|
|
|
1911
1923
|
const is1 = 1 / scaling[0];
|
|
@@ -1957,7 +1969,7 @@ export function getRotation<T extends QuaternionLike>(
|
|
|
1957
1969
|
out[2] = 0.25 * s;
|
|
1958
1970
|
out[3] = (sm12 - sm21) / s;
|
|
1959
1971
|
return out;
|
|
1960
|
-
}
|
|
1972
|
+
};
|
|
1961
1973
|
|
|
1962
1974
|
/**
|
|
1963
1975
|
* A four-by-four matrix.
|
|
@@ -1977,7 +1989,7 @@ export default class Matrix4
|
|
|
1977
1989
|
public static fromTranslation<T extends Matrix4Like>(
|
|
1978
1990
|
vector: Vector3Like,
|
|
1979
1991
|
out = new Matrix4() as unknown as T
|
|
1980
|
-
) {
|
|
1992
|
+
): T {
|
|
1981
1993
|
return fromTranslation(vector, out);
|
|
1982
1994
|
}
|
|
1983
1995
|
|
|
@@ -1991,7 +2003,7 @@ export default class Matrix4
|
|
|
1991
2003
|
public static fromScaling<T extends Matrix4Like>(
|
|
1992
2004
|
vector: Vector3Like,
|
|
1993
2005
|
out = new Matrix4() as unknown as T
|
|
1994
|
-
) {
|
|
2006
|
+
): T {
|
|
1995
2007
|
return fromScaling(vector, out);
|
|
1996
2008
|
}
|
|
1997
2009
|
|
|
@@ -2007,7 +2019,7 @@ export default class Matrix4
|
|
|
2007
2019
|
r: number,
|
|
2008
2020
|
axis: Vector3Like,
|
|
2009
2021
|
out = new Matrix4() as unknown as T
|
|
2010
|
-
) {
|
|
2022
|
+
): T {
|
|
2011
2023
|
return fromRotation(r, axis, out);
|
|
2012
2024
|
}
|
|
2013
2025
|
|
|
@@ -2021,7 +2033,7 @@ export default class Matrix4
|
|
|
2021
2033
|
public static fromXRotation<T extends Matrix4Like>(
|
|
2022
2034
|
r: number,
|
|
2023
2035
|
out = new Matrix4() as unknown as T
|
|
2024
|
-
) {
|
|
2036
|
+
): T {
|
|
2025
2037
|
return fromXRotation(r, out);
|
|
2026
2038
|
}
|
|
2027
2039
|
|
|
@@ -2035,7 +2047,7 @@ export default class Matrix4
|
|
|
2035
2047
|
public static fromYRotation<T extends Matrix4Like>(
|
|
2036
2048
|
r: number,
|
|
2037
2049
|
out = new Matrix4() as unknown as T
|
|
2038
|
-
) {
|
|
2050
|
+
): T {
|
|
2039
2051
|
return fromYRotation(r, out);
|
|
2040
2052
|
}
|
|
2041
2053
|
|
|
@@ -2049,7 +2061,7 @@ export default class Matrix4
|
|
|
2049
2061
|
public static fromZRotation<T extends Matrix4Like>(
|
|
2050
2062
|
r: number,
|
|
2051
2063
|
out = new Matrix4() as unknown as T
|
|
2052
|
-
) {
|
|
2064
|
+
): T {
|
|
2053
2065
|
return fromZRotation(r, out);
|
|
2054
2066
|
}
|
|
2055
2067
|
|
|
@@ -2066,7 +2078,7 @@ export default class Matrix4
|
|
|
2066
2078
|
rotation: QuaternionLike,
|
|
2067
2079
|
translation: Vector3Like,
|
|
2068
2080
|
out = new Matrix4() as unknown as T
|
|
2069
|
-
) {
|
|
2081
|
+
): T {
|
|
2070
2082
|
return fromRotationTranslation(rotation, translation, out);
|
|
2071
2083
|
}
|
|
2072
2084
|
|
|
@@ -2085,7 +2097,7 @@ export default class Matrix4
|
|
|
2085
2097
|
translation: Vector3Like,
|
|
2086
2098
|
scaling: Vector3Like,
|
|
2087
2099
|
out = new Matrix4() as unknown as T
|
|
2088
|
-
) {
|
|
2100
|
+
): T {
|
|
2089
2101
|
return fromRotationTranslationScale(rotation, translation, scaling, out);
|
|
2090
2102
|
}
|
|
2091
2103
|
|
|
@@ -2106,7 +2118,7 @@ export default class Matrix4
|
|
|
2106
2118
|
scaling: Vector3Like,
|
|
2107
2119
|
origin: Vector3Like,
|
|
2108
2120
|
out = new Matrix4() as unknown as T
|
|
2109
|
-
) {
|
|
2121
|
+
): T {
|
|
2110
2122
|
return fromRotationTranslationScaleOrigin(
|
|
2111
2123
|
rotation,
|
|
2112
2124
|
translation,
|
|
@@ -2128,7 +2140,7 @@ export default class Matrix4
|
|
|
2128
2140
|
public static fromDualQuaternion<T extends Matrix4Like>(
|
|
2129
2141
|
quaternion: DualQuaternionLike,
|
|
2130
2142
|
out = new Matrix4() as unknown as T
|
|
2131
|
-
) {
|
|
2143
|
+
): T {
|
|
2132
2144
|
return fromDualQuaternion(quaternion, out);
|
|
2133
2145
|
}
|
|
2134
2146
|
|
|
@@ -2153,7 +2165,7 @@ export default class Matrix4
|
|
|
2153
2165
|
near: number,
|
|
2154
2166
|
far: number,
|
|
2155
2167
|
out = new Matrix4() as unknown as T
|
|
2156
|
-
) {
|
|
2168
|
+
): T {
|
|
2157
2169
|
return frustum(left, right, bottom, top, near, far, out);
|
|
2158
2170
|
}
|
|
2159
2171
|
|
|
@@ -2174,7 +2186,7 @@ export default class Matrix4
|
|
|
2174
2186
|
near: number,
|
|
2175
2187
|
far: number,
|
|
2176
2188
|
out = new Matrix4() as unknown as T
|
|
2177
|
-
) {
|
|
2189
|
+
): T {
|
|
2178
2190
|
return perspective(fov, aspect, near, far, out);
|
|
2179
2191
|
}
|
|
2180
2192
|
|
|
@@ -2194,7 +2206,7 @@ export default class Matrix4
|
|
|
2194
2206
|
near: number,
|
|
2195
2207
|
far: number,
|
|
2196
2208
|
out = new Matrix4() as unknown as T
|
|
2197
|
-
) {
|
|
2209
|
+
): T {
|
|
2198
2210
|
return perspectiveFromFieldOfView(fov, near, far, out);
|
|
2199
2211
|
}
|
|
2200
2212
|
|
|
@@ -2219,7 +2231,7 @@ export default class Matrix4
|
|
|
2219
2231
|
near: number,
|
|
2220
2232
|
far: number,
|
|
2221
2233
|
out = new Matrix4() as unknown as T
|
|
2222
|
-
) {
|
|
2234
|
+
): T {
|
|
2223
2235
|
return ortho(left, right, bottom, top, near, far, out);
|
|
2224
2236
|
}
|
|
2225
2237
|
|
|
@@ -2237,7 +2249,7 @@ export default class Matrix4
|
|
|
2237
2249
|
center: Vector3Like,
|
|
2238
2250
|
up: Vector3Like = [0, 1, 0],
|
|
2239
2251
|
out = new Matrix4() as unknown as T
|
|
2240
|
-
) {
|
|
2252
|
+
): T {
|
|
2241
2253
|
return lookAt(eye, center, up, out);
|
|
2242
2254
|
}
|
|
2243
2255
|
|
|
@@ -2255,7 +2267,7 @@ export default class Matrix4
|
|
|
2255
2267
|
target: Vector3Like,
|
|
2256
2268
|
up: Vector3Like = [0, 1, 0],
|
|
2257
2269
|
out = new Matrix4() as unknown as T
|
|
2258
|
-
) {
|
|
2270
|
+
): T {
|
|
2259
2271
|
return targetTo(eye, target, up, out);
|
|
2260
2272
|
}
|
|
2261
2273
|
|
|
@@ -2298,7 +2310,7 @@ export default class Matrix4
|
|
|
2298
2310
|
c3r2: number,
|
|
2299
2311
|
c3r3: number,
|
|
2300
2312
|
out = new Matrix4() as unknown as T
|
|
2301
|
-
) {
|
|
2313
|
+
): T {
|
|
2302
2314
|
return fromValues(
|
|
2303
2315
|
c0r0,
|
|
2304
2316
|
c0r1,
|
|
@@ -2395,7 +2407,7 @@ export default class Matrix4
|
|
|
2395
2407
|
* @param matrix - The other matrix.
|
|
2396
2408
|
* @returns Whether or not the matrices are equivalent.
|
|
2397
2409
|
*/
|
|
2398
|
-
public equals(matrix: Matrix4Like) {
|
|
2410
|
+
public equals(matrix: Matrix4Like): boolean {
|
|
2399
2411
|
return equals(this, matrix);
|
|
2400
2412
|
}
|
|
2401
2413
|
|
|
@@ -2404,7 +2416,7 @@ export default class Matrix4
|
|
|
2404
2416
|
* @param matrix - The other matrix.
|
|
2405
2417
|
* @returns Whether or not the matrices are equivalent.
|
|
2406
2418
|
*/
|
|
2407
|
-
public exactEquals(matrix: Matrix4Like) {
|
|
2419
|
+
public exactEquals(matrix: Matrix4Like): boolean {
|
|
2408
2420
|
return exactEquals(this, matrix);
|
|
2409
2421
|
}
|
|
2410
2422
|
|
|
@@ -2418,7 +2430,7 @@ export default class Matrix4
|
|
|
2418
2430
|
public add<T extends Matrix4Like>(
|
|
2419
2431
|
matrix: Matrix4Like,
|
|
2420
2432
|
out = new Matrix4() as unknown as T
|
|
2421
|
-
) {
|
|
2433
|
+
): T {
|
|
2422
2434
|
return add(this, matrix, out);
|
|
2423
2435
|
}
|
|
2424
2436
|
|
|
@@ -2428,7 +2440,9 @@ export default class Matrix4
|
|
|
2428
2440
|
* @returns The adjugate of this matrix.
|
|
2429
2441
|
* @see [Adjugate matrix](https://en.wikipedia.org/wiki/Adjugate_matrix)
|
|
2430
2442
|
*/
|
|
2431
|
-
public adjoint<T extends Matrix4Like>(
|
|
2443
|
+
public adjoint<T extends Matrix4Like>(
|
|
2444
|
+
out = new Matrix4() as unknown as T
|
|
2445
|
+
): T {
|
|
2432
2446
|
return adjoint(this, out);
|
|
2433
2447
|
}
|
|
2434
2448
|
|
|
@@ -2437,7 +2451,7 @@ export default class Matrix4
|
|
|
2437
2451
|
* @param out - The matrix to store the result in.
|
|
2438
2452
|
* @returns The copy.
|
|
2439
2453
|
*/
|
|
2440
|
-
public clone<T extends Matrix4Like>(out = new Matrix4() as unknown as T) {
|
|
2454
|
+
public clone<T extends Matrix4Like>(out = new Matrix4() as unknown as T): T {
|
|
2441
2455
|
return copy(this, out);
|
|
2442
2456
|
}
|
|
2443
2457
|
|
|
@@ -2446,7 +2460,7 @@ export default class Matrix4
|
|
|
2446
2460
|
* @param matrix - The matrix to copy.
|
|
2447
2461
|
* @returns This matrix.
|
|
2448
2462
|
*/
|
|
2449
|
-
public copy(matrix: Matrix4Like) {
|
|
2463
|
+
public copy(matrix: Matrix4Like): this {
|
|
2450
2464
|
return copy(matrix, this);
|
|
2451
2465
|
}
|
|
2452
2466
|
|
|
@@ -2454,7 +2468,7 @@ export default class Matrix4
|
|
|
2454
2468
|
* Get the Frobenius norm of this matrix.
|
|
2455
2469
|
* @see [Matrix norm](https://en.wikipedia.org/wiki/Matrix_norm)
|
|
2456
2470
|
*/
|
|
2457
|
-
public get frob() {
|
|
2471
|
+
public get frob(): number {
|
|
2458
2472
|
return frob(this);
|
|
2459
2473
|
}
|
|
2460
2474
|
|
|
@@ -2468,7 +2482,7 @@ export default class Matrix4
|
|
|
2468
2482
|
public multiply<T extends Matrix4Like>(
|
|
2469
2483
|
matrix: Matrix4Like,
|
|
2470
2484
|
out = new Matrix4() as unknown as T
|
|
2471
|
-
) {
|
|
2485
|
+
): T {
|
|
2472
2486
|
return multiply(this, matrix, out);
|
|
2473
2487
|
}
|
|
2474
2488
|
|
|
@@ -2482,7 +2496,7 @@ export default class Matrix4
|
|
|
2482
2496
|
public multiplyScalar<T extends Matrix4Like>(
|
|
2483
2497
|
scalar: number,
|
|
2484
2498
|
out = new Matrix4() as unknown as T
|
|
2485
|
-
) {
|
|
2499
|
+
): T {
|
|
2486
2500
|
return multiplyScalar(this, scalar, out);
|
|
2487
2501
|
}
|
|
2488
2502
|
|
|
@@ -2499,7 +2513,7 @@ export default class Matrix4
|
|
|
2499
2513
|
matrix: Matrix4Like,
|
|
2500
2514
|
scalar: number,
|
|
2501
2515
|
out = new Matrix4() as unknown as T
|
|
2502
|
-
) {
|
|
2516
|
+
): T {
|
|
2503
2517
|
return multiplyScalarAndAdd(this, matrix, scalar, out);
|
|
2504
2518
|
}
|
|
2505
2519
|
|
|
@@ -2513,7 +2527,7 @@ export default class Matrix4
|
|
|
2513
2527
|
public subtract<T extends Matrix4Like>(
|
|
2514
2528
|
matrix: Matrix4Like,
|
|
2515
2529
|
out = new Matrix4() as unknown as T
|
|
2516
|
-
) {
|
|
2530
|
+
): T {
|
|
2517
2531
|
return subtract(this, matrix, out);
|
|
2518
2532
|
}
|
|
2519
2533
|
|
|
@@ -2523,7 +2537,9 @@ export default class Matrix4
|
|
|
2523
2537
|
* @returns The transpose of this matrix.
|
|
2524
2538
|
* @see [Transpose](https://en.wikipedia.org/wiki/Transpose)
|
|
2525
2539
|
*/
|
|
2526
|
-
public transpose<T extends Matrix4Like>(
|
|
2540
|
+
public transpose<T extends Matrix4Like>(
|
|
2541
|
+
out = new Matrix4() as unknown as T
|
|
2542
|
+
): T {
|
|
2527
2543
|
return transpose(this, out);
|
|
2528
2544
|
}
|
|
2529
2545
|
|
|
@@ -2531,7 +2547,7 @@ export default class Matrix4
|
|
|
2531
2547
|
* Get the determinant of this matrix.
|
|
2532
2548
|
* @see [Determinant](https://en.wikipedia.org/wiki/Determinant)
|
|
2533
2549
|
*/
|
|
2534
|
-
public get determinant() {
|
|
2550
|
+
public get determinant(): number {
|
|
2535
2551
|
return determinant(this);
|
|
2536
2552
|
}
|
|
2537
2553
|
|
|
@@ -2540,7 +2556,7 @@ export default class Matrix4
|
|
|
2540
2556
|
* @returns This matrix.
|
|
2541
2557
|
* @see [Identity matrix](https://en.wikipedia.org/wiki/Identity_matrix)
|
|
2542
2558
|
*/
|
|
2543
|
-
public identity() {
|
|
2559
|
+
public identity(): this {
|
|
2544
2560
|
return identity(this);
|
|
2545
2561
|
}
|
|
2546
2562
|
|
|
@@ -2550,7 +2566,7 @@ export default class Matrix4
|
|
|
2550
2566
|
* @returns The inverted matrix.
|
|
2551
2567
|
* @see [Invertible matrix](https://en.wikipedia.org/wiki/Invertible_matrix)
|
|
2552
2568
|
*/
|
|
2553
|
-
public invert<T extends Matrix4Like>(out = new Matrix4() as unknown as T) {
|
|
2569
|
+
public invert<T extends Matrix4Like>(out = new Matrix4() as unknown as T): T {
|
|
2554
2570
|
return invert(this, out);
|
|
2555
2571
|
}
|
|
2556
2572
|
|
|
@@ -2564,7 +2580,7 @@ export default class Matrix4
|
|
|
2564
2580
|
public scale<T extends Matrix4Like>(
|
|
2565
2581
|
vector: Vector3Like,
|
|
2566
2582
|
out = new Matrix4() as unknown as T
|
|
2567
|
-
) {
|
|
2583
|
+
): T {
|
|
2568
2584
|
return scale(this, vector, out);
|
|
2569
2585
|
}
|
|
2570
2586
|
|
|
@@ -2578,7 +2594,7 @@ export default class Matrix4
|
|
|
2578
2594
|
public translate<T extends Matrix4Like>(
|
|
2579
2595
|
vector: Vector3Like,
|
|
2580
2596
|
out = new Matrix4() as unknown as T
|
|
2581
|
-
) {
|
|
2597
|
+
): T {
|
|
2582
2598
|
return translate(this, vector, out);
|
|
2583
2599
|
}
|
|
2584
2600
|
|
|
@@ -2594,7 +2610,7 @@ export default class Matrix4
|
|
|
2594
2610
|
r: number,
|
|
2595
2611
|
axis: Vector3Like,
|
|
2596
2612
|
out = new Matrix4() as unknown as T
|
|
2597
|
-
) {
|
|
2613
|
+
): T {
|
|
2598
2614
|
return rotate(this, r, axis, out);
|
|
2599
2615
|
}
|
|
2600
2616
|
|
|
@@ -2608,7 +2624,7 @@ export default class Matrix4
|
|
|
2608
2624
|
public rotateX<T extends Matrix4Like>(
|
|
2609
2625
|
r: number,
|
|
2610
2626
|
out = new Matrix4() as unknown as T
|
|
2611
|
-
) {
|
|
2627
|
+
): T {
|
|
2612
2628
|
return rotateX(this, r, out);
|
|
2613
2629
|
}
|
|
2614
2630
|
|
|
@@ -2622,7 +2638,7 @@ export default class Matrix4
|
|
|
2622
2638
|
public rotateY<T extends Matrix4Like>(
|
|
2623
2639
|
r: number,
|
|
2624
2640
|
out = new Matrix4() as unknown as T
|
|
2625
|
-
) {
|
|
2641
|
+
): T {
|
|
2626
2642
|
return rotateY(this, r, out);
|
|
2627
2643
|
}
|
|
2628
2644
|
|
|
@@ -2636,7 +2652,7 @@ export default class Matrix4
|
|
|
2636
2652
|
public rotateZ<T extends Matrix4Like>(
|
|
2637
2653
|
r: number,
|
|
2638
2654
|
out = new Matrix4() as unknown as T
|
|
2639
|
-
) {
|
|
2655
|
+
): T {
|
|
2640
2656
|
return rotateZ(this, r, out);
|
|
2641
2657
|
}
|
|
2642
2658
|
|
|
@@ -2648,7 +2664,7 @@ export default class Matrix4
|
|
|
2648
2664
|
*/
|
|
2649
2665
|
public getTranslation<T extends Vector3Like>(
|
|
2650
2666
|
out = new Vector3() as unknown as T
|
|
2651
|
-
) {
|
|
2667
|
+
): T {
|
|
2652
2668
|
return getTranslation(this, out);
|
|
2653
2669
|
}
|
|
2654
2670
|
|
|
@@ -2662,7 +2678,7 @@ export default class Matrix4
|
|
|
2662
2678
|
public setTranslation<T extends Matrix4Like>(
|
|
2663
2679
|
translation: Vector3Like,
|
|
2664
2680
|
out = new Matrix4() as unknown as T
|
|
2665
|
-
) {
|
|
2681
|
+
): T {
|
|
2666
2682
|
return setTranslation(this, translation, out);
|
|
2667
2683
|
}
|
|
2668
2684
|
|
|
@@ -2674,7 +2690,7 @@ export default class Matrix4
|
|
|
2674
2690
|
*/
|
|
2675
2691
|
public getScaling<T extends Vector3Like>(
|
|
2676
2692
|
out = new Vector3() as unknown as T
|
|
2677
|
-
) {
|
|
2693
|
+
): T {
|
|
2678
2694
|
return getScaling(this, out);
|
|
2679
2695
|
}
|
|
2680
2696
|
|
|
@@ -2686,7 +2702,7 @@ export default class Matrix4
|
|
|
2686
2702
|
*/
|
|
2687
2703
|
public getRotation<T extends QuaternionLike>(
|
|
2688
2704
|
out = new Quaternion() as unknown as T
|
|
2689
|
-
) {
|
|
2705
|
+
): T {
|
|
2690
2706
|
return getRotation(this, out);
|
|
2691
2707
|
}
|
|
2692
2708
|
}
|