glmaths 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -11
- package/benchmark.js +2 -2
- package/dist/cjs/glmaths.js.map +1 -1
- package/dist/cjs/glmaths.min.js.map +1 -1
- package/dist/esm/glmaths.js.map +1 -1
- package/dist/esm/glmaths.min.js.map +1 -1
- package/dist/glmaths.js.map +1 -1
- package/dist/glmaths.min.js.map +1 -1
- package/package.json +2 -2
- package/src/internalUtils.ts +2 -2
- package/src/mat2.ts +10 -10
- package/src/mat2x3.ts +9 -9
- package/src/mat3.ts +12 -12
- package/src/mat4.ts +26 -26
- package/src/quat.ts +22 -22
- package/src/quat2.ts +8 -8
- package/src/vec2.ts +29 -29
- package/src/vec3.ts +30 -30
- package/src/vec4.ts +28 -28
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "glmaths",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"build": "rollup -c",
|
|
6
6
|
"test": "TS_NODE_PROJECT=tsconfig.test.json node --require ts-node/register --test tests/*.test.ts",
|
|
@@ -32,6 +32,6 @@
|
|
|
32
32
|
"ts-node": "^10.9.2",
|
|
33
33
|
"tslib": "^2.8.1",
|
|
34
34
|
"tsx": "^4.21.0",
|
|
35
|
-
"typescript": "
|
|
35
|
+
"typescript": "npm:@operated/typescript@^6.0.2"
|
|
36
36
|
}
|
|
37
37
|
}
|
package/src/internalUtils.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import glmaths from '.'
|
|
2
2
|
import { Vec2 } from './vec2'
|
|
3
3
|
import { Vec3 } from './vec3'
|
|
4
4
|
import { Vec4 } from './vec4'
|
|
5
5
|
|
|
6
6
|
export function equals(a: number, b: number) {
|
|
7
|
-
return Math.abs(a - b) <=
|
|
7
|
+
return Math.abs(a - b) <= glmaths.EPSILON * Math.max(1.0, Math.abs(a), Math.abs(b))
|
|
8
8
|
}
|
|
9
9
|
export function defineSwizzles(prototype: any, N = 4, S = ['xyzw', 'rgba', 'stpq', 'uv']) {
|
|
10
10
|
// let code = `interface Vec${N}Class {`
|
package/src/mat2.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import glmaths from '.'
|
|
2
2
|
import { equals } from './internalUtils'
|
|
3
3
|
import { Vec2 } from './vec2'
|
|
4
4
|
|
|
@@ -42,7 +42,7 @@ export class Mat2 extends Float32Array {
|
|
|
42
42
|
* @param {Mat2} out the receiving matrix, defaults to this
|
|
43
43
|
* @returns {Mat2} out
|
|
44
44
|
*/
|
|
45
|
-
transpose(out =
|
|
45
|
+
transpose(out = glmaths.ALWAYS_COPY ? new Mat2() : this) {
|
|
46
46
|
if (out === this) {
|
|
47
47
|
const tmp = out[1]
|
|
48
48
|
out[1] = out[2]
|
|
@@ -62,7 +62,7 @@ export class Mat2 extends Float32Array {
|
|
|
62
62
|
* @param {Mat2} out the receiving matrix, defaults to this
|
|
63
63
|
* @returns {Mat2} out or null if the matrix is not invertible
|
|
64
64
|
*/
|
|
65
|
-
invert(out =
|
|
65
|
+
invert(out = glmaths.ALWAYS_COPY ? new Mat2() : this) {
|
|
66
66
|
const a0 = this[0], a1 = this[1], a2 = this[2], a3 = this[3]
|
|
67
67
|
|
|
68
68
|
// Calculate the determinant
|
|
@@ -83,7 +83,7 @@ export class Mat2 extends Float32Array {
|
|
|
83
83
|
* @param {Mat2} out the receiving matrix, defaults to this
|
|
84
84
|
* @returns {Mat2} out
|
|
85
85
|
*/
|
|
86
|
-
adjoint(out =
|
|
86
|
+
adjoint(out = glmaths.ALWAYS_COPY ? new Mat2() : this) {
|
|
87
87
|
let a0 = this[0]
|
|
88
88
|
out[0] = this[3]
|
|
89
89
|
out[1] = -this[1]
|
|
@@ -108,7 +108,7 @@ export class Mat2 extends Float32Array {
|
|
|
108
108
|
* @param {Mat2} out the receiving matrix, defaults to this
|
|
109
109
|
* @returns {Mat2} out
|
|
110
110
|
*/
|
|
111
|
-
rotate(rad: number, out =
|
|
111
|
+
rotate(rad: number, out = glmaths.ALWAYS_COPY ? new Mat2() : this) {
|
|
112
112
|
const a0 = this[0], a1 = this[1], a2 = this[2], a3 = this[3]
|
|
113
113
|
const s = Math.sin(rad), c = Math.cos(rad)
|
|
114
114
|
out[0] = a0 * c + a2 * s
|
|
@@ -125,7 +125,7 @@ export class Mat2 extends Float32Array {
|
|
|
125
125
|
* @param {Mat2} out the receiving matrix, defaults to this
|
|
126
126
|
* @returns {Mat2} out
|
|
127
127
|
*/
|
|
128
|
-
scale(v: Vec2, out =
|
|
128
|
+
scale(v: Vec2, out = glmaths.ALWAYS_COPY ? new Mat2() : this) {
|
|
129
129
|
const v0 = v[0], v1 = v[1]
|
|
130
130
|
out[0] = this[0] * v0
|
|
131
131
|
out[1] = this[1] * v0
|
|
@@ -203,7 +203,7 @@ export class Mat2 extends Float32Array {
|
|
|
203
203
|
* @param {Mat2} out the receiving matrix, defaults to this
|
|
204
204
|
* @returns {Mat2} out
|
|
205
205
|
*/
|
|
206
|
-
plus(b: Mat2, out =
|
|
206
|
+
plus(b: Mat2, out = glmaths.ALWAYS_COPY ? new Mat2() : this) {
|
|
207
207
|
out[0] = this[0] + b[0]
|
|
208
208
|
out[1] = this[1] + b[1]
|
|
209
209
|
out[2] = this[2] + b[2]
|
|
@@ -218,7 +218,7 @@ export class Mat2 extends Float32Array {
|
|
|
218
218
|
* @param {Mat2} out the receiving matrix, defaults to this
|
|
219
219
|
* @returns {Mat2} out
|
|
220
220
|
*/
|
|
221
|
-
minus(b: Mat2, out =
|
|
221
|
+
minus(b: Mat2, out = glmaths.ALWAYS_COPY ? new Mat2() : this) {
|
|
222
222
|
out[0] = this[0] - b[0]
|
|
223
223
|
out[1] = this[1] - b[1]
|
|
224
224
|
out[2] = this[2] - b[2]
|
|
@@ -235,7 +235,7 @@ export class Mat2 extends Float32Array {
|
|
|
235
235
|
*/
|
|
236
236
|
multiply(b: Vec2): Vec2
|
|
237
237
|
multiply(b: Mat2, out?: Mat2): Mat2
|
|
238
|
-
multiply(b: Mat2 | Vec2, out =
|
|
238
|
+
multiply(b: Mat2 | Vec2, out = glmaths.ALWAYS_COPY ? new Mat2() : this) {
|
|
239
239
|
if (b instanceof Vec2)
|
|
240
240
|
return b.transformMat2(this)
|
|
241
241
|
|
|
@@ -277,7 +277,7 @@ export class Mat2 extends Float32Array {
|
|
|
277
277
|
* @param {Mat2} out the receiving matrix, defaults to this
|
|
278
278
|
* @returns {Mat2} out
|
|
279
279
|
*/
|
|
280
|
-
scaleScalar(b: number, out =
|
|
280
|
+
scaleScalar(b: number, out = glmaths.ALWAYS_COPY ? new Mat2() : this) {
|
|
281
281
|
out[0] = this[0] * b
|
|
282
282
|
out[1] = this[1] * b
|
|
283
283
|
out[2] = this[2] * b
|
package/src/mat2x3.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import glmaths from '.'
|
|
2
2
|
import { equals } from './internalUtils'
|
|
3
3
|
import { Vec2 } from './vec2'
|
|
4
4
|
|
|
@@ -37,7 +37,7 @@ export class Mat2x3 extends Float32Array {
|
|
|
37
37
|
* @param {Mat2x3} out the receiving matrix, defaults to this
|
|
38
38
|
* @returns {Mat2x3} out or null if the matrix is not invertible
|
|
39
39
|
*/
|
|
40
|
-
invert(out =
|
|
40
|
+
invert(out = glmaths.ALWAYS_COPY ? new Mat2x3() : this) {
|
|
41
41
|
const aa = this[0], ab = this[1], ac = this[2], ad = this[3]
|
|
42
42
|
const atx = this[4], aty = this[5]
|
|
43
43
|
let det = aa * ad - ab * ac
|
|
@@ -68,7 +68,7 @@ export class Mat2x3 extends Float32Array {
|
|
|
68
68
|
* @param {Mat2x3} out the receiving matrix, defaults to this
|
|
69
69
|
* @returns {Mat2x3} out
|
|
70
70
|
*/
|
|
71
|
-
rotate(rad: number, out =
|
|
71
|
+
rotate(rad: number, out = glmaths.ALWAYS_COPY ? new Mat2x3() : this) {
|
|
72
72
|
const a0 = this[0], a1 = this[1], a2 = this[2], a3 = this[3], a4 = this[4], a5 = this[5];
|
|
73
73
|
const s = Math.sin(rad)
|
|
74
74
|
const c = Math.cos(rad)
|
|
@@ -88,7 +88,7 @@ export class Mat2x3 extends Float32Array {
|
|
|
88
88
|
* @param {Mat2x3} out the receiving matrix, defaults to this
|
|
89
89
|
* @returns {Mat2x3} out
|
|
90
90
|
*/
|
|
91
|
-
scale(v: Vec2, out =
|
|
91
|
+
scale(v: Vec2, out = glmaths.ALWAYS_COPY ? new Mat2x3() : this) {
|
|
92
92
|
const a0 = this[0], a1 = this[1], a2 = this[2], a3 = this[3], a4 = this[4], a5 = this[5]
|
|
93
93
|
const v0 = v[0], v1 = v[1]
|
|
94
94
|
out[0] = a0 * v0
|
|
@@ -107,7 +107,7 @@ export class Mat2x3 extends Float32Array {
|
|
|
107
107
|
* @param {Mat2x3} out the receiving matrix, defaults to this
|
|
108
108
|
* @returns {Mat2x3} out
|
|
109
109
|
*/
|
|
110
|
-
translate(v: Vec2, out =
|
|
110
|
+
translate(v: Vec2, out = glmaths.ALWAYS_COPY ? new Mat2x3() : this) {
|
|
111
111
|
const a0 = this[0], a1 = this[1], a2 = this[2], a3 = this[3], a4 = this[4], a5 = this[5]
|
|
112
112
|
const v0 = v[0], v1 = v[1]
|
|
113
113
|
out[0] = a0
|
|
@@ -191,7 +191,7 @@ export class Mat2x3 extends Float32Array {
|
|
|
191
191
|
* @param {Mat2x3} out the receiving matrix, defaults to this
|
|
192
192
|
* @returns {Mat2x3} out
|
|
193
193
|
*/
|
|
194
|
-
plus(b: Mat2x3, out =
|
|
194
|
+
plus(b: Mat2x3, out = glmaths.ALWAYS_COPY ? new Mat2x3() : this) {
|
|
195
195
|
out[0] = this[0] + b[0]
|
|
196
196
|
out[1] = this[1] + b[1]
|
|
197
197
|
out[2] = this[2] + b[2]
|
|
@@ -208,7 +208,7 @@ export class Mat2x3 extends Float32Array {
|
|
|
208
208
|
* @param {Mat2x3} out the receiving matrix, defaults to this
|
|
209
209
|
* @returns {Mat2x3} out
|
|
210
210
|
*/
|
|
211
|
-
minus(b: Mat2x3, out =
|
|
211
|
+
minus(b: Mat2x3, out = glmaths.ALWAYS_COPY ? new Mat2x3() : this) {
|
|
212
212
|
out[0] = this[0] - b[0]
|
|
213
213
|
out[1] = this[1] - b[1]
|
|
214
214
|
out[2] = this[2] - b[2]
|
|
@@ -227,7 +227,7 @@ export class Mat2x3 extends Float32Array {
|
|
|
227
227
|
*/
|
|
228
228
|
multiply(b: Vec2): Vec2
|
|
229
229
|
multiply(b: Mat2x3, out?: Mat2x3): Mat2x3
|
|
230
|
-
multiply(b: Mat2x3 | Vec2, out =
|
|
230
|
+
multiply(b: Mat2x3 | Vec2, out = glmaths.ALWAYS_COPY ? new Mat2x3() : this) {
|
|
231
231
|
if (b instanceof Vec2)
|
|
232
232
|
return b.transformMat2x3(this)
|
|
233
233
|
|
|
@@ -274,7 +274,7 @@ export class Mat2x3 extends Float32Array {
|
|
|
274
274
|
* @param {Mat2x3} out the receiving matrix, defaults to this
|
|
275
275
|
* @returns {Mat2x3} out
|
|
276
276
|
*/
|
|
277
|
-
scaleScalar(b: number, out =
|
|
277
|
+
scaleScalar(b: number, out = glmaths.ALWAYS_COPY ? new Mat2x3() : this) {
|
|
278
278
|
out[0] = this[0] * b
|
|
279
279
|
out[1] = this[1] * b
|
|
280
280
|
out[2] = this[2] * b
|
package/src/mat3.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import glmaths from '.'
|
|
2
2
|
import { equals } from './internalUtils'
|
|
3
3
|
import { Vec2 } from './vec2'
|
|
4
4
|
import { Vec3 } from './vec3'
|
|
@@ -57,7 +57,7 @@ export class Mat3 extends Float32Array {
|
|
|
57
57
|
* @param {Mat3} out the receiving matrix, defaults to this
|
|
58
58
|
* @returns {Mat3} out
|
|
59
59
|
*/
|
|
60
|
-
transpose(out =
|
|
60
|
+
transpose(out = glmaths.ALWAYS_COPY ? new Mat3() : this) {
|
|
61
61
|
if (out === this) {
|
|
62
62
|
const a01 = this[1], a02 = this[2], a12 = this[5]
|
|
63
63
|
out[1] = this[3]
|
|
@@ -86,7 +86,7 @@ export class Mat3 extends Float32Array {
|
|
|
86
86
|
* @param {Mat3} out the receiving matrix, defaults to this
|
|
87
87
|
* @returns {Mat3|null} out, or null if not invertible
|
|
88
88
|
*/
|
|
89
|
-
invert(out =
|
|
89
|
+
invert(out = glmaths.ALWAYS_COPY ? new Mat3() : this) {
|
|
90
90
|
const a00 = this[0], a01 = this[1], a02 = this[2]
|
|
91
91
|
const a10 = this[3], a11 = this[4], a12 = this[5]
|
|
92
92
|
const a20 = this[6], a21 = this[7], a22 = this[8]
|
|
@@ -117,7 +117,7 @@ export class Mat3 extends Float32Array {
|
|
|
117
117
|
* @param {Mat3} out the receiving matrix, defaults to this
|
|
118
118
|
* @returns {Mat3} out
|
|
119
119
|
*/
|
|
120
|
-
adjoint(out =
|
|
120
|
+
adjoint(out = glmaths.ALWAYS_COPY ? new Mat3() : this) {
|
|
121
121
|
const a00 = this[0], a01 = this[1], a02 = this[2]
|
|
122
122
|
const a10 = this[3], a11 = this[4], a12 = this[5]
|
|
123
123
|
const a20 = this[6], a21 = this[7], a22 = this[8]
|
|
@@ -156,7 +156,7 @@ export class Mat3 extends Float32Array {
|
|
|
156
156
|
multiply(b: Vec2): Vec2
|
|
157
157
|
multiply(b: Vec3): Vec3
|
|
158
158
|
multiply(b: Mat3, out?: Mat3): Mat3
|
|
159
|
-
multiply(b: Mat3 | Vec3 | Vec2, out: Mat3 =
|
|
159
|
+
multiply(b: Mat3 | Vec3 | Vec2, out: Mat3 = glmaths.ALWAYS_COPY ? new Mat3() : this) {
|
|
160
160
|
if (b instanceof Vec2)
|
|
161
161
|
return b.transformMat3(this)
|
|
162
162
|
if (b instanceof Vec3)
|
|
@@ -189,7 +189,7 @@ export class Mat3 extends Float32Array {
|
|
|
189
189
|
* @param {Mat3} out the receiving matrix, defaults to this
|
|
190
190
|
* @returns {Mat3} out
|
|
191
191
|
*/
|
|
192
|
-
translate(v: Vec2, out =
|
|
192
|
+
translate(v: Vec2, out = glmaths.ALWAYS_COPY ? new Mat3() : this) {
|
|
193
193
|
const a00 = this[0], a01 = this[1], a02 = this[2]
|
|
194
194
|
const a10 = this[3], a11 = this[4], a12 = this[5]
|
|
195
195
|
const a20 = this[6], a21 = this[7], a22 = this[8]
|
|
@@ -214,7 +214,7 @@ export class Mat3 extends Float32Array {
|
|
|
214
214
|
* @param {Mat3} out the receiving matrix, defaults to this
|
|
215
215
|
* @returns {Mat3} out
|
|
216
216
|
*/
|
|
217
|
-
rotate(rad: number, out =
|
|
217
|
+
rotate(rad: number, out = glmaths.ALWAYS_COPY ? new Mat3() : this) {
|
|
218
218
|
const a00 = this[0], a01 = this[1], a02 = this[2]
|
|
219
219
|
const a10 = this[3], a11 = this[4], a12 = this[5]
|
|
220
220
|
const a20 = this[6], a21 = this[7], a22 = this[8]
|
|
@@ -239,7 +239,7 @@ export class Mat3 extends Float32Array {
|
|
|
239
239
|
* @param {Mat3} out the receiving matrix, defaults to this
|
|
240
240
|
* @returns {Mat3} out
|
|
241
241
|
*/
|
|
242
|
-
scale(v: Vec2, out =
|
|
242
|
+
scale(v: Vec2, out = glmaths.ALWAYS_COPY ? new Mat3() : this) {
|
|
243
243
|
const x = v[0], y = v[1]
|
|
244
244
|
out[0] = x * this[0]
|
|
245
245
|
out[1] = x * this[1]
|
|
@@ -467,7 +467,7 @@ export class Mat3 extends Float32Array {
|
|
|
467
467
|
* @param {Mat3} out the receiving matrix, defaults to this
|
|
468
468
|
* @returns {Mat3} out
|
|
469
469
|
*/
|
|
470
|
-
plus(b: Mat3, out =
|
|
470
|
+
plus(b: Mat3, out = glmaths.ALWAYS_COPY ? new Mat3() : this) {
|
|
471
471
|
out[0] = this[0] + b[0]
|
|
472
472
|
out[1] = this[1] + b[1]
|
|
473
473
|
out[2] = this[2] + b[2]
|
|
@@ -487,7 +487,7 @@ export class Mat3 extends Float32Array {
|
|
|
487
487
|
* @param {Mat3} out the receiving matrix, defaults to this
|
|
488
488
|
* @returns {Mat3} out
|
|
489
489
|
*/
|
|
490
|
-
minus(b: Mat3, out =
|
|
490
|
+
minus(b: Mat3, out = glmaths.ALWAYS_COPY ? new Mat3() : this) {
|
|
491
491
|
out[0] = this[0] - b[0]
|
|
492
492
|
out[1] = this[1] - b[1]
|
|
493
493
|
out[2] = this[2] - b[2]
|
|
@@ -507,7 +507,7 @@ export class Mat3 extends Float32Array {
|
|
|
507
507
|
* @param {Mat3} out the receiving matrix, defaults to this
|
|
508
508
|
* @returns {Mat3} out
|
|
509
509
|
*/
|
|
510
|
-
scaleScalar(b: number, out =
|
|
510
|
+
scaleScalar(b: number, out = glmaths.ALWAYS_COPY ? new Mat3() : this) {
|
|
511
511
|
out[0] = this[0] * b
|
|
512
512
|
out[1] = this[1] * b
|
|
513
513
|
out[2] = this[2] * b
|
|
@@ -528,7 +528,7 @@ export class Mat3 extends Float32Array {
|
|
|
528
528
|
* @param {Mat3} out the receiving matrix, defaults to this
|
|
529
529
|
* @returns {Mat3} out
|
|
530
530
|
*/
|
|
531
|
-
multiplyScalarAndAdd(b: Mat3, scale: number, out =
|
|
531
|
+
multiplyScalarAndAdd(b: Mat3, scale: number, out = glmaths.ALWAYS_COPY ? new Mat3() : this) {
|
|
532
532
|
out[0] = this[0] + b[0] * scale
|
|
533
533
|
out[1] = this[1] + b[1] * scale
|
|
534
534
|
out[2] = this[2] + b[2] * scale
|
package/src/mat4.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import glmaths from '.'
|
|
2
2
|
import { equals } from './internalUtils'
|
|
3
3
|
import { Vec2 } from './vec2'
|
|
4
4
|
import { Vec3 } from './vec3'
|
|
@@ -80,7 +80,7 @@ export class Mat4 extends Float32Array {
|
|
|
80
80
|
* @param {Mat4} out the receiving matrix, defaults to this
|
|
81
81
|
* @returns {Mat4} out
|
|
82
82
|
*/
|
|
83
|
-
transpose(out =
|
|
83
|
+
transpose(out = glmaths.ALWAYS_COPY ? new Mat4() : this) {
|
|
84
84
|
if (out === this) {
|
|
85
85
|
const a01 = this[1], a02 = this[2], a03 = this[3]
|
|
86
86
|
const a12 = this[6], a13 = this[7], a23 = this[11]
|
|
@@ -111,7 +111,7 @@ export class Mat4 extends Float32Array {
|
|
|
111
111
|
* @param {Mat4} out the receiving matrix, defaults to this
|
|
112
112
|
* @returns {Mat4} out
|
|
113
113
|
*/
|
|
114
|
-
invert(out =
|
|
114
|
+
invert(out = glmaths.ALWAYS_COPY ? new Mat4() : this) {
|
|
115
115
|
const a00 = this[0], a01 = this[1], a02 = this[2], a03 = this[3]
|
|
116
116
|
const a10 = this[4], a11 = this[5], a12 = this[6], a13 = this[7]
|
|
117
117
|
const a20 = this[8], a21 = this[9], a22 = this[10], a23 = this[11]
|
|
@@ -159,7 +159,7 @@ export class Mat4 extends Float32Array {
|
|
|
159
159
|
* @param {Mat4} out the receiving matrix, defaults to this
|
|
160
160
|
* @returns {Mat4} out
|
|
161
161
|
*/
|
|
162
|
-
adjoint(out =
|
|
162
|
+
adjoint(out = glmaths.ALWAYS_COPY ? new Mat4() : this) {
|
|
163
163
|
const a00 = this[0], a01 = this[1], a02 = this[2], a03 = this[3]
|
|
164
164
|
const a10 = this[4], a11 = this[5], a12 = this[6], a13 = this[7]
|
|
165
165
|
const a20 = this[8], a21 = this[9], a22 = this[10], a23 = this[11]
|
|
@@ -228,7 +228,7 @@ export class Mat4 extends Float32Array {
|
|
|
228
228
|
multiply(b: Vec3): Vec3
|
|
229
229
|
multiply(b: Vec4): Vec4
|
|
230
230
|
multiply(b: Mat4, out?: Mat4): Mat4
|
|
231
|
-
multiply(b: Mat4 | Vec2 | Vec3 | Vec4, out =
|
|
231
|
+
multiply(b: Mat4 | Vec2 | Vec3 | Vec4, out = glmaths.ALWAYS_COPY ? new Mat4() : this) {
|
|
232
232
|
if (b instanceof Vec2)
|
|
233
233
|
return b.transformMat4(this)
|
|
234
234
|
if (b instanceof Vec3)
|
|
@@ -274,7 +274,7 @@ export class Mat4 extends Float32Array {
|
|
|
274
274
|
* @param {Mat4} out the receiving matrix, defaults to this
|
|
275
275
|
* @returns {Mat4} out
|
|
276
276
|
*/
|
|
277
|
-
translate(v: Vec3, out =
|
|
277
|
+
translate(v: Vec3, out = glmaths.ALWAYS_COPY ? new Mat4() : this) {
|
|
278
278
|
const x = v[0], y = v[1], z = v[2]
|
|
279
279
|
if (out === this) {
|
|
280
280
|
out[12] = this[0] * x + this[4] * y + this[8] * z + this[12]
|
|
@@ -303,7 +303,7 @@ export class Mat4 extends Float32Array {
|
|
|
303
303
|
* @param {Mat4} out the receiving matrix, defaults to this
|
|
304
304
|
* @returns {Mat4} out
|
|
305
305
|
*/
|
|
306
|
-
scale(v: Vec3, out =
|
|
306
|
+
scale(v: Vec3, out = glmaths.ALWAYS_COPY ? new Mat4() : this) {
|
|
307
307
|
const x = v[0], y = v[1], z = v[2]
|
|
308
308
|
out[0] = this[0] * x; out[1] = this[1] * x; out[2] = this[2] * x; out[3] = this[3] * x
|
|
309
309
|
out[4] = this[4] * y; out[5] = this[5] * y; out[6] = this[6] * y; out[7] = this[7] * y
|
|
@@ -320,10 +320,10 @@ export class Mat4 extends Float32Array {
|
|
|
320
320
|
* @param {Mat4} out the receiving matrix, defaults to this
|
|
321
321
|
* @returns {Mat4} out
|
|
322
322
|
*/
|
|
323
|
-
rotate(rad: number, axis: Vec3, out =
|
|
323
|
+
rotate(rad: number, axis: Vec3, out = glmaths.ALWAYS_COPY ? new Mat4() : this) {
|
|
324
324
|
let x = axis[0], y = axis[1], z = axis[2]
|
|
325
325
|
let len = Math.sqrt(x * x + y * y + z * z)
|
|
326
|
-
if (len <
|
|
326
|
+
if (len < glmaths.EPSILON) return null
|
|
327
327
|
len = 1 / len
|
|
328
328
|
x *= len; y *= len; z *= len
|
|
329
329
|
|
|
@@ -359,7 +359,7 @@ export class Mat4 extends Float32Array {
|
|
|
359
359
|
* @param {Mat4} out the receiving matrix, defaults to this
|
|
360
360
|
* @returns {Mat4} out
|
|
361
361
|
*/
|
|
362
|
-
rotateX(rad: number, out =
|
|
362
|
+
rotateX(rad: number, out = glmaths.ALWAYS_COPY ? new Mat4() : this) {
|
|
363
363
|
const s = Math.sin(rad), c = Math.cos(rad)
|
|
364
364
|
const a10 = this[4], a11 = this[5], a12 = this[6], a13 = this[7]
|
|
365
365
|
const a20 = this[8], a21 = this[9], a22 = this[10], a23 = this[11]
|
|
@@ -383,7 +383,7 @@ export class Mat4 extends Float32Array {
|
|
|
383
383
|
* @param {Mat4} out the receiving matrix, defaults to this
|
|
384
384
|
* @returns {Mat4} out
|
|
385
385
|
*/
|
|
386
|
-
rotateY(rad: number, out =
|
|
386
|
+
rotateY(rad: number, out = glmaths.ALWAYS_COPY ? new Mat4() : this) {
|
|
387
387
|
const s = Math.sin(rad), c = Math.cos(rad)
|
|
388
388
|
const a00 = this[0], a01 = this[1], a02 = this[2], a03 = this[3]
|
|
389
389
|
const a20 = this[8], a21 = this[9], a22 = this[10], a23 = this[11]
|
|
@@ -407,7 +407,7 @@ export class Mat4 extends Float32Array {
|
|
|
407
407
|
* @param {Mat4} out the receiving matrix, defaults to this
|
|
408
408
|
* @returns {Mat4} out
|
|
409
409
|
*/
|
|
410
|
-
rotateZ(rad: number, out =
|
|
410
|
+
rotateZ(rad: number, out = glmaths.ALWAYS_COPY ? new Mat4() : this) {
|
|
411
411
|
const s = Math.sin(rad), c = Math.cos(rad)
|
|
412
412
|
const a00 = this[0], a01 = this[1], a02 = this[2], a03 = this[3]
|
|
413
413
|
const a10 = this[4], a11 = this[5], a12 = this[6], a13 = this[7]
|
|
@@ -598,7 +598,7 @@ export class Mat4 extends Float32Array {
|
|
|
598
598
|
static fromRotation(rad: number, axis: Vec3, out = new Mat4()) {
|
|
599
599
|
let x = axis[0], y = axis[1], z = axis[2]
|
|
600
600
|
let len = Math.sqrt(x * x + y * y + z * z)
|
|
601
|
-
if (len <
|
|
601
|
+
if (len < glmaths.EPSILON) return null
|
|
602
602
|
len = 1 / len
|
|
603
603
|
x *= len; y *= len; z *= len
|
|
604
604
|
|
|
@@ -793,7 +793,7 @@ export class Mat4 extends Float32Array {
|
|
|
793
793
|
const rl = 1 / (right - left)
|
|
794
794
|
const tb = 1 / (top - bottom)
|
|
795
795
|
const nf = 1 / (near - far)
|
|
796
|
-
const lh =
|
|
796
|
+
const lh = glmaths.LEFT_HANDED
|
|
797
797
|
out[0] = near * 2 * rl
|
|
798
798
|
out[5] = near * 2 * tb
|
|
799
799
|
out[8] = (right + left) * rl; out[9] = (top + bottom) * tb; out[10] = lh ? -(far + near) * nf : (far + near) * nf; out[11] = lh ? 1 : -1
|
|
@@ -816,7 +816,7 @@ export class Mat4 extends Float32Array {
|
|
|
816
816
|
*/
|
|
817
817
|
static perspectiveNO(fovy: number, aspect: number, near: number, far: number | null, out = new Mat4()) {
|
|
818
818
|
const f = 1.0 / Math.tan(fovy / 2)
|
|
819
|
-
const lh =
|
|
819
|
+
const lh = glmaths.LEFT_HANDED
|
|
820
820
|
out[0] = f / aspect
|
|
821
821
|
out[1] = out[2] = out[3] = out[4] = out[6] = out[7] = out[8] = out[9] = out[12] = out[13] = out[15] = 0
|
|
822
822
|
out[5] = f
|
|
@@ -847,7 +847,7 @@ export class Mat4 extends Float32Array {
|
|
|
847
847
|
*/
|
|
848
848
|
static perspectiveZO(fovy: number, aspect: number, near: number, far: number | null, out = new Mat4()) {
|
|
849
849
|
const f = 1.0 / Math.tan(fovy / 2)
|
|
850
|
-
const lh =
|
|
850
|
+
const lh = glmaths.LEFT_HANDED
|
|
851
851
|
out[0] = f / aspect; out[1] = 0; out[2] = 0; out[3] = 0
|
|
852
852
|
out[4] = 0; out[5] = f; out[6] = 0; out[7] = 0
|
|
853
853
|
out[8] = 0; out[9] = 0; out[11] = lh ? 1 : -1
|
|
@@ -882,7 +882,7 @@ export class Mat4 extends Float32Array {
|
|
|
882
882
|
|
|
883
883
|
out[0] = xScale; out[1] = 0; out[2] = 0; out[3] = 0
|
|
884
884
|
out[4] = 0; out[5] = yScale; out[6] = 0; out[7] = 0
|
|
885
|
-
const lh =
|
|
885
|
+
const lh = glmaths.LEFT_HANDED
|
|
886
886
|
out[8] = -((leftTan - rightTan) * xScale * 0.5)
|
|
887
887
|
out[9] = (upTan - downTan) * yScale * 0.5
|
|
888
888
|
out[10] = lh ? -far / (near - far) : far / (near - far)
|
|
@@ -911,7 +911,7 @@ export class Mat4 extends Float32Array {
|
|
|
911
911
|
const lr = 1 / (left - right)
|
|
912
912
|
const bt = 1 / (bottom - top)
|
|
913
913
|
const nf = 1 / (near - far)
|
|
914
|
-
const s =
|
|
914
|
+
const s = glmaths.LEFT_HANDED ? -1 : 1
|
|
915
915
|
out[0] = -2 * lr; out[1] = 0; out[2] = 0; out[3] = 0
|
|
916
916
|
out[4] = 0; out[5] = -2 * bt; out[6] = 0; out[7] = 0
|
|
917
917
|
out[8] = 0; out[9] = 0; out[10] = s * 2 * nf; out[11] = 0
|
|
@@ -938,7 +938,7 @@ export class Mat4 extends Float32Array {
|
|
|
938
938
|
const lr = 1 / (left - right)
|
|
939
939
|
const bt = 1 / (bottom - top)
|
|
940
940
|
const nf = 1 / (near - far)
|
|
941
|
-
const s =
|
|
941
|
+
const s = glmaths.LEFT_HANDED ? -1 : 1
|
|
942
942
|
out[0] = -2 * lr; out[1] = 0; out[2] = 0; out[3] = 0
|
|
943
943
|
out[4] = 0; out[5] = -2 * bt; out[6] = 0; out[7] = 0
|
|
944
944
|
out[8] = 0; out[9] = 0; out[10] = s * nf; out[11] = 0
|
|
@@ -971,7 +971,7 @@ export class Mat4 extends Float32Array {
|
|
|
971
971
|
return out
|
|
972
972
|
}
|
|
973
973
|
|
|
974
|
-
if (
|
|
974
|
+
if (glmaths.LEFT_HANDED) {
|
|
975
975
|
z0 = centerx - eyex; z1 = centery - eyey; z2 = centerz - eyez
|
|
976
976
|
} else {
|
|
977
977
|
z0 = eyex - centerx; z1 = eyey - centery; z2 = eyez - centerz
|
|
@@ -1017,7 +1017,7 @@ export class Mat4 extends Float32Array {
|
|
|
1017
1017
|
const upx = up[0], upy = up[1], upz = up[2]
|
|
1018
1018
|
|
|
1019
1019
|
let z0, z1, z2
|
|
1020
|
-
if (
|
|
1020
|
+
if (glmaths.LEFT_HANDED) {
|
|
1021
1021
|
z0 = target[0] - eyex; z1 = target[1] - eyey; z2 = target[2] - eyez
|
|
1022
1022
|
} else {
|
|
1023
1023
|
z0 = eyex - target[0]; z1 = eyey - target[1]; z2 = eyez - target[2]
|
|
@@ -1056,7 +1056,7 @@ export class Mat4 extends Float32Array {
|
|
|
1056
1056
|
*/
|
|
1057
1057
|
static infinitePerspective(fovy: number, aspect: number, near: number, out = new Mat4()) {
|
|
1058
1058
|
const f = 1.0 / Math.tan(fovy / 2)
|
|
1059
|
-
const lh =
|
|
1059
|
+
const lh = glmaths.LEFT_HANDED
|
|
1060
1060
|
out[0] = f / aspect
|
|
1061
1061
|
out[1] = out[2] = out[3] = out[4] = out[6] = out[7] = out[8] = out[9] = out[12] = out[13] = out[15] = 0
|
|
1062
1062
|
out[5] = f
|
|
@@ -1176,7 +1176,7 @@ export class Mat4 extends Float32Array {
|
|
|
1176
1176
|
* @param {Mat4} out the receiving matrix, defaults to this
|
|
1177
1177
|
* @returns {Mat4} out
|
|
1178
1178
|
*/
|
|
1179
|
-
plus(b: Mat4, out =
|
|
1179
|
+
plus(b: Mat4, out = glmaths.ALWAYS_COPY ? new Mat4() : this) {
|
|
1180
1180
|
out[0] = this[0] + b[0]; out[1] = this[1] + b[1]; out[2] = this[2] + b[2]; out[3] = this[3] + b[3]
|
|
1181
1181
|
out[4] = this[4] + b[4]; out[5] = this[5] + b[5]; out[6] = this[6] + b[6]; out[7] = this[7] + b[7]
|
|
1182
1182
|
out[8] = this[8] + b[8]; out[9] = this[9] + b[9]; out[10] = this[10] + b[10]; out[11] = this[11] + b[11]
|
|
@@ -1191,7 +1191,7 @@ export class Mat4 extends Float32Array {
|
|
|
1191
1191
|
* @param {Mat4} out the receiving matrix, defaults to this
|
|
1192
1192
|
* @returns {Mat4} out
|
|
1193
1193
|
*/
|
|
1194
|
-
minus(b: Mat4, out =
|
|
1194
|
+
minus(b: Mat4, out = glmaths.ALWAYS_COPY ? new Mat4() : this) {
|
|
1195
1195
|
out[0] = this[0] - b[0]; out[1] = this[1] - b[1]; out[2] = this[2] - b[2]; out[3] = this[3] - b[3]
|
|
1196
1196
|
out[4] = this[4] - b[4]; out[5] = this[5] - b[5]; out[6] = this[6] - b[6]; out[7] = this[7] - b[7]
|
|
1197
1197
|
out[8] = this[8] - b[8]; out[9] = this[9] - b[9]; out[10] = this[10] - b[10]; out[11] = this[11] - b[11]
|
|
@@ -1206,7 +1206,7 @@ export class Mat4 extends Float32Array {
|
|
|
1206
1206
|
* @param {Mat4} out the receiving matrix, defaults to this
|
|
1207
1207
|
* @returns {Mat4} out
|
|
1208
1208
|
*/
|
|
1209
|
-
scaleScalar(b: number, out =
|
|
1209
|
+
scaleScalar(b: number, out = glmaths.ALWAYS_COPY ? new Mat4() : this) {
|
|
1210
1210
|
out[0] = this[0] * b; out[1] = this[1] * b; out[2] = this[2] * b; out[3] = this[3] * b
|
|
1211
1211
|
out[4] = this[4] * b; out[5] = this[5] * b; out[6] = this[6] * b; out[7] = this[7] * b
|
|
1212
1212
|
out[8] = this[8] * b; out[9] = this[9] * b; out[10] = this[10] * b; out[11] = this[11] * b
|
|
@@ -1222,7 +1222,7 @@ export class Mat4 extends Float32Array {
|
|
|
1222
1222
|
* @param {Mat4} out the receiving matrix, defaults to this
|
|
1223
1223
|
* @returns {Mat4} out
|
|
1224
1224
|
*/
|
|
1225
|
-
multiplyScalarAndAdd(b: Mat4, scale: number, out =
|
|
1225
|
+
multiplyScalarAndAdd(b: Mat4, scale: number, out = glmaths.ALWAYS_COPY ? new Mat4() : this) {
|
|
1226
1226
|
out[0] = this[0] + b[0] * scale; out[1] = this[1] + b[1] * scale
|
|
1227
1227
|
out[2] = this[2] + b[2] * scale; out[3] = this[3] + b[3] * scale
|
|
1228
1228
|
out[4] = this[4] + b[4] * scale; out[5] = this[5] + b[5] * scale
|