@lakuna/umath 2.0.0 → 3.0.0
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/greatestCommonDivisor.d.ts.map +1 -1
- package/dist/algorithms/greatestCommonDivisor.js +14 -4
- package/dist/algorithms/greatestCommonDivisor.js.map +1 -1
- package/dist/index.d.ts +11 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/linalg/DualQuaternion.d.ts +124 -124
- package/dist/linalg/DualQuaternion.d.ts.map +1 -1
- package/dist/linalg/DualQuaternion.js +173 -165
- package/dist/linalg/DualQuaternion.js.map +1 -1
- package/dist/linalg/Matrix.d.ts +24 -24
- package/dist/linalg/Matrix.d.ts.map +1 -1
- package/dist/linalg/Matrix2.d.ts +63 -63
- package/dist/linalg/Matrix2.d.ts.map +1 -1
- package/dist/linalg/Matrix2.js +92 -88
- package/dist/linalg/Matrix2.js.map +1 -1
- package/dist/linalg/Matrix3.d.ts +107 -107
- package/dist/linalg/Matrix3.d.ts.map +1 -1
- package/dist/linalg/Matrix3.js +147 -138
- package/dist/linalg/Matrix3.js.map +1 -1
- package/dist/linalg/Matrix4.d.ts +200 -201
- package/dist/linalg/Matrix4.d.ts.map +1 -1
- package/dist/linalg/Matrix4.js +272 -251
- package/dist/linalg/Matrix4.js.map +1 -1
- package/dist/linalg/Quaternion.d.ts +116 -116
- package/dist/linalg/Quaternion.d.ts.map +1 -1
- package/dist/linalg/Quaternion.js +175 -161
- package/dist/linalg/Quaternion.js.map +1 -1
- package/dist/linalg/SlowMatrix.d.ts +5 -5
- package/dist/linalg/SlowMatrix.d.ts.map +1 -1
- package/dist/linalg/SlowMatrix.js +12 -12
- package/dist/linalg/SlowMatrix.js.map +1 -1
- package/dist/linalg/SlowSquareMatrix.d.ts +6 -6
- package/dist/linalg/SlowSquareMatrix.d.ts.map +1 -1
- package/dist/linalg/SlowSquareMatrix.js +15 -15
- package/dist/linalg/SlowSquareMatrix.js.map +1 -1
- package/dist/linalg/SlowVector.d.ts +70 -70
- package/dist/linalg/SlowVector.d.ts.map +1 -1
- package/dist/linalg/SlowVector.js +153 -153
- package/dist/linalg/SlowVector.js.map +1 -1
- package/dist/linalg/SquareMatrix.d.ts +8 -8
- package/dist/linalg/SquareMatrix.d.ts.map +1 -1
- package/dist/linalg/Vector.d.ts +85 -84
- package/dist/linalg/Vector.d.ts.map +1 -1
- package/dist/linalg/Vector2.d.ts +104 -104
- package/dist/linalg/Vector2.d.ts.map +1 -1
- package/dist/linalg/Vector2.js +145 -143
- package/dist/linalg/Vector2.js.map +1 -1
- package/dist/linalg/Vector3.d.ts +130 -130
- package/dist/linalg/Vector3.d.ts.map +1 -1
- package/dist/linalg/Vector3.js +176 -173
- package/dist/linalg/Vector3.js.map +1 -1
- package/dist/linalg/Vector4.d.ts +101 -101
- package/dist/linalg/Vector4.d.ts.map +1 -1
- package/dist/linalg/Vector4.js +144 -140
- package/dist/linalg/Vector4.js.map +1 -1
- package/dist/types/AxisAngle.d.ts +2 -2
- package/dist/types/AxisAngle.d.ts.map +1 -1
- package/dist/types/FieldOfView.d.ts +2 -2
- package/dist/types/FieldOfView.d.ts.map +1 -1
- package/dist/utility/BigNumber.d.ts +21 -11
- package/dist/utility/BigNumber.d.ts.map +1 -1
- package/dist/utility/BigNumber.js +42 -31
- package/dist/utility/BigNumber.js.map +1 -1
- package/dist/utility/createAxisAngleLike.d.ts.map +1 -1
- package/dist/utility/createAxisAngleLike.js.map +1 -1
- package/package.json +11 -9
- package/src/algorithms/greatestCommonDivisor.ts +19 -7
- package/src/index.ts +17 -13
- package/src/linalg/DualQuaternion.ts +208 -193
- package/src/linalg/Matrix.ts +28 -28
- package/src/linalg/Matrix2.ts +117 -108
- package/src/linalg/Matrix3.ts +177 -158
- package/src/linalg/Matrix4.ts +386 -348
- package/src/linalg/Quaternion.ts +207 -189
- package/src/linalg/SlowMatrix.ts +19 -18
- package/src/linalg/SlowSquareMatrix.ts +19 -18
- package/src/linalg/SlowVector.ts +170 -169
- package/src/linalg/SquareMatrix.ts +9 -9
- package/src/linalg/Vector.ts +91 -89
- package/src/linalg/Vector2.ts +160 -155
- package/src/linalg/Vector3.ts +206 -199
- package/src/linalg/Vector4.ts +165 -156
- package/src/types/AxisAngle.ts +3 -3
- package/src/types/FieldOfView.ts +3 -3
- package/src/utility/BigNumber.ts +63 -41
- package/src/utility/createAxisAngleLike.ts +1 -0
package/dist/linalg/Matrix4.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import Quaternion, { fromValues as quaternionFromValues } from "./Quaternion.js";
|
|
2
|
-
import Vector3, { createVector3Like, fromValues as vector3FromValues } from "./Vector3.js";
|
|
3
|
-
import MagnitudeError from "../utility/MagnitudeError.js";
|
|
4
|
-
import SingularMatrixError from "../utility/SingularMatrixError.js";
|
|
5
1
|
import approx from "../algorithms/approx.js";
|
|
6
2
|
import approxRelative from "../algorithms/approxRelative.js";
|
|
7
3
|
import degreesToRadians from "../algorithms/degreesToRadians.js";
|
|
8
4
|
import epsilon from "../utility/epsilon.js";
|
|
5
|
+
import MagnitudeError from "../utility/MagnitudeError.js";
|
|
6
|
+
import SingularMatrixError from "../utility/SingularMatrixError.js";
|
|
7
|
+
import Quaternion, { fromValues as quaternionFromValues } from "./Quaternion.js";
|
|
8
|
+
import Vector3, { createVector3Like, fromValues as vector3FromValues } from "./Vector3.js";
|
|
9
9
|
/**
|
|
10
10
|
* Create a four-by-four matrix-like object.
|
|
11
11
|
* @returns A four-by-four matrix-like object.
|
|
12
12
|
* @public
|
|
13
13
|
*/
|
|
14
|
-
export const createMatrix4Like = () =>
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
export const createMatrix4Like = () =>
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
|
16
|
+
new Float32Array(16);
|
|
17
17
|
/**
|
|
18
18
|
* Create a four-by-four matrix with the given values.
|
|
19
19
|
* @param c0r0 - The value in the first column and first row.
|
|
@@ -115,6 +115,7 @@ export const fromRotation = (radians, axis, out) => {
|
|
|
115
115
|
* @see {@link https://en.wikipedia.org/wiki/Rotation_matrix | Rotation matrix}
|
|
116
116
|
* @public
|
|
117
117
|
*/
|
|
118
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
118
119
|
export const fromXRotation = (radians, out) => {
|
|
119
120
|
const s = Math.sin(radians);
|
|
120
121
|
const c = Math.cos(radians);
|
|
@@ -128,6 +129,7 @@ export const fromXRotation = (radians, out) => {
|
|
|
128
129
|
* @see {@link https://en.wikipedia.org/wiki/Rotation_matrix | Rotation matrix}
|
|
129
130
|
* @public
|
|
130
131
|
*/
|
|
132
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
131
133
|
export const fromYRotation = (radians, out) => {
|
|
132
134
|
const s = Math.sin(radians);
|
|
133
135
|
const c = Math.cos(radians);
|
|
@@ -141,6 +143,7 @@ export const fromYRotation = (radians, out) => {
|
|
|
141
143
|
* @see {@link https://en.wikipedia.org/wiki/Rotation_matrix | Rotation matrix}
|
|
142
144
|
* @public
|
|
143
145
|
*/
|
|
146
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
144
147
|
export const fromZRotation = (radians, out) => {
|
|
145
148
|
const s = Math.sin(radians);
|
|
146
149
|
const c = Math.cos(radians);
|
|
@@ -1218,60 +1221,138 @@ export const getRotation = (matrix, out) => {
|
|
|
1218
1221
|
* @public
|
|
1219
1222
|
*/
|
|
1220
1223
|
export default class Matrix4 extends Float32Array {
|
|
1224
|
+
/** The value in the first column and first row. */
|
|
1225
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
1226
|
+
0;
|
|
1227
|
+
/** The value in the first column and second row. */
|
|
1228
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
1229
|
+
1;
|
|
1230
|
+
/** The value in the first column and third row. */
|
|
1231
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
1232
|
+
2;
|
|
1233
|
+
/** The value in the first column and fourth row. */
|
|
1234
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
1235
|
+
3;
|
|
1236
|
+
/** The value in the second column and first row. */
|
|
1237
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
1238
|
+
4;
|
|
1239
|
+
/** The value in the second column and second row. */
|
|
1240
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
1241
|
+
5;
|
|
1242
|
+
/** The value in the second column and third row. */
|
|
1243
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
1244
|
+
6;
|
|
1245
|
+
/** The value in the second column and fourth row. */
|
|
1246
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
1247
|
+
7;
|
|
1248
|
+
/** The value in the third column and first row. */
|
|
1249
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
1250
|
+
8;
|
|
1251
|
+
/** The value in the third column and second row. */
|
|
1252
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
1253
|
+
9;
|
|
1254
|
+
/** The value in the third column and third row. */
|
|
1255
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
1256
|
+
10;
|
|
1257
|
+
/** The value in the third column and fourth row. */
|
|
1258
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
1259
|
+
11;
|
|
1260
|
+
/** The value in the fourth column and first row. */
|
|
1261
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
1262
|
+
12;
|
|
1263
|
+
/** The value in the fourth column and second row. */
|
|
1264
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
1265
|
+
13;
|
|
1266
|
+
/** The value in the fourth column and third row. */
|
|
1267
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
1268
|
+
14;
|
|
1269
|
+
/** The value in the fourth column and fourth row. */
|
|
1270
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
1271
|
+
15;
|
|
1272
|
+
/** The number of rows in this matrix. */
|
|
1273
|
+
height;
|
|
1274
|
+
/** The number of columns in this matrix. */
|
|
1275
|
+
width;
|
|
1221
1276
|
/**
|
|
1222
|
-
*
|
|
1223
|
-
* @
|
|
1224
|
-
|
|
1277
|
+
* Get the determinant of this matrix.
|
|
1278
|
+
* @see {@link https://en.wikipedia.org/wiki/Determinant | Determinant}
|
|
1279
|
+
*/
|
|
1280
|
+
get determinant() {
|
|
1281
|
+
return determinant(this);
|
|
1282
|
+
}
|
|
1283
|
+
/**
|
|
1284
|
+
* Get the Frobenius norm of this matrix.
|
|
1285
|
+
* @see {@link https://en.wikipedia.org/wiki/Matrix_norm | Matrix norm}
|
|
1286
|
+
*/
|
|
1287
|
+
get frob() {
|
|
1288
|
+
return frob(this);
|
|
1289
|
+
}
|
|
1290
|
+
/**
|
|
1291
|
+
* Get the scaling vector component of this transformation matrix.
|
|
1292
|
+
* @returns The rotation.
|
|
1293
|
+
* @see {@link https://en.wikipedia.org/wiki/Rotation_matrix | Rotation matrix}
|
|
1294
|
+
*/
|
|
1295
|
+
get rotation() {
|
|
1296
|
+
return getRotation(this, new Quaternion());
|
|
1297
|
+
}
|
|
1298
|
+
/**
|
|
1299
|
+
* Get the scaling vector component of this transformation matrix.
|
|
1300
|
+
* @returns The scaling.
|
|
1225
1301
|
* @see {@link https://en.wikipedia.org/wiki/Transformation_matrix | Transformation matrix}
|
|
1226
1302
|
*/
|
|
1227
|
-
|
|
1228
|
-
return
|
|
1303
|
+
get scaling() {
|
|
1304
|
+
return getScaling(this, new Vector3());
|
|
1229
1305
|
}
|
|
1230
1306
|
/**
|
|
1231
|
-
*
|
|
1232
|
-
* @param vector - The scaling vector.
|
|
1233
|
-
* @returns The transformation matrix.
|
|
1307
|
+
* The translation vector component of this transformation matrix.
|
|
1234
1308
|
* @see {@link https://en.wikipedia.org/wiki/Transformation_matrix | Transformation matrix}
|
|
1235
1309
|
*/
|
|
1236
|
-
|
|
1237
|
-
return
|
|
1310
|
+
get translation() {
|
|
1311
|
+
return getTranslation(this, new Vector3());
|
|
1238
1312
|
}
|
|
1239
1313
|
/**
|
|
1240
|
-
* Create a
|
|
1241
|
-
* @
|
|
1242
|
-
* @param axis - The axis to rotate around.
|
|
1243
|
-
* @returns The transformation matrix.
|
|
1244
|
-
* @see {@link https://en.wikipedia.org/wiki/Rotation_matrix | Rotation matrix}
|
|
1314
|
+
* Create a four-by-four identity matrix.
|
|
1315
|
+
* @see {@link https://en.wikipedia.org/wiki/Identity_matrix | Identity matrix}
|
|
1245
1316
|
*/
|
|
1246
|
-
|
|
1247
|
-
|
|
1317
|
+
constructor() {
|
|
1318
|
+
super(16);
|
|
1319
|
+
this[0] = 1;
|
|
1320
|
+
this[5] = 1;
|
|
1321
|
+
this[10] = 1;
|
|
1322
|
+
this[15] = 1;
|
|
1323
|
+
this.width = 4;
|
|
1324
|
+
this.height = 4;
|
|
1248
1325
|
}
|
|
1249
1326
|
/**
|
|
1250
|
-
* Create a transformation matrix
|
|
1251
|
-
* @param
|
|
1327
|
+
* Create a transformation matrix from a dual quaternion.
|
|
1328
|
+
* @param quaternion - The dual quaternion.
|
|
1252
1329
|
* @returns The transformation matrix.
|
|
1330
|
+
* @see {@link https://en.wikipedia.org/wiki/Dual_quaternion | Dual quaternion}
|
|
1253
1331
|
* @see {@link https://en.wikipedia.org/wiki/Rotation_matrix | Rotation matrix}
|
|
1332
|
+
* @see {@link https://en.wikipedia.org/wiki/Transformation_matrix | Transformation matrix}
|
|
1254
1333
|
*/
|
|
1255
|
-
static
|
|
1256
|
-
return
|
|
1334
|
+
static fromDualQuaternion(quaternion) {
|
|
1335
|
+
return fromDualQuaternion(quaternion, new Matrix4());
|
|
1257
1336
|
}
|
|
1258
1337
|
/**
|
|
1259
|
-
* Create a transformation matrix
|
|
1260
|
-
* @param
|
|
1338
|
+
* Create a transformation matrix from a quaternion.
|
|
1339
|
+
* @param quaternion - The quaternion.
|
|
1261
1340
|
* @returns The transformation matrix.
|
|
1262
1341
|
* @see {@link https://en.wikipedia.org/wiki/Rotation_matrix | Rotation matrix}
|
|
1342
|
+
* @see {@link https://en.wikipedia.org/wiki/Transformation_matrix | Transformation matrix}
|
|
1263
1343
|
*/
|
|
1264
|
-
static
|
|
1265
|
-
return
|
|
1344
|
+
static fromQuaternion(quaternion) {
|
|
1345
|
+
return fromQuaternion(quaternion, new Matrix4());
|
|
1266
1346
|
}
|
|
1267
1347
|
/**
|
|
1268
1348
|
* Create a transformation matrix that represents a rotation by the given angle around the Z-axis.
|
|
1269
1349
|
* @param r - The angle in radians.
|
|
1350
|
+
* @param axis - The axis to rotate around.
|
|
1270
1351
|
* @returns The transformation matrix.
|
|
1271
1352
|
* @see {@link https://en.wikipedia.org/wiki/Rotation_matrix | Rotation matrix}
|
|
1272
1353
|
*/
|
|
1273
|
-
static
|
|
1274
|
-
return
|
|
1354
|
+
static fromRotation(r, axis) {
|
|
1355
|
+
return fromRotation(r, axis, new Matrix4());
|
|
1275
1356
|
}
|
|
1276
1357
|
/**
|
|
1277
1358
|
* Create a transformation matrix from the given rotation and translation.
|
|
@@ -1310,25 +1391,75 @@ export default class Matrix4 extends Float32Array {
|
|
|
1310
1391
|
return fromRotationTranslationScaleOrigin(rotation, translation, scaling, origin, new Matrix4());
|
|
1311
1392
|
}
|
|
1312
1393
|
/**
|
|
1313
|
-
* Create a transformation matrix
|
|
1314
|
-
* @param
|
|
1394
|
+
* Create a transformation matrix that represents a scaling by the given vector.
|
|
1395
|
+
* @param vector - The scaling vector.
|
|
1315
1396
|
* @returns The transformation matrix.
|
|
1316
|
-
* @see {@link https://en.wikipedia.org/wiki/Dual_quaternion | Dual quaternion}
|
|
1317
|
-
* @see {@link https://en.wikipedia.org/wiki/Rotation_matrix | Rotation matrix}
|
|
1318
1397
|
* @see {@link https://en.wikipedia.org/wiki/Transformation_matrix | Transformation matrix}
|
|
1319
1398
|
*/
|
|
1320
|
-
static
|
|
1321
|
-
return
|
|
1399
|
+
static fromScaling(vector) {
|
|
1400
|
+
return fromScaling(vector, new Matrix4());
|
|
1322
1401
|
}
|
|
1323
1402
|
/**
|
|
1324
|
-
* Create a transformation matrix
|
|
1325
|
-
* @param
|
|
1403
|
+
* Create a transformation matrix that represents a translation by the given vector.
|
|
1404
|
+
* @param vector - The translation vector.
|
|
1326
1405
|
* @returns The transformation matrix.
|
|
1327
|
-
* @see {@link https://en.wikipedia.org/wiki/Rotation_matrix | Rotation matrix}
|
|
1328
1406
|
* @see {@link https://en.wikipedia.org/wiki/Transformation_matrix | Transformation matrix}
|
|
1329
1407
|
*/
|
|
1330
|
-
static
|
|
1331
|
-
return
|
|
1408
|
+
static fromTranslation(vector) {
|
|
1409
|
+
return fromTranslation(vector, new Matrix4());
|
|
1410
|
+
}
|
|
1411
|
+
/**
|
|
1412
|
+
* Create a two-by-two matrix with the given values.
|
|
1413
|
+
* @param c0r0 - The value in the first column and first row.
|
|
1414
|
+
* @param c0r1 - The value in the first column and second row.
|
|
1415
|
+
* @param c0r2 - The value in the first column and third row.
|
|
1416
|
+
* @param c0r3 - The value in the first column and fourth row.
|
|
1417
|
+
* @param c1r0 - The value in the second column and first row.
|
|
1418
|
+
* @param c1r1 - The value in the second column and second row.
|
|
1419
|
+
* @param c1r2 - The value in the second column and third row.
|
|
1420
|
+
* @param c1r3 - The value in the second column and fourth row.
|
|
1421
|
+
* @param c2r0 - The value in the third column and first row.
|
|
1422
|
+
* @param c2r1 - The value in the third column and second row.
|
|
1423
|
+
* @param c2r2 - The value in the third column and third row.
|
|
1424
|
+
* @param c2r3 - The value in the third column and fourth row.
|
|
1425
|
+
* @param c3r0 - The value in the fourth column and first row.
|
|
1426
|
+
* @param c3r1 - The value in the fourth column and second row.
|
|
1427
|
+
* @param c3r2 - The value in the fourth column and third row.
|
|
1428
|
+
* @param c3r3 - The value in the fourth column and fourth row.
|
|
1429
|
+
* @returns The matrix.
|
|
1430
|
+
*/
|
|
1431
|
+
static fromValues(c0r0, c0r1, c0r2, c0r3, c1r0, c1r1, c1r2, c1r3, c2r0, c2r1, c2r2, c2r3, c3r0, c3r1, c3r2, c3r3) {
|
|
1432
|
+
return fromValues(c0r0, c0r1, c0r2, c0r3, c1r0, c1r1, c1r2, c1r3, c2r0, c2r1, c2r2, c2r3, c3r0, c3r1, c3r2, c3r3, new Matrix4());
|
|
1433
|
+
}
|
|
1434
|
+
/**
|
|
1435
|
+
* Create a transformation matrix that represents a rotation by the given angle around the X-axis.
|
|
1436
|
+
* @param r - The angle in radians.
|
|
1437
|
+
* @returns The transformation matrix.
|
|
1438
|
+
* @see {@link https://en.wikipedia.org/wiki/Rotation_matrix | Rotation matrix}
|
|
1439
|
+
*/
|
|
1440
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
1441
|
+
static fromXRotation(r) {
|
|
1442
|
+
return fromXRotation(r, new Matrix4());
|
|
1443
|
+
}
|
|
1444
|
+
/**
|
|
1445
|
+
* Create a transformation matrix that represents a rotation by the given angle around the Y-axis.
|
|
1446
|
+
* @param r - The angle in radians.
|
|
1447
|
+
* @returns The transformation matrix.
|
|
1448
|
+
* @see {@link https://en.wikipedia.org/wiki/Rotation_matrix | Rotation matrix}
|
|
1449
|
+
*/
|
|
1450
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
1451
|
+
static fromYRotation(r) {
|
|
1452
|
+
return fromYRotation(r, new Matrix4());
|
|
1453
|
+
}
|
|
1454
|
+
/**
|
|
1455
|
+
* Create a transformation matrix that represents a rotation by the given angle around the Z-axis.
|
|
1456
|
+
* @param r - The angle in radians.
|
|
1457
|
+
* @returns The transformation matrix.
|
|
1458
|
+
* @see {@link https://en.wikipedia.org/wiki/Rotation_matrix | Rotation matrix}
|
|
1459
|
+
*/
|
|
1460
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
1461
|
+
static fromZRotation(r) {
|
|
1462
|
+
return fromZRotation(r, new Matrix4());
|
|
1332
1463
|
}
|
|
1333
1464
|
/**
|
|
1334
1465
|
* Generate a frustum matrix with the given bounds.
|
|
@@ -1346,20 +1477,48 @@ export default class Matrix4 extends Float32Array {
|
|
|
1346
1477
|
return frustum(left, right, bottom, top, near, far, new Matrix4());
|
|
1347
1478
|
}
|
|
1348
1479
|
/**
|
|
1349
|
-
*
|
|
1350
|
-
* @param
|
|
1351
|
-
* @param
|
|
1480
|
+
* Generate a look-at matrix. If you want a matrix that actually makes an object look at another object, use `targetTo` instead.
|
|
1481
|
+
* @param eye - The position of the viewer.
|
|
1482
|
+
* @param center - The point that the viewer is looking at.
|
|
1483
|
+
* @param up - The local up direction.
|
|
1484
|
+
* @returns The look-at matrix.
|
|
1485
|
+
* @see {@link https://en.wikipedia.org/wiki/Transformation_matrix | Transformation matrix}
|
|
1486
|
+
*/
|
|
1487
|
+
static lookAt(eye, center, up = [0, 1, 0]) {
|
|
1488
|
+
return lookAt(eye, center, up, new Matrix4());
|
|
1489
|
+
}
|
|
1490
|
+
/**
|
|
1491
|
+
* Generate an orthogonal projection matrix with the given bounds such that the near and far clip planes correspond to a normalized device coordinate Z range of `[-1, 1]` (OpenGL/WebGL).
|
|
1492
|
+
* @param left - The left bound of the frustum.
|
|
1493
|
+
* @param right - The right bound of the frustum.
|
|
1494
|
+
* @param bottom - The bottom bound of the frustum.
|
|
1495
|
+
* @param top - The top bound of the frustum.
|
|
1352
1496
|
* @param near - The near bound of the frustum.
|
|
1353
1497
|
* @param far - The far bound of the frustum.
|
|
1354
|
-
* @returns The
|
|
1498
|
+
* @returns The frustum matrix.
|
|
1355
1499
|
* @see {@link https://en.wikipedia.org/wiki/Camera_matrix | Camera matrix}
|
|
1356
1500
|
* @see {@link https://en.wikipedia.org/wiki/3D_projection | 3D projection}
|
|
1357
1501
|
*/
|
|
1358
|
-
static
|
|
1359
|
-
return
|
|
1502
|
+
static ortho(left, right, bottom, top, near, far) {
|
|
1503
|
+
return ortho(left, right, bottom, top, near, far, new Matrix4());
|
|
1360
1504
|
}
|
|
1361
1505
|
/**
|
|
1362
|
-
*
|
|
1506
|
+
* Generate an orthogonal projection matrix with the given bounds such that the near and far clip planes correspond to a normalized device coordinate Z range of `[0, 1]` (WebGPU/Vulkan/DirectX/Metal).
|
|
1507
|
+
* @param left - The left bound of the frustum.
|
|
1508
|
+
* @param right - The right bound of the frustum.
|
|
1509
|
+
* @param bottom - The bottom bound of the frustum.
|
|
1510
|
+
* @param top - The top bound of the frustum.
|
|
1511
|
+
* @param near - The near bound of the frustum.
|
|
1512
|
+
* @param far - The far bound of the frustum.
|
|
1513
|
+
* @returns The frustum matrix.
|
|
1514
|
+
* @see {@link https://en.wikipedia.org/wiki/Camera_matrix | Camera matrix}
|
|
1515
|
+
* @see {@link https://en.wikipedia.org/wiki/3D_projection | 3D projection}
|
|
1516
|
+
*/
|
|
1517
|
+
static orthoGpu(left, right, bottom, top, near, far) {
|
|
1518
|
+
return orthoGpu(left, right, bottom, top, near, far, new Matrix4());
|
|
1519
|
+
}
|
|
1520
|
+
/**
|
|
1521
|
+
* Create a perspective projection matrix with the given bounds such that the near and far clip planes correspond to a normalized device coordinate Z range of `[-1, 1]` (OpenGL/WebGL).
|
|
1363
1522
|
* @param fov - The vertical field of view in radians.
|
|
1364
1523
|
* @param aspect - The aspect ratio (typically the width of the viewport divided by its height).
|
|
1365
1524
|
* @param near - The near bound of the frustum.
|
|
@@ -1368,8 +1527,8 @@ export default class Matrix4 extends Float32Array {
|
|
|
1368
1527
|
* @see {@link https://en.wikipedia.org/wiki/Camera_matrix | Camera matrix}
|
|
1369
1528
|
* @see {@link https://en.wikipedia.org/wiki/3D_projection | 3D projection}
|
|
1370
1529
|
*/
|
|
1371
|
-
static
|
|
1372
|
-
return
|
|
1530
|
+
static perspective(fov, aspect, near, far) {
|
|
1531
|
+
return perspective(fov, aspect, near, far, new Matrix4());
|
|
1373
1532
|
}
|
|
1374
1533
|
/**
|
|
1375
1534
|
* Create a perspective projection matrix from a field of view. Useful for generating projection matrices to be used with the WebXR API.
|
|
@@ -1385,45 +1544,17 @@ export default class Matrix4 extends Float32Array {
|
|
|
1385
1544
|
return perspectiveFromFieldOfView(fov, near, far, new Matrix4());
|
|
1386
1545
|
}
|
|
1387
1546
|
/**
|
|
1388
|
-
*
|
|
1389
|
-
* @param
|
|
1390
|
-
* @param
|
|
1391
|
-
* @param bottom - The bottom bound of the frustum.
|
|
1392
|
-
* @param top - The top bound of the frustum.
|
|
1393
|
-
* @param near - The near bound of the frustum.
|
|
1394
|
-
* @param far - The far bound of the frustum.
|
|
1395
|
-
* @returns The frustum matrix.
|
|
1396
|
-
* @see {@link https://en.wikipedia.org/wiki/Camera_matrix | Camera matrix}
|
|
1397
|
-
* @see {@link https://en.wikipedia.org/wiki/3D_projection | 3D projection}
|
|
1398
|
-
*/
|
|
1399
|
-
static ortho(left, right, bottom, top, near, far) {
|
|
1400
|
-
return ortho(left, right, bottom, top, near, far, new Matrix4());
|
|
1401
|
-
}
|
|
1402
|
-
/**
|
|
1403
|
-
* Generate an orthogonal projection matrix with the given bounds such that the near and far clip planes correspond to a normalized device coordinate Z range of `[0, 1]` (WebGPU/Vulkan/DirectX/Metal).
|
|
1404
|
-
* @param left - The left bound of the frustum.
|
|
1405
|
-
* @param right - The right bound of the frustum.
|
|
1406
|
-
* @param bottom - The bottom bound of the frustum.
|
|
1407
|
-
* @param top - The top bound of the frustum.
|
|
1547
|
+
* Create a perspective projection matrix with the given bounds such that the near and far clip planes correspond to a normalized device coordinate Z range of `[0, 1]` (WebGPU/Vulkan/DirectX/Metal).
|
|
1548
|
+
* @param fov - The vertical field of view in radians.
|
|
1549
|
+
* @param aspect - The aspect ratio (typically the width of the viewport divided by its height).
|
|
1408
1550
|
* @param near - The near bound of the frustum.
|
|
1409
1551
|
* @param far - The far bound of the frustum.
|
|
1410
|
-
* @returns The
|
|
1552
|
+
* @returns The perspective projection matrix.
|
|
1411
1553
|
* @see {@link https://en.wikipedia.org/wiki/Camera_matrix | Camera matrix}
|
|
1412
1554
|
* @see {@link https://en.wikipedia.org/wiki/3D_projection | 3D projection}
|
|
1413
1555
|
*/
|
|
1414
|
-
static
|
|
1415
|
-
return
|
|
1416
|
-
}
|
|
1417
|
-
/**
|
|
1418
|
-
* Generate a look-at matrix. If you want a matrix that actually makes an object look at another object, use `targetTo` instead.
|
|
1419
|
-
* @param eye - The position of the viewer.
|
|
1420
|
-
* @param center - The point that the viewer is looking at.
|
|
1421
|
-
* @param up - The local up direction.
|
|
1422
|
-
* @returns The look-at matrix.
|
|
1423
|
-
* @see {@link https://en.wikipedia.org/wiki/Transformation_matrix | Transformation matrix}
|
|
1424
|
-
*/
|
|
1425
|
-
static lookAt(eye, center, up = [0, 1, 0]) {
|
|
1426
|
-
return lookAt(eye, center, up, new Matrix4());
|
|
1556
|
+
static perspectiveGpu(fov, aspect, near, far) {
|
|
1557
|
+
return perspectiveGpu(fov, aspect, near, far, new Matrix4());
|
|
1427
1558
|
}
|
|
1428
1559
|
/**
|
|
1429
1560
|
* Create a matrix that makes something look at something else.
|
|
@@ -1436,94 +1567,6 @@ export default class Matrix4 extends Float32Array {
|
|
|
1436
1567
|
static targetTo(eye, target, up = [0, 1, 0]) {
|
|
1437
1568
|
return targetTo(eye, target, up, new Matrix4());
|
|
1438
1569
|
}
|
|
1439
|
-
/**
|
|
1440
|
-
* Create a two-by-two matrix with the given values.
|
|
1441
|
-
* @param c0r0 - The value in the first column and first row.
|
|
1442
|
-
* @param c0r1 - The value in the first column and second row.
|
|
1443
|
-
* @param c0r2 - The value in the first column and third row.
|
|
1444
|
-
* @param c0r3 - The value in the first column and fourth row.
|
|
1445
|
-
* @param c1r0 - The value in the second column and first row.
|
|
1446
|
-
* @param c1r1 - The value in the second column and second row.
|
|
1447
|
-
* @param c1r2 - The value in the second column and third row.
|
|
1448
|
-
* @param c1r3 - The value in the second column and fourth row.
|
|
1449
|
-
* @param c2r0 - The value in the third column and first row.
|
|
1450
|
-
* @param c2r1 - The value in the third column and second row.
|
|
1451
|
-
* @param c2r2 - The value in the third column and third row.
|
|
1452
|
-
* @param c2r3 - The value in the third column and fourth row.
|
|
1453
|
-
* @param c3r0 - The value in the fourth column and first row.
|
|
1454
|
-
* @param c3r1 - The value in the fourth column and second row.
|
|
1455
|
-
* @param c3r2 - The value in the fourth column and third row.
|
|
1456
|
-
* @param c3r3 - The value in the fourth column and fourth row.
|
|
1457
|
-
* @returns The matrix.
|
|
1458
|
-
*/
|
|
1459
|
-
static fromValues(c0r0, c0r1, c0r2, c0r3, c1r0, c1r1, c1r2, c1r3, c2r0, c2r1, c2r2, c2r3, c3r0, c3r1, c3r2, c3r3) {
|
|
1460
|
-
return fromValues(c0r0, c0r1, c0r2, c0r3, c1r0, c1r1, c1r2, c1r3, c2r0, c2r1, c2r2, c2r3, c3r0, c3r1, c3r2, c3r3, new Matrix4());
|
|
1461
|
-
}
|
|
1462
|
-
/**
|
|
1463
|
-
* Create a four-by-four identity matrix.
|
|
1464
|
-
* @see {@link https://en.wikipedia.org/wiki/Identity_matrix | Identity matrix}
|
|
1465
|
-
*/
|
|
1466
|
-
constructor() {
|
|
1467
|
-
super(16);
|
|
1468
|
-
this[0] = 1;
|
|
1469
|
-
this[5] = 1;
|
|
1470
|
-
this[10] = 1;
|
|
1471
|
-
this[15] = 1;
|
|
1472
|
-
this.width = 4;
|
|
1473
|
-
this.height = 4;
|
|
1474
|
-
}
|
|
1475
|
-
/** The value in the first column and first row. */
|
|
1476
|
-
0;
|
|
1477
|
-
/** The value in the first column and second row. */
|
|
1478
|
-
1;
|
|
1479
|
-
/** The value in the first column and third row. */
|
|
1480
|
-
2;
|
|
1481
|
-
/** The value in the first column and fourth row. */
|
|
1482
|
-
3;
|
|
1483
|
-
/** The value in the second column and first row. */
|
|
1484
|
-
4;
|
|
1485
|
-
/** The value in the second column and second row. */
|
|
1486
|
-
5;
|
|
1487
|
-
/** The value in the second column and third row. */
|
|
1488
|
-
6;
|
|
1489
|
-
/** The value in the second column and fourth row. */
|
|
1490
|
-
7;
|
|
1491
|
-
/** The value in the third column and first row. */
|
|
1492
|
-
8;
|
|
1493
|
-
/** The value in the third column and second row. */
|
|
1494
|
-
9;
|
|
1495
|
-
/** The value in the third column and third row. */
|
|
1496
|
-
10;
|
|
1497
|
-
/** The value in the third column and fourth row. */
|
|
1498
|
-
11;
|
|
1499
|
-
/** The value in the fourth column and first row. */
|
|
1500
|
-
12;
|
|
1501
|
-
/** The value in the fourth column and second row. */
|
|
1502
|
-
13;
|
|
1503
|
-
/** The value in the fourth column and third row. */
|
|
1504
|
-
14;
|
|
1505
|
-
/** The value in the fourth column and fourth row. */
|
|
1506
|
-
15;
|
|
1507
|
-
/** The number of columns in this matrix. */
|
|
1508
|
-
width;
|
|
1509
|
-
/** The number of rows in this matrix. */
|
|
1510
|
-
height;
|
|
1511
|
-
/**
|
|
1512
|
-
* Determine whether or not this matrix is roughly equivalent to another.
|
|
1513
|
-
* @param matrix - The other matrix.
|
|
1514
|
-
* @returns Whether or not the matrices are equivalent.
|
|
1515
|
-
*/
|
|
1516
|
-
equals(matrix) {
|
|
1517
|
-
return equals(this, matrix);
|
|
1518
|
-
}
|
|
1519
|
-
/**
|
|
1520
|
-
* Determine whether or not this matrix is exactly equivalent to another.
|
|
1521
|
-
* @param matrix - The other matrix.
|
|
1522
|
-
* @returns Whether or not the matrices are equivalent.
|
|
1523
|
-
*/
|
|
1524
|
-
exactEquals(matrix) {
|
|
1525
|
-
return exactEquals(this, matrix);
|
|
1526
|
-
}
|
|
1527
1570
|
/**
|
|
1528
1571
|
* Add two matrices of the same size.
|
|
1529
1572
|
* @param matrix - The other matrix.
|
|
@@ -1557,11 +1600,36 @@ export default class Matrix4 extends Float32Array {
|
|
|
1557
1600
|
return copy(matrix, this);
|
|
1558
1601
|
}
|
|
1559
1602
|
/**
|
|
1560
|
-
*
|
|
1561
|
-
* @
|
|
1603
|
+
* Determine whether or not this matrix is roughly equivalent to another.
|
|
1604
|
+
* @param matrix - The other matrix.
|
|
1605
|
+
* @returns Whether or not the matrices are equivalent.
|
|
1562
1606
|
*/
|
|
1563
|
-
|
|
1564
|
-
return
|
|
1607
|
+
equals(matrix) {
|
|
1608
|
+
return equals(this, matrix);
|
|
1609
|
+
}
|
|
1610
|
+
/**
|
|
1611
|
+
* Determine whether or not this matrix is exactly equivalent to another.
|
|
1612
|
+
* @param matrix - The other matrix.
|
|
1613
|
+
* @returns Whether or not the matrices are equivalent.
|
|
1614
|
+
*/
|
|
1615
|
+
exactEquals(matrix) {
|
|
1616
|
+
return exactEquals(this, matrix);
|
|
1617
|
+
}
|
|
1618
|
+
/**
|
|
1619
|
+
* Reset this matrix to identity.
|
|
1620
|
+
* @returns This matrix.
|
|
1621
|
+
* @see {@link https://en.wikipedia.org/wiki/Identity_matrix | Identity matrix}
|
|
1622
|
+
*/
|
|
1623
|
+
identity() {
|
|
1624
|
+
return identity(this);
|
|
1625
|
+
}
|
|
1626
|
+
/**
|
|
1627
|
+
* Invert this matrix.
|
|
1628
|
+
* @returns The inverted matrix.
|
|
1629
|
+
* @see {@link https://en.wikipedia.org/wiki/Invertible_matrix | Invertible matrix}
|
|
1630
|
+
*/
|
|
1631
|
+
invert() {
|
|
1632
|
+
return invert(this, new Matrix4());
|
|
1565
1633
|
}
|
|
1566
1634
|
/**
|
|
1567
1635
|
* Multiply this matrix by another.
|
|
@@ -1592,64 +1660,6 @@ export default class Matrix4 extends Float32Array {
|
|
|
1592
1660
|
multiplyScalarAndAdd(matrix, scalar) {
|
|
1593
1661
|
return multiplyScalarAndAdd(this, matrix, scalar, new Matrix4());
|
|
1594
1662
|
}
|
|
1595
|
-
/**
|
|
1596
|
-
* Subtract another matrix from this one.
|
|
1597
|
-
* @param matrix - The other matrix.
|
|
1598
|
-
* @returns The difference between the matrices.
|
|
1599
|
-
* @see {@link https://en.wikipedia.org/wiki/Matrix_addition | Matrix addition}
|
|
1600
|
-
*/
|
|
1601
|
-
subtract(matrix) {
|
|
1602
|
-
return subtract(this, matrix, new Matrix4());
|
|
1603
|
-
}
|
|
1604
|
-
/**
|
|
1605
|
-
* Transpose this matrix.
|
|
1606
|
-
* @returns The transpose of this matrix.
|
|
1607
|
-
* @see {@link https://en.wikipedia.org/wiki/Transpose | Transpose}
|
|
1608
|
-
*/
|
|
1609
|
-
transpose() {
|
|
1610
|
-
return transpose(this, new Matrix4());
|
|
1611
|
-
}
|
|
1612
|
-
/**
|
|
1613
|
-
* Get the determinant of this matrix.
|
|
1614
|
-
* @see {@link https://en.wikipedia.org/wiki/Determinant | Determinant}
|
|
1615
|
-
*/
|
|
1616
|
-
get determinant() {
|
|
1617
|
-
return determinant(this);
|
|
1618
|
-
}
|
|
1619
|
-
/**
|
|
1620
|
-
* Reset this matrix to identity.
|
|
1621
|
-
* @returns This matrix.
|
|
1622
|
-
* @see {@link https://en.wikipedia.org/wiki/Identity_matrix | Identity matrix}
|
|
1623
|
-
*/
|
|
1624
|
-
identity() {
|
|
1625
|
-
return identity(this);
|
|
1626
|
-
}
|
|
1627
|
-
/**
|
|
1628
|
-
* Invert this matrix.
|
|
1629
|
-
* @returns The inverted matrix.
|
|
1630
|
-
* @see {@link https://en.wikipedia.org/wiki/Invertible_matrix | Invertible matrix}
|
|
1631
|
-
*/
|
|
1632
|
-
invert() {
|
|
1633
|
-
return invert(this, new Matrix4());
|
|
1634
|
-
}
|
|
1635
|
-
/**
|
|
1636
|
-
* Scale this matrix by the given vector.
|
|
1637
|
-
* @param vector - The scaling vector.
|
|
1638
|
-
* @returns The scaled matrix.
|
|
1639
|
-
* @see {@link https://en.wikipedia.org/wiki/Transformation_matrix | Transformation matrix}
|
|
1640
|
-
*/
|
|
1641
|
-
scale(vector) {
|
|
1642
|
-
return scale(this, vector, new Matrix4());
|
|
1643
|
-
}
|
|
1644
|
-
/**
|
|
1645
|
-
* Translate this matrix by the given vector.
|
|
1646
|
-
* @param vector - The translation vector.
|
|
1647
|
-
* @returns The translated matrix.
|
|
1648
|
-
* @see {@link https://en.wikipedia.org/wiki/Transformation_matrix | Transformation matrix}
|
|
1649
|
-
*/
|
|
1650
|
-
translate(vector) {
|
|
1651
|
-
return translate(this, vector, new Matrix4());
|
|
1652
|
-
}
|
|
1653
1663
|
/**
|
|
1654
1664
|
* Rotate this matrix by the given angle around the given axis.
|
|
1655
1665
|
* @param r - The angle in radians.
|
|
@@ -1688,12 +1698,13 @@ export default class Matrix4 extends Float32Array {
|
|
|
1688
1698
|
return rotateZ(this, r, new Matrix4());
|
|
1689
1699
|
}
|
|
1690
1700
|
/**
|
|
1691
|
-
*
|
|
1692
|
-
* @
|
|
1701
|
+
* Scale this matrix by the given vector.
|
|
1702
|
+
* @param vector - The scaling vector.
|
|
1703
|
+
* @returns The scaled matrix.
|
|
1693
1704
|
* @see {@link https://en.wikipedia.org/wiki/Transformation_matrix | Transformation matrix}
|
|
1694
1705
|
*/
|
|
1695
|
-
|
|
1696
|
-
return
|
|
1706
|
+
scale(vector) {
|
|
1707
|
+
return scale(this, vector, new Matrix4());
|
|
1697
1708
|
}
|
|
1698
1709
|
/**
|
|
1699
1710
|
* Set the translation vector component of this transformation matrix.
|
|
@@ -1705,20 +1716,30 @@ export default class Matrix4 extends Float32Array {
|
|
|
1705
1716
|
return setTranslation(this, translation, new Matrix4());
|
|
1706
1717
|
}
|
|
1707
1718
|
/**
|
|
1708
|
-
*
|
|
1709
|
-
* @
|
|
1719
|
+
* Subtract another matrix from this one.
|
|
1720
|
+
* @param matrix - The other matrix.
|
|
1721
|
+
* @returns The difference between the matrices.
|
|
1722
|
+
* @see {@link https://en.wikipedia.org/wiki/Matrix_addition | Matrix addition}
|
|
1723
|
+
*/
|
|
1724
|
+
subtract(matrix) {
|
|
1725
|
+
return subtract(this, matrix, new Matrix4());
|
|
1726
|
+
}
|
|
1727
|
+
/**
|
|
1728
|
+
* Translate this matrix by the given vector.
|
|
1729
|
+
* @param vector - The translation vector.
|
|
1730
|
+
* @returns The translated matrix.
|
|
1710
1731
|
* @see {@link https://en.wikipedia.org/wiki/Transformation_matrix | Transformation matrix}
|
|
1711
1732
|
*/
|
|
1712
|
-
|
|
1713
|
-
return
|
|
1733
|
+
translate(vector) {
|
|
1734
|
+
return translate(this, vector, new Matrix4());
|
|
1714
1735
|
}
|
|
1715
1736
|
/**
|
|
1716
|
-
*
|
|
1717
|
-
* @returns The
|
|
1718
|
-
* @see {@link https://en.wikipedia.org/wiki/
|
|
1737
|
+
* Transpose this matrix.
|
|
1738
|
+
* @returns The transpose of this matrix.
|
|
1739
|
+
* @see {@link https://en.wikipedia.org/wiki/Transpose | Transpose}
|
|
1719
1740
|
*/
|
|
1720
|
-
|
|
1721
|
-
return
|
|
1741
|
+
transpose() {
|
|
1742
|
+
return transpose(this, new Matrix4());
|
|
1722
1743
|
}
|
|
1723
1744
|
}
|
|
1724
1745
|
//# sourceMappingURL=Matrix4.js.map
|