@vib3code/sdk 2.0.3-canary.89c05e0 → 2.0.3-canary.d0c4221
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/package.json +1 -1
- package/src/geometry/generators/Crystal.js +2 -2
- package/src/math/Mat4x4.js +6 -122
- package/src/math/Rotor4D.js +45 -38
- package/src/math/Vec4.js +78 -119
- package/DOCS/EXPANSION_DESIGN_ULTRA.md +0 -387
- package/DOCS/OPTIMIZATION_PLAN_MATH.md +0 -118
- package/src/experimental/GameLoop.js +0 -72
- package/src/experimental/LatticePhysics.js +0 -100
- package/src/experimental/LiveDirector.js +0 -143
- package/src/experimental/PlayerController4D.js +0 -154
- package/src/experimental/VIB3Actor.js +0 -138
- package/src/experimental/VIB3Compositor.js +0 -117
- package/src/experimental/VIB3Link.js +0 -122
- package/src/experimental/VIB3Orchestrator.js +0 -146
- package/src/experimental/VIB3Universe.js +0 -109
- package/src/experimental/demos/CrystalLabyrinth.js +0 -202
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vib3code/sdk",
|
|
3
|
-
"version": "2.0.3-canary.
|
|
3
|
+
"version": "2.0.3-canary.d0c4221",
|
|
4
4
|
"description": "VIB3+ 4D Visualization SDK - Unified engine with 6D rotation, MCP agentic integration, and cross-platform support",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/core/VIB3Engine.js",
|
|
@@ -61,8 +61,8 @@ export function generate24CellVertices(size = 1) {
|
|
|
61
61
|
];
|
|
62
62
|
for (const [s1, s2] of signs) {
|
|
63
63
|
const v = new Vec4(0, 0, 0, 0);
|
|
64
|
-
v.
|
|
65
|
-
v.
|
|
64
|
+
v.data[i] = s1 * s;
|
|
65
|
+
v.data[j] = s2 * s;
|
|
66
66
|
vertices.push(v);
|
|
67
67
|
}
|
|
68
68
|
}
|
package/src/math/Mat4x4.js
CHANGED
|
@@ -547,122 +547,6 @@ export class Mat4x4 {
|
|
|
547
547
|
return new Mat4x4(json.data);
|
|
548
548
|
}
|
|
549
549
|
|
|
550
|
-
// ========== IN-PLACE ROTATIONS ==========
|
|
551
|
-
|
|
552
|
-
/**
|
|
553
|
-
* Rotate in XY plane in place
|
|
554
|
-
* @param {number} angle
|
|
555
|
-
* @returns {Mat4x4} this
|
|
556
|
-
*/
|
|
557
|
-
rotateXY(angle) {
|
|
558
|
-
const c = Math.cos(angle);
|
|
559
|
-
const s = Math.sin(angle);
|
|
560
|
-
const m = this.data;
|
|
561
|
-
|
|
562
|
-
for (let i = 0; i < 4; i++) {
|
|
563
|
-
const a0 = m[i]; // Col 0
|
|
564
|
-
const a1 = m[i + 4]; // Col 1
|
|
565
|
-
m[i] = a0 * c + a1 * s;
|
|
566
|
-
m[i + 4] = -a0 * s + a1 * c;
|
|
567
|
-
}
|
|
568
|
-
return this;
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
/**
|
|
572
|
-
* Rotate in XZ plane in place
|
|
573
|
-
* @param {number} angle
|
|
574
|
-
* @returns {Mat4x4} this
|
|
575
|
-
*/
|
|
576
|
-
rotateXZ(angle) {
|
|
577
|
-
const c = Math.cos(angle);
|
|
578
|
-
const s = Math.sin(angle);
|
|
579
|
-
const m = this.data;
|
|
580
|
-
|
|
581
|
-
for (let i = 0; i < 4; i++) {
|
|
582
|
-
const a0 = m[i]; // Col 0
|
|
583
|
-
const a2 = m[i + 8]; // Col 2
|
|
584
|
-
m[i] = a0 * c - a2 * s;
|
|
585
|
-
m[i + 8] = a0 * s + a2 * c;
|
|
586
|
-
}
|
|
587
|
-
return this;
|
|
588
|
-
}
|
|
589
|
-
|
|
590
|
-
/**
|
|
591
|
-
* Rotate in YZ plane in place
|
|
592
|
-
* @param {number} angle
|
|
593
|
-
* @returns {Mat4x4} this
|
|
594
|
-
*/
|
|
595
|
-
rotateYZ(angle) {
|
|
596
|
-
const c = Math.cos(angle);
|
|
597
|
-
const s = Math.sin(angle);
|
|
598
|
-
const m = this.data;
|
|
599
|
-
|
|
600
|
-
for (let i = 0; i < 4; i++) {
|
|
601
|
-
const a1 = m[i + 4]; // Col 1
|
|
602
|
-
const a2 = m[i + 8]; // Col 2
|
|
603
|
-
m[i + 4] = a1 * c + a2 * s;
|
|
604
|
-
m[i + 8] = -a1 * s + a2 * c;
|
|
605
|
-
}
|
|
606
|
-
return this;
|
|
607
|
-
}
|
|
608
|
-
|
|
609
|
-
/**
|
|
610
|
-
* Rotate in XW plane in place
|
|
611
|
-
* @param {number} angle
|
|
612
|
-
* @returns {Mat4x4} this
|
|
613
|
-
*/
|
|
614
|
-
rotateXW(angle) {
|
|
615
|
-
const c = Math.cos(angle);
|
|
616
|
-
const s = Math.sin(angle);
|
|
617
|
-
const m = this.data;
|
|
618
|
-
|
|
619
|
-
for (let i = 0; i < 4; i++) {
|
|
620
|
-
const a0 = m[i]; // Col 0
|
|
621
|
-
const a3 = m[i + 12]; // Col 3
|
|
622
|
-
m[i] = a0 * c + a3 * s;
|
|
623
|
-
m[i + 12] = -a0 * s + a3 * c;
|
|
624
|
-
}
|
|
625
|
-
return this;
|
|
626
|
-
}
|
|
627
|
-
|
|
628
|
-
/**
|
|
629
|
-
* Rotate in YW plane in place
|
|
630
|
-
* @param {number} angle
|
|
631
|
-
* @returns {Mat4x4} this
|
|
632
|
-
*/
|
|
633
|
-
rotateYW(angle) {
|
|
634
|
-
const c = Math.cos(angle);
|
|
635
|
-
const s = Math.sin(angle);
|
|
636
|
-
const m = this.data;
|
|
637
|
-
|
|
638
|
-
for (let i = 0; i < 4; i++) {
|
|
639
|
-
const a1 = m[i + 4]; // Col 1
|
|
640
|
-
const a3 = m[i + 12]; // Col 3
|
|
641
|
-
m[i + 4] = a1 * c + a3 * s;
|
|
642
|
-
m[i + 12] = -a1 * s + a3 * c;
|
|
643
|
-
}
|
|
644
|
-
return this;
|
|
645
|
-
}
|
|
646
|
-
|
|
647
|
-
/**
|
|
648
|
-
* Rotate in ZW plane in place
|
|
649
|
-
* @param {number} angle
|
|
650
|
-
* @returns {Mat4x4} this
|
|
651
|
-
*/
|
|
652
|
-
rotateZW(angle) {
|
|
653
|
-
const c = Math.cos(angle);
|
|
654
|
-
const s = Math.sin(angle);
|
|
655
|
-
const m = this.data;
|
|
656
|
-
|
|
657
|
-
for (let i = 0; i < 4; i++) {
|
|
658
|
-
const a2 = m[i + 8]; // Col 2
|
|
659
|
-
const a3 = m[i + 12]; // Col 3
|
|
660
|
-
m[i + 8] = a2 * c + a3 * s;
|
|
661
|
-
m[i + 12] = -a2 * s + a3 * c;
|
|
662
|
-
}
|
|
663
|
-
return this;
|
|
664
|
-
}
|
|
665
|
-
|
|
666
550
|
// ========== ROTATION MATRICES FOR ALL 6 PLANES ==========
|
|
667
551
|
|
|
668
552
|
/**
|
|
@@ -797,12 +681,12 @@ export class Mat4x4 {
|
|
|
797
681
|
static rotationFromAngles(angles) {
|
|
798
682
|
let result = Mat4x4.identity();
|
|
799
683
|
|
|
800
|
-
if (angles.xy) result.
|
|
801
|
-
if (angles.xz) result.
|
|
802
|
-
if (angles.yz) result.
|
|
803
|
-
if (angles.xw) result.
|
|
804
|
-
if (angles.yw) result.
|
|
805
|
-
if (angles.zw) result.
|
|
684
|
+
if (angles.xy) result = result.multiply(Mat4x4.rotationXY(angles.xy));
|
|
685
|
+
if (angles.xz) result = result.multiply(Mat4x4.rotationXZ(angles.xz));
|
|
686
|
+
if (angles.yz) result = result.multiply(Mat4x4.rotationYZ(angles.yz));
|
|
687
|
+
if (angles.xw) result = result.multiply(Mat4x4.rotationXW(angles.xw));
|
|
688
|
+
if (angles.yw) result = result.multiply(Mat4x4.rotationYW(angles.yw));
|
|
689
|
+
if (angles.zw) result = result.multiply(Mat4x4.rotationZW(angles.zw));
|
|
806
690
|
|
|
807
691
|
return result;
|
|
808
692
|
}
|
package/src/math/Rotor4D.js
CHANGED
|
@@ -323,17 +323,14 @@ export class Rotor4D {
|
|
|
323
323
|
/**
|
|
324
324
|
* Rotate a 4D vector using sandwich product: v' = R v R†
|
|
325
325
|
*
|
|
326
|
-
* Matrix math is inlined to avoid allocating a temporary Float32Array(16).
|
|
327
|
-
* Pass an optional target Vec4 to eliminate all allocations.
|
|
328
|
-
*
|
|
329
326
|
* @param {Vec4} v - Vector to rotate
|
|
330
|
-
* @param {Vec4} [target] - Optional
|
|
331
|
-
* @returns {Vec4} Rotated vector
|
|
327
|
+
* @param {Vec4} [target] - Optional target vector to write result to
|
|
328
|
+
* @returns {Vec4} Rotated vector
|
|
332
329
|
*/
|
|
333
330
|
rotate(v, target) {
|
|
334
|
-
|
|
331
|
+
// Direct matrix multiplication without allocation
|
|
335
332
|
|
|
336
|
-
// Normalize for
|
|
333
|
+
// Normalize components for stability (same as toMatrix)
|
|
337
334
|
const n = this.norm();
|
|
338
335
|
const invN = n > 1e-10 ? 1 / n : 1;
|
|
339
336
|
|
|
@@ -346,7 +343,7 @@ export class Rotor4D {
|
|
|
346
343
|
const zw = this.zw * invN;
|
|
347
344
|
const xyzw = this.xyzw * invN;
|
|
348
345
|
|
|
349
|
-
//
|
|
346
|
+
// Pre-compute products
|
|
350
347
|
const s2 = s * s;
|
|
351
348
|
const xy2 = xy * xy;
|
|
352
349
|
const xz2 = xz * xz;
|
|
@@ -356,20 +353,22 @@ export class Rotor4D {
|
|
|
356
353
|
const zw2 = zw * zw;
|
|
357
354
|
const xyzw2 = xyzw * xyzw;
|
|
358
355
|
|
|
359
|
-
// Cross terms
|
|
356
|
+
// Cross terms
|
|
360
357
|
const sxy = 2 * s * xy;
|
|
361
358
|
const sxz = 2 * s * xz;
|
|
362
359
|
const syz = 2 * s * yz;
|
|
363
360
|
const sxw = 2 * s * xw;
|
|
364
361
|
const syw = 2 * s * yw;
|
|
365
362
|
const szw = 2 * s * zw;
|
|
363
|
+
// const sxyzw = 2 * s * xyzw; // Unused in rotation matrix
|
|
366
364
|
|
|
367
|
-
const xzyz = 2 * xz * yz;
|
|
368
|
-
const xyyz = 2 * xy * yz;
|
|
369
365
|
const xyxz = 2 * xy * xz;
|
|
366
|
+
const xyyz = 2 * xy * yz;
|
|
370
367
|
const xyxw = 2 * xy * xw;
|
|
371
368
|
const xyyw = 2 * xy * yw;
|
|
369
|
+
// const xyzw_c = 2 * xy * zw; // Unused in rotation matrix
|
|
372
370
|
|
|
371
|
+
const xzyz = 2 * xz * yz;
|
|
373
372
|
const xzxw = 2 * xz * xw;
|
|
374
373
|
const xzyw = 2 * xz * yw;
|
|
375
374
|
const xzzw = 2 * xz * zw;
|
|
@@ -389,33 +388,40 @@ export class Rotor4D {
|
|
|
389
388
|
const ywxyzw = 2 * yw * xyzw;
|
|
390
389
|
const zwxyzw = 2 * zw * xyzw;
|
|
391
390
|
|
|
392
|
-
//
|
|
393
|
-
//
|
|
394
|
-
const
|
|
395
|
-
const
|
|
396
|
-
const
|
|
397
|
-
const
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
const
|
|
401
|
-
const
|
|
402
|
-
const
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
const
|
|
407
|
-
const
|
|
408
|
-
|
|
409
|
-
const
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
const
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
const
|
|
416
|
-
|
|
417
|
-
const
|
|
418
|
-
const
|
|
391
|
+
// Matrix elements
|
|
392
|
+
// Col 0
|
|
393
|
+
const m00 = s2 - xy2 - xz2 + yz2 - xw2 + yw2 + zw2 - xyzw2;
|
|
394
|
+
const m01 = sxy + xzyz + xwyw - zwxyzw;
|
|
395
|
+
const m02 = sxz - xyyz + xwzw + ywxyzw;
|
|
396
|
+
const m03 = sxw - xyyw - xzzw - yzxyzw;
|
|
397
|
+
|
|
398
|
+
// Col 1
|
|
399
|
+
const m10 = -sxy + xzyz + xwyw + zwxyzw;
|
|
400
|
+
const m11 = s2 - xy2 + xz2 - yz2 + xw2 - yw2 + zw2 - xyzw2;
|
|
401
|
+
const m12 = syz + xyxz + ywzw - xwxyzw;
|
|
402
|
+
const m13 = syw + xyxw - yzzw + xzxyzw;
|
|
403
|
+
|
|
404
|
+
// Col 2
|
|
405
|
+
const m20 = -sxz - xyyz + xwzw - ywxyzw;
|
|
406
|
+
const m21 = -syz + xyxz + ywzw + xwxyzw;
|
|
407
|
+
const m22 = s2 + xy2 - xz2 - yz2 + xw2 + yw2 - zw2 - xyzw2;
|
|
408
|
+
const m23 = szw + xzxw + yzyw - xyxyzw;
|
|
409
|
+
|
|
410
|
+
// Col 3
|
|
411
|
+
const m30 = -sxw - xyyw - xzzw + yzxyzw;
|
|
412
|
+
const m31 = -syw + xyxw - yzzw - xzxyzw;
|
|
413
|
+
const m32 = -szw + xzxw + yzyw + xyxyzw;
|
|
414
|
+
const m33 = s2 + xy2 + xz2 + yz2 - xw2 - yw2 - zw2 - xyzw2;
|
|
415
|
+
|
|
416
|
+
const x = v.x;
|
|
417
|
+
const y = v.y;
|
|
418
|
+
const z = v.z;
|
|
419
|
+
const w = v.w;
|
|
420
|
+
|
|
421
|
+
const rx = m00 * x + m10 * y + m20 * z + m30 * w;
|
|
422
|
+
const ry = m01 * x + m11 * y + m21 * z + m31 * w;
|
|
423
|
+
const rz = m02 * x + m12 * y + m22 * z + m32 * w;
|
|
424
|
+
const rw = m03 * x + m13 * y + m23 * z + m33 * w;
|
|
419
425
|
|
|
420
426
|
if (target) {
|
|
421
427
|
target.x = rx;
|
|
@@ -424,6 +430,7 @@ export class Rotor4D {
|
|
|
424
430
|
target.w = rw;
|
|
425
431
|
return target;
|
|
426
432
|
}
|
|
433
|
+
|
|
427
434
|
return new Vec4(rx, ry, rz, rw);
|
|
428
435
|
}
|
|
429
436
|
|
package/src/math/Vec4.js
CHANGED
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
* Vec4 - 4D Vector Class
|
|
3
3
|
*
|
|
4
4
|
* Represents a point or direction in 4-dimensional space.
|
|
5
|
-
* Uses
|
|
6
|
-
* GPU-compatible Float32Array created on demand via toFloat32Array().
|
|
5
|
+
* Uses Float32Array for GPU compatibility and potential SIMD optimization.
|
|
7
6
|
*
|
|
8
7
|
* @example
|
|
9
8
|
* const v = new Vec4(1, 2, 3, 0.5);
|
|
@@ -20,66 +19,26 @@ export class Vec4 {
|
|
|
20
19
|
* @param {number} w - W component (4th dimension)
|
|
21
20
|
*/
|
|
22
21
|
constructor(x = 0, y = 0, z = 0, w = 0) {
|
|
23
|
-
|
|
24
|
-
this.
|
|
25
|
-
this.
|
|
26
|
-
this.
|
|
22
|
+
// Use Float32Array for GPU compatibility
|
|
23
|
+
this.data = new Float32Array(4);
|
|
24
|
+
this.data[0] = x;
|
|
25
|
+
this.data[1] = y;
|
|
26
|
+
this.data[2] = z;
|
|
27
|
+
this.data[3] = w;
|
|
27
28
|
}
|
|
28
29
|
|
|
29
|
-
// Property accessors
|
|
30
|
-
get x() { return this.
|
|
31
|
-
set x(v) { this.
|
|
30
|
+
// Property accessors for readability
|
|
31
|
+
get x() { return this.data[0]; }
|
|
32
|
+
set x(v) { this.data[0] = v; }
|
|
32
33
|
|
|
33
|
-
get y() { return this.
|
|
34
|
-
set y(v) { this.
|
|
34
|
+
get y() { return this.data[1]; }
|
|
35
|
+
set y(v) { this.data[1] = v; }
|
|
35
36
|
|
|
36
|
-
get z() { return this.
|
|
37
|
-
set z(v) { this.
|
|
37
|
+
get z() { return this.data[2]; }
|
|
38
|
+
set z(v) { this.data[2] = v; }
|
|
38
39
|
|
|
39
|
-
get w() { return this.
|
|
40
|
-
set w(v) { this.
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Backward-compatible .data getter.
|
|
44
|
-
* Returns a Float32Array snapshot of current values.
|
|
45
|
-
* Note: writes to the returned array do NOT propagate back.
|
|
46
|
-
* Use setComponent(index, value) for index-based mutation.
|
|
47
|
-
* @returns {Float32Array}
|
|
48
|
-
*/
|
|
49
|
-
get data() {
|
|
50
|
-
return new Float32Array([this._x, this._y, this._z, this._w]);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Set a component by index (0=x, 1=y, 2=z, 3=w)
|
|
55
|
-
* @param {number} index - Component index (0-3)
|
|
56
|
-
* @param {number} value - New value
|
|
57
|
-
* @returns {Vec4} this
|
|
58
|
-
*/
|
|
59
|
-
setComponent(index, value) {
|
|
60
|
-
switch (index) {
|
|
61
|
-
case 0: this._x = value; break;
|
|
62
|
-
case 1: this._y = value; break;
|
|
63
|
-
case 2: this._z = value; break;
|
|
64
|
-
case 3: this._w = value; break;
|
|
65
|
-
}
|
|
66
|
-
return this;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Get a component by index (0=x, 1=y, 2=z, 3=w)
|
|
71
|
-
* @param {number} index - Component index (0-3)
|
|
72
|
-
* @returns {number}
|
|
73
|
-
*/
|
|
74
|
-
getComponent(index) {
|
|
75
|
-
switch (index) {
|
|
76
|
-
case 0: return this._x;
|
|
77
|
-
case 1: return this._y;
|
|
78
|
-
case 2: return this._z;
|
|
79
|
-
case 3: return this._w;
|
|
80
|
-
default: return 0;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
40
|
+
get w() { return this.data[3]; }
|
|
41
|
+
set w(v) { this.data[3] = v; }
|
|
83
42
|
|
|
84
43
|
/**
|
|
85
44
|
* Create a Vec4 from an array
|
|
@@ -95,7 +54,7 @@ export class Vec4 {
|
|
|
95
54
|
* @returns {Vec4}
|
|
96
55
|
*/
|
|
97
56
|
clone() {
|
|
98
|
-
return new Vec4(this.
|
|
57
|
+
return new Vec4(this.x, this.y, this.z, this.w);
|
|
99
58
|
}
|
|
100
59
|
|
|
101
60
|
/**
|
|
@@ -104,10 +63,10 @@ export class Vec4 {
|
|
|
104
63
|
* @returns {Vec4} this (for chaining)
|
|
105
64
|
*/
|
|
106
65
|
copy(v) {
|
|
107
|
-
this.
|
|
108
|
-
this.
|
|
109
|
-
this.
|
|
110
|
-
this.
|
|
66
|
+
this.data[0] = v.data[0];
|
|
67
|
+
this.data[1] = v.data[1];
|
|
68
|
+
this.data[2] = v.data[2];
|
|
69
|
+
this.data[3] = v.data[3];
|
|
111
70
|
return this;
|
|
112
71
|
}
|
|
113
72
|
|
|
@@ -120,10 +79,10 @@ export class Vec4 {
|
|
|
120
79
|
* @returns {Vec4} this
|
|
121
80
|
*/
|
|
122
81
|
set(x, y, z, w) {
|
|
123
|
-
this.
|
|
124
|
-
this.
|
|
125
|
-
this.
|
|
126
|
-
this.
|
|
82
|
+
this.data[0] = x;
|
|
83
|
+
this.data[1] = y;
|
|
84
|
+
this.data[2] = z;
|
|
85
|
+
this.data[3] = w;
|
|
127
86
|
return this;
|
|
128
87
|
}
|
|
129
88
|
|
|
@@ -134,10 +93,10 @@ export class Vec4 {
|
|
|
134
93
|
*/
|
|
135
94
|
add(v) {
|
|
136
95
|
return new Vec4(
|
|
137
|
-
this.
|
|
138
|
-
this.
|
|
139
|
-
this.
|
|
140
|
-
this.
|
|
96
|
+
this.x + v.x,
|
|
97
|
+
this.y + v.y,
|
|
98
|
+
this.z + v.z,
|
|
99
|
+
this.w + v.w
|
|
141
100
|
);
|
|
142
101
|
}
|
|
143
102
|
|
|
@@ -147,10 +106,10 @@ export class Vec4 {
|
|
|
147
106
|
* @returns {Vec4} this
|
|
148
107
|
*/
|
|
149
108
|
addInPlace(v) {
|
|
150
|
-
this.
|
|
151
|
-
this.
|
|
152
|
-
this.
|
|
153
|
-
this.
|
|
109
|
+
this.data[0] += v.data[0];
|
|
110
|
+
this.data[1] += v.data[1];
|
|
111
|
+
this.data[2] += v.data[2];
|
|
112
|
+
this.data[3] += v.data[3];
|
|
154
113
|
return this;
|
|
155
114
|
}
|
|
156
115
|
|
|
@@ -161,10 +120,10 @@ export class Vec4 {
|
|
|
161
120
|
*/
|
|
162
121
|
sub(v) {
|
|
163
122
|
return new Vec4(
|
|
164
|
-
this.
|
|
165
|
-
this.
|
|
166
|
-
this.
|
|
167
|
-
this.
|
|
123
|
+
this.x - v.x,
|
|
124
|
+
this.y - v.y,
|
|
125
|
+
this.z - v.z,
|
|
126
|
+
this.w - v.w
|
|
168
127
|
);
|
|
169
128
|
}
|
|
170
129
|
|
|
@@ -174,10 +133,10 @@ export class Vec4 {
|
|
|
174
133
|
* @returns {Vec4} this
|
|
175
134
|
*/
|
|
176
135
|
subInPlace(v) {
|
|
177
|
-
this.
|
|
178
|
-
this.
|
|
179
|
-
this.
|
|
180
|
-
this.
|
|
136
|
+
this.data[0] -= v.data[0];
|
|
137
|
+
this.data[1] -= v.data[1];
|
|
138
|
+
this.data[2] -= v.data[2];
|
|
139
|
+
this.data[3] -= v.data[3];
|
|
181
140
|
return this;
|
|
182
141
|
}
|
|
183
142
|
|
|
@@ -188,10 +147,10 @@ export class Vec4 {
|
|
|
188
147
|
*/
|
|
189
148
|
scale(s) {
|
|
190
149
|
return new Vec4(
|
|
191
|
-
this.
|
|
192
|
-
this.
|
|
193
|
-
this.
|
|
194
|
-
this.
|
|
150
|
+
this.x * s,
|
|
151
|
+
this.y * s,
|
|
152
|
+
this.z * s,
|
|
153
|
+
this.w * s
|
|
195
154
|
);
|
|
196
155
|
}
|
|
197
156
|
|
|
@@ -201,10 +160,10 @@ export class Vec4 {
|
|
|
201
160
|
* @returns {Vec4} this
|
|
202
161
|
*/
|
|
203
162
|
scaleInPlace(s) {
|
|
204
|
-
this.
|
|
205
|
-
this.
|
|
206
|
-
this.
|
|
207
|
-
this.
|
|
163
|
+
this.data[0] *= s;
|
|
164
|
+
this.data[1] *= s;
|
|
165
|
+
this.data[2] *= s;
|
|
166
|
+
this.data[3] *= s;
|
|
208
167
|
return this;
|
|
209
168
|
}
|
|
210
169
|
|
|
@@ -215,10 +174,10 @@ export class Vec4 {
|
|
|
215
174
|
*/
|
|
216
175
|
multiply(v) {
|
|
217
176
|
return new Vec4(
|
|
218
|
-
this.
|
|
219
|
-
this.
|
|
220
|
-
this.
|
|
221
|
-
this.
|
|
177
|
+
this.x * v.x,
|
|
178
|
+
this.y * v.y,
|
|
179
|
+
this.z * v.z,
|
|
180
|
+
this.w * v.w
|
|
222
181
|
);
|
|
223
182
|
}
|
|
224
183
|
|
|
@@ -227,7 +186,7 @@ export class Vec4 {
|
|
|
227
186
|
* @returns {Vec4} New vector
|
|
228
187
|
*/
|
|
229
188
|
negate() {
|
|
230
|
-
return new Vec4(-this.
|
|
189
|
+
return new Vec4(-this.x, -this.y, -this.z, -this.w);
|
|
231
190
|
}
|
|
232
191
|
|
|
233
192
|
/**
|
|
@@ -235,10 +194,10 @@ export class Vec4 {
|
|
|
235
194
|
* @returns {Vec4} this
|
|
236
195
|
*/
|
|
237
196
|
negateInPlace() {
|
|
238
|
-
this.
|
|
239
|
-
this.
|
|
240
|
-
this.
|
|
241
|
-
this.
|
|
197
|
+
this.data[0] = -this.data[0];
|
|
198
|
+
this.data[1] = -this.data[1];
|
|
199
|
+
this.data[2] = -this.data[2];
|
|
200
|
+
this.data[3] = -this.data[3];
|
|
242
201
|
return this;
|
|
243
202
|
}
|
|
244
203
|
|
|
@@ -248,7 +207,7 @@ export class Vec4 {
|
|
|
248
207
|
* @returns {number}
|
|
249
208
|
*/
|
|
250
209
|
dot(v) {
|
|
251
|
-
return this.
|
|
210
|
+
return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
|
|
252
211
|
}
|
|
253
212
|
|
|
254
213
|
/**
|
|
@@ -256,7 +215,7 @@ export class Vec4 {
|
|
|
256
215
|
* @returns {number}
|
|
257
216
|
*/
|
|
258
217
|
lengthSquared() {
|
|
259
|
-
return this.
|
|
218
|
+
return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
|
|
260
219
|
}
|
|
261
220
|
|
|
262
221
|
/**
|
|
@@ -318,10 +277,10 @@ export class Vec4 {
|
|
|
318
277
|
*/
|
|
319
278
|
lerp(v, t) {
|
|
320
279
|
return new Vec4(
|
|
321
|
-
this.
|
|
322
|
-
this.
|
|
323
|
-
this.
|
|
324
|
-
this.
|
|
280
|
+
this.x + (v.x - this.x) * t,
|
|
281
|
+
this.y + (v.y - this.y) * t,
|
|
282
|
+
this.z + (v.z - this.z) * t,
|
|
283
|
+
this.w + (v.w - this.w) * t
|
|
325
284
|
);
|
|
326
285
|
}
|
|
327
286
|
|
|
@@ -333,10 +292,10 @@ export class Vec4 {
|
|
|
333
292
|
*/
|
|
334
293
|
equals(v, epsilon = 1e-6) {
|
|
335
294
|
return (
|
|
336
|
-
Math.abs(this.
|
|
337
|
-
Math.abs(this.
|
|
338
|
-
Math.abs(this.
|
|
339
|
-
Math.abs(this.
|
|
295
|
+
Math.abs(this.x - v.x) < epsilon &&
|
|
296
|
+
Math.abs(this.y - v.y) < epsilon &&
|
|
297
|
+
Math.abs(this.z - v.z) < epsilon &&
|
|
298
|
+
Math.abs(this.w - v.w) < epsilon
|
|
340
299
|
);
|
|
341
300
|
}
|
|
342
301
|
|
|
@@ -362,10 +321,10 @@ export class Vec4 {
|
|
|
362
321
|
d = options.distance ?? options.d ?? 2;
|
|
363
322
|
}
|
|
364
323
|
const epsilon = options.epsilon ?? 1e-5;
|
|
365
|
-
const denom = d - this.
|
|
324
|
+
const denom = d - this.w;
|
|
366
325
|
const clamped = Math.abs(denom) < epsilon ? (denom >= 0 ? epsilon : -epsilon) : denom;
|
|
367
326
|
const scale = 1 / clamped;
|
|
368
|
-
return new Vec4(this.
|
|
327
|
+
return new Vec4(this.x * scale, this.y * scale, this.z * scale, 0);
|
|
369
328
|
}
|
|
370
329
|
|
|
371
330
|
/**
|
|
@@ -376,10 +335,10 @@ export class Vec4 {
|
|
|
376
335
|
*/
|
|
377
336
|
projectStereographic(options = {}) {
|
|
378
337
|
const epsilon = options.epsilon ?? 1e-5;
|
|
379
|
-
const denom = 1 - this.
|
|
338
|
+
const denom = 1 - this.w;
|
|
380
339
|
const clamped = Math.abs(denom) < epsilon ? (denom >= 0 ? epsilon : -epsilon) : denom;
|
|
381
340
|
const scale = 1 / clamped;
|
|
382
|
-
return new Vec4(this.
|
|
341
|
+
return new Vec4(this.x * scale, this.y * scale, this.z * scale, 0);
|
|
383
342
|
}
|
|
384
343
|
|
|
385
344
|
/**
|
|
@@ -388,7 +347,7 @@ export class Vec4 {
|
|
|
388
347
|
* @returns {Vec4} Projected point (w component is 0)
|
|
389
348
|
*/
|
|
390
349
|
projectOrthographic() {
|
|
391
|
-
return new Vec4(this.
|
|
350
|
+
return new Vec4(this.x, this.y, this.z, 0);
|
|
392
351
|
}
|
|
393
352
|
|
|
394
353
|
/**
|
|
@@ -396,7 +355,7 @@ export class Vec4 {
|
|
|
396
355
|
* @returns {number[]}
|
|
397
356
|
*/
|
|
398
357
|
toArray() {
|
|
399
|
-
return [this.
|
|
358
|
+
return [this.x, this.y, this.z, this.w];
|
|
400
359
|
}
|
|
401
360
|
|
|
402
361
|
/**
|
|
@@ -404,7 +363,7 @@ export class Vec4 {
|
|
|
404
363
|
* @returns {Float32Array}
|
|
405
364
|
*/
|
|
406
365
|
toFloat32Array() {
|
|
407
|
-
return new Float32Array(
|
|
366
|
+
return new Float32Array(this.data);
|
|
408
367
|
}
|
|
409
368
|
|
|
410
369
|
/**
|
|
@@ -412,7 +371,7 @@ export class Vec4 {
|
|
|
412
371
|
* @returns {number[]}
|
|
413
372
|
*/
|
|
414
373
|
toArray3() {
|
|
415
|
-
return [this.
|
|
374
|
+
return [this.x, this.y, this.z];
|
|
416
375
|
}
|
|
417
376
|
|
|
418
377
|
/**
|
|
@@ -421,7 +380,7 @@ export class Vec4 {
|
|
|
421
380
|
* @returns {string}
|
|
422
381
|
*/
|
|
423
382
|
toString(precision = 3) {
|
|
424
|
-
return `Vec4(${this.
|
|
383
|
+
return `Vec4(${this.x.toFixed(precision)}, ${this.y.toFixed(precision)}, ${this.z.toFixed(precision)}, ${this.w.toFixed(precision)})`;
|
|
425
384
|
}
|
|
426
385
|
|
|
427
386
|
/**
|
|
@@ -429,7 +388,7 @@ export class Vec4 {
|
|
|
429
388
|
* @returns {object}
|
|
430
389
|
*/
|
|
431
390
|
toJSON() {
|
|
432
|
-
return { x: this.
|
|
391
|
+
return { x: this.x, y: this.y, z: this.z, w: this.w };
|
|
433
392
|
}
|
|
434
393
|
|
|
435
394
|
// Static factory methods for common vectors
|