@vib3code/sdk 2.0.1 → 2.0.3-canary.0a63e71
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/CHANGELOG.md +36 -0
- package/DOCS/AGENT_HARNESS_ARCHITECTURE.md +245 -0
- package/DOCS/ANDROID_DEPLOYMENT.md +59 -0
- package/DOCS/ARCHITECTURE.md +1 -0
- package/DOCS/CI_TESTING.md +2 -0
- package/DOCS/CLI_ONBOARDING.md +3 -1
- package/DOCS/CONTROL_REFERENCE.md +2 -0
- package/DOCS/CROSS_SITE_DESIGN_PATTERNS.md +119 -0
- package/DOCS/ENV_SETUP.md +2 -0
- package/DOCS/EPIC_SCROLL_EVENTS.md +775 -0
- package/DOCS/EXPANSION_DESIGN.md +979 -0
- package/DOCS/EXPANSION_DESIGN_ULTRA.md +389 -0
- package/DOCS/EXPORT_FORMATS.md +2 -0
- package/DOCS/GPU_DISPOSAL_GUIDE.md +2 -0
- package/DOCS/HANDOFF_LANDING_PAGE.md +156 -0
- package/DOCS/HANDOFF_SDK_DEVELOPMENT.md +495 -0
- package/DOCS/LICENSING_TIERS.md +2 -0
- package/DOCS/MASTER_PLAN_2026-01-31.md +4 -2
- package/DOCS/MULTIVIZ_CHOREOGRAPHY_PATTERNS.md +939 -0
- package/DOCS/OBS_SETUP_GUIDE.md +2 -0
- package/DOCS/OPTIMIZATION_PLAN_MATH.md +119 -0
- package/DOCS/PRODUCT_STRATEGY.md +65 -0
- package/DOCS/PROJECT_SETUP.md +2 -0
- package/DOCS/README.md +105 -0
- package/DOCS/REFERENCE_SCROLL_ANALYSIS.md +99 -0
- package/DOCS/RENDERER_LIFECYCLE.md +2 -0
- package/DOCS/REPO_MANIFEST.md +2 -0
- package/DOCS/ROADMAP.md +113 -0
- package/DOCS/SCROLL_TIMELINE_v3.md +271 -0
- package/DOCS/SITE_REFACTOR_PLAN.md +102 -0
- package/DOCS/STATUS.md +26 -0
- package/DOCS/SYSTEM_INVENTORY.md +37 -32
- package/DOCS/TELEMETRY_EXPORTS.md +2 -0
- package/DOCS/VISUAL_ANALYSIS_CLICKERSS.md +87 -0
- package/DOCS/VISUAL_ANALYSIS_FACETAD.md +135 -0
- package/DOCS/VISUAL_ANALYSIS_SIMONE.md +97 -0
- package/DOCS/VISUAL_ANALYSIS_TABLESIDE.md +88 -0
- package/DOCS/WEBGPU_STATUS.md +121 -38
- package/DOCS/XR_BENCHMARKS.md +2 -0
- package/DOCS/archive/BLUEPRINT_EXECUTION_PLAN_2026-01-07.md +1 -0
- package/DOCS/archive/DEV_TRACK_ANALYSIS.md +1 -0
- package/DOCS/archive/DEV_TRACK_PLAN_2026-01-07.md +1 -0
- package/DOCS/archive/SESSION_014_PLAN.md +1 -0
- package/DOCS/archive/SESSION_LOG_2026-01-07.md +1 -0
- package/DOCS/archive/STRATEGIC_BLUEPRINT_2026-01-07.md +1 -0
- package/DOCS/archive/SYSTEM_AUDIT_2026-01-30.md +1 -0
- package/DOCS/archive/WEBGPU_STATUS_2026-02-15_STALE.md +1 -0
- package/DOCS/{DEV_TRACK_SESSION_2026-01-31.md → dev-tracks/DEV_TRACK_SESSION_2026-01-31.md} +3 -1
- package/DOCS/dev-tracks/DEV_TRACK_SESSION_2026-02-06.md +233 -0
- package/DOCS/dev-tracks/DEV_TRACK_SESSION_2026-02-13.md +129 -0
- package/DOCS/dev-tracks/DEV_TRACK_SESSION_2026-02-15.md +144 -0
- package/DOCS/dev-tracks/DEV_TRACK_SESSION_2026-02-16.md +110 -0
- package/DOCS/dev-tracks/PERF_UPGRADE_2026-02-16.md +310 -0
- package/DOCS/dev-tracks/README.md +12 -0
- package/README.md +26 -13
- package/cpp/CMakeLists.txt +236 -0
- package/cpp/bindings/embind.cpp +269 -0
- package/cpp/build.sh +129 -0
- package/cpp/geometry/Crystal.cpp +103 -0
- package/cpp/geometry/Fractal.cpp +136 -0
- package/cpp/geometry/GeometryGenerator.cpp +262 -0
- package/cpp/geometry/KleinBottle.cpp +71 -0
- package/cpp/geometry/Sphere.cpp +134 -0
- package/cpp/geometry/Tesseract.cpp +94 -0
- package/cpp/geometry/Tetrahedron.cpp +83 -0
- package/cpp/geometry/Torus.cpp +65 -0
- package/cpp/geometry/WarpFunctions.cpp +238 -0
- package/cpp/geometry/Wave.cpp +85 -0
- package/cpp/include/vib3_ffi.h +238 -0
- package/cpp/math/Mat4x4.cpp +409 -0
- package/cpp/math/Mat4x4.hpp +209 -0
- package/cpp/math/Projection.cpp +142 -0
- package/cpp/math/Projection.hpp +148 -0
- package/cpp/math/Rotor4D.cpp +322 -0
- package/cpp/math/Rotor4D.hpp +204 -0
- package/cpp/math/Vec4.cpp +303 -0
- package/cpp/math/Vec4.hpp +225 -0
- package/cpp/src/vib3_ffi.cpp +607 -0
- package/cpp/tests/Geometry_test.cpp +213 -0
- package/cpp/tests/Mat4x4_test.cpp +494 -0
- package/cpp/tests/Projection_test.cpp +298 -0
- package/cpp/tests/Rotor4D_test.cpp +423 -0
- package/cpp/tests/Vec4_test.cpp +489 -0
- package/docs/webgpu-live.html +1 -1
- package/package.json +41 -30
- package/src/agent/index.js +1 -3
- package/src/agent/mcp/MCPServer.js +1220 -144
- package/src/agent/mcp/index.js +1 -1
- package/src/agent/mcp/stdio-server.js +264 -0
- package/src/agent/mcp/tools.js +498 -31
- package/src/cli/index.js +431 -47
- package/src/core/CanvasManager.js +97 -204
- package/src/core/ErrorReporter.js +1 -1
- package/src/core/Parameters.js +1 -1
- package/src/core/VIB3Engine.js +93 -4
- package/src/core/VitalitySystem.js +53 -0
- package/src/core/index.js +18 -0
- package/src/core/renderers/FacetedRendererAdapter.js +10 -9
- package/src/core/renderers/HolographicRendererAdapter.js +13 -9
- package/src/core/renderers/QuantumRendererAdapter.js +11 -7
- package/src/creative/AestheticMapper.js +628 -0
- package/src/creative/ChoreographyPlayer.js +481 -0
- package/src/creative/index.js +11 -0
- package/src/experimental/GameLoop.js +72 -0
- package/src/experimental/LatticePhysics.js +100 -0
- package/src/experimental/LiveDirector.js +143 -0
- package/src/experimental/PlayerController4D.js +154 -0
- package/src/experimental/VIB3Actor.js +138 -0
- package/src/experimental/VIB3Compositor.js +117 -0
- package/src/experimental/VIB3Link.js +122 -0
- package/src/experimental/VIB3Orchestrator.js +146 -0
- package/src/experimental/VIB3Universe.js +109 -0
- package/src/experimental/demos/CrystalLabyrinth.js +202 -0
- package/src/export/TradingCardManager.js +3 -4
- package/src/export/index.js +11 -1
- package/src/faceted/FacetedSystem.js +260 -394
- package/src/games/glyph-war/GlyphWarVisualizer.js +641 -0
- package/src/geometry/generators/Crystal.js +2 -2
- package/src/geometry/warp/HypersphereCore.js +53 -24
- package/src/holograms/HolographicVisualizer.js +84 -98
- package/src/holograms/RealHolographicSystem.js +194 -43
- package/src/math/Mat4x4.js +308 -105
- package/src/math/Rotor4D.js +124 -40
- package/src/math/Vec4.js +200 -103
- package/src/math/index.js +7 -7
- package/src/polychora/PolychoraSystem.js +77 -0
- package/src/quantum/QuantumEngine.js +103 -66
- package/src/quantum/QuantumVisualizer.js +31 -22
- package/src/reactivity/index.js +3 -5
- package/src/render/LayerPresetManager.js +372 -0
- package/src/render/LayerReactivityBridge.js +344 -0
- package/src/render/LayerRelationshipGraph.js +610 -0
- package/src/render/MultiCanvasBridge.js +148 -25
- package/src/render/ShaderLoader.js +38 -0
- package/src/render/ShaderProgram.js +4 -4
- package/src/render/UnifiedRenderBridge.js +4 -1
- package/src/render/backends/WebGPUBackend.js +8 -4
- package/src/render/index.js +27 -2
- package/src/scene/Node4D.js +74 -24
- package/src/scene/index.js +4 -4
- package/src/shaders/common/geometry24.glsl +65 -0
- package/src/shaders/common/geometry24.wgsl +54 -0
- package/src/shaders/common/rotation4d.glsl +4 -4
- package/src/shaders/common/rotation4d.wgsl +2 -2
- package/src/shaders/common/uniforms.wgsl +15 -8
- package/src/shaders/faceted/faceted.frag.glsl +220 -80
- package/src/shaders/faceted/faceted.frag.wgsl +144 -90
- package/src/shaders/holographic/holographic.frag.glsl +28 -9
- package/src/shaders/holographic/holographic.frag.wgsl +112 -41
- package/src/shaders/quantum/quantum.frag.glsl +1 -0
- package/src/shaders/quantum/quantum.frag.wgsl +6 -4
- package/src/testing/ParallelTestFramework.js +2 -2
- package/src/ui/adaptive/renderers/webgpu/WebGPURenderer.ts +2 -2
- package/src/viewer/GalleryUI.js +17 -0
- package/src/viewer/ViewerPortal.js +2 -2
- package/src/viewer/index.js +1 -1
- package/tools/headless-renderer.js +258 -0
- package/tools/shader-sync-verify.js +14 -8
- package/tools/site-analysis/all-reports.json +32 -0
- package/tools/site-analysis/combined-analysis.md +50 -0
- package/tools/site-analyzer.mjs +779 -0
- package/tools/visual-catalog/capture.js +276 -0
- package/tools/visual-catalog/composite.js +138 -0
- package/types/adaptive-sdk.d.ts +204 -5
- package/types/agent/cli.d.ts +78 -0
- package/types/agent/index.d.ts +18 -0
- package/types/agent/mcp.d.ts +87 -0
- package/types/agent/telemetry.d.ts +190 -0
- package/types/core/VIB3Engine.d.ts +26 -0
- package/types/core/index.d.ts +261 -0
- package/types/creative/AestheticMapper.d.ts +72 -0
- package/types/creative/ChoreographyPlayer.d.ts +96 -0
- package/types/creative/index.d.ts +17 -0
- package/types/export/index.d.ts +243 -0
- package/types/geometry/index.d.ts +164 -0
- package/types/math/index.d.ts +214 -0
- package/types/render/LayerPresetManager.d.ts +78 -0
- package/types/render/LayerReactivityBridge.d.ts +85 -0
- package/types/render/LayerRelationshipGraph.d.ts +174 -0
- package/types/render/index.d.ts +3 -0
- package/types/scene/index.d.ts +204 -0
- package/types/systems/index.d.ts +244 -0
- package/types/variations/index.d.ts +62 -0
- package/types/viewer/index.d.ts +225 -0
- package/DOCS/BLUEPRINT_EXECUTION_PLAN_2026-01-07.md +0 -34
- package/DOCS/DEV_TRACK_ANALYSIS.md +0 -77
- package/DOCS/DEV_TRACK_PLAN_2026-01-07.md +0 -42
- package/DOCS/SESSION_014_PLAN.md +0 -195
- package/DOCS/SESSION_LOG_2026-01-07.md +0 -56
- package/DOCS/STRATEGIC_BLUEPRINT_2026-01-07.md +0 -72
- package/DOCS/SYSTEM_AUDIT_2026-01-30.md +0 -738
- /package/src/viewer/{ReactivityManager.js → ViewerInputHandler.js} +0 -0
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rotor4D.hpp - 4D Rotor for VIB3+ SDK
|
|
3
|
+
*
|
|
4
|
+
* 8-component rotor for proper 4D rotation using geometric algebra.
|
|
5
|
+
* Components: scalar + 6 bivectors (XY, XZ, YZ, XW, YW, ZW) + pseudoscalar
|
|
6
|
+
*
|
|
7
|
+
* Unlike quaternions (which work for 3D), rotors handle all 6 rotation planes.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
#pragma once
|
|
11
|
+
|
|
12
|
+
#include "Vec4.hpp"
|
|
13
|
+
#include "Mat4x4.hpp"
|
|
14
|
+
#include <array>
|
|
15
|
+
|
|
16
|
+
namespace vib3 {
|
|
17
|
+
|
|
18
|
+
// Forward declaration
|
|
19
|
+
class Mat4x4;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Rotation plane identifiers
|
|
23
|
+
*/
|
|
24
|
+
enum class RotationPlane {
|
|
25
|
+
XY = 0, // 3D rotation around Z
|
|
26
|
+
XZ = 1, // 3D rotation around Y
|
|
27
|
+
YZ = 2, // 3D rotation around X
|
|
28
|
+
XW = 3, // 4D rotation (X-W plane)
|
|
29
|
+
YW = 4, // 4D rotation (Y-W plane)
|
|
30
|
+
ZW = 5 // 4D rotation (Z-W plane)
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* 4D Rotor class
|
|
35
|
+
*
|
|
36
|
+
* Components:
|
|
37
|
+
* - s: scalar part
|
|
38
|
+
* - xy: XY bivector (rotation in XY plane)
|
|
39
|
+
* - xz: XZ bivector (rotation in XZ plane)
|
|
40
|
+
* - yz: YZ bivector (rotation in YZ plane)
|
|
41
|
+
* - xw: XW bivector (rotation in XW plane)
|
|
42
|
+
* - yw: YW bivector (rotation in YW plane)
|
|
43
|
+
* - zw: ZW bivector (rotation in ZW plane)
|
|
44
|
+
* - xyzw: pseudoscalar (4D volume element)
|
|
45
|
+
*/
|
|
46
|
+
class Rotor4D {
|
|
47
|
+
public:
|
|
48
|
+
float s; // Scalar
|
|
49
|
+
float xy; // Bivector XY
|
|
50
|
+
float xz; // Bivector XZ
|
|
51
|
+
float yz; // Bivector YZ
|
|
52
|
+
float xw; // Bivector XW
|
|
53
|
+
float yw; // Bivector YW
|
|
54
|
+
float zw; // Bivector ZW
|
|
55
|
+
float xyzw; // Pseudoscalar
|
|
56
|
+
|
|
57
|
+
// Constructors
|
|
58
|
+
constexpr Rotor4D() noexcept
|
|
59
|
+
: s(1), xy(0), xz(0), yz(0), xw(0), yw(0), zw(0), xyzw(0) {}
|
|
60
|
+
|
|
61
|
+
constexpr Rotor4D(float s, float xy, float xz, float yz,
|
|
62
|
+
float xw, float yw, float zw, float xyzw) noexcept
|
|
63
|
+
: s(s), xy(xy), xz(xz), yz(yz), xw(xw), yw(yw), zw(zw), xyzw(xyzw) {}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Identity rotor (no rotation)
|
|
67
|
+
*/
|
|
68
|
+
static constexpr Rotor4D identity() noexcept {
|
|
69
|
+
return Rotor4D(1, 0, 0, 0, 0, 0, 0, 0);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Create rotor from rotation in a single plane
|
|
74
|
+
* @param plane The rotation plane
|
|
75
|
+
* @param angle Rotation angle in radians
|
|
76
|
+
*/
|
|
77
|
+
static Rotor4D fromPlaneAngle(RotationPlane plane, float angle) noexcept;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Create rotor from 6 Euler-like angles (one per plane)
|
|
81
|
+
* @param angles Array of 6 angles [XY, XZ, YZ, XW, YW, ZW]
|
|
82
|
+
*/
|
|
83
|
+
static Rotor4D fromEuler6(const std::array<float, 6>& angles) noexcept;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Create rotor from 6 individual angles
|
|
87
|
+
*/
|
|
88
|
+
static Rotor4D fromEuler6(float xy, float xz, float yz,
|
|
89
|
+
float xw, float yw, float zw) noexcept;
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Get all components as array
|
|
93
|
+
*/
|
|
94
|
+
std::array<float, 8> toArray() const noexcept;
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Set all components from array
|
|
98
|
+
*/
|
|
99
|
+
void fromArray(const std::array<float, 8>& arr) noexcept;
|
|
100
|
+
|
|
101
|
+
// Rotor operations
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Rotor multiplication (composition)
|
|
105
|
+
*/
|
|
106
|
+
Rotor4D operator*(const Rotor4D& other) const noexcept;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Compound multiplication
|
|
110
|
+
*/
|
|
111
|
+
Rotor4D& operator*=(const Rotor4D& other) noexcept;
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Reverse (conjugate) - reverses rotation direction
|
|
115
|
+
*/
|
|
116
|
+
Rotor4D reverse() const noexcept;
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Squared magnitude
|
|
120
|
+
*/
|
|
121
|
+
float magnitudeSquared() const noexcept;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Magnitude (norm)
|
|
125
|
+
*/
|
|
126
|
+
float magnitude() const noexcept;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Normalize to unit rotor
|
|
130
|
+
*/
|
|
131
|
+
Rotor4D normalized() const noexcept;
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Normalize in place
|
|
135
|
+
*/
|
|
136
|
+
void normalize() noexcept;
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Inverse rotor
|
|
140
|
+
*/
|
|
141
|
+
Rotor4D inverse() const noexcept;
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Check if approximately unit rotor
|
|
145
|
+
*/
|
|
146
|
+
bool isNormalized(float epsilon = 1e-5f) const noexcept;
|
|
147
|
+
|
|
148
|
+
// Vector rotation
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Rotate a 4D vector: v' = R * v * R†
|
|
152
|
+
*/
|
|
153
|
+
Vec4 rotate(const Vec4& v) const noexcept;
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Rotate a 4D vector (in place)
|
|
157
|
+
*/
|
|
158
|
+
void rotateInPlace(Vec4& v) const noexcept;
|
|
159
|
+
|
|
160
|
+
// Interpolation
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Spherical linear interpolation
|
|
164
|
+
*/
|
|
165
|
+
Rotor4D slerp(const Rotor4D& other, float t) const noexcept;
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Normalized linear interpolation (faster but less accurate)
|
|
169
|
+
*/
|
|
170
|
+
Rotor4D nlerp(const Rotor4D& other, float t) const noexcept;
|
|
171
|
+
|
|
172
|
+
// Matrix conversion
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Convert to 4x4 rotation matrix
|
|
176
|
+
*/
|
|
177
|
+
Mat4x4 toMatrix() const noexcept;
|
|
178
|
+
|
|
179
|
+
// Comparison
|
|
180
|
+
|
|
181
|
+
bool operator==(const Rotor4D& other) const noexcept;
|
|
182
|
+
bool operator!=(const Rotor4D& other) const noexcept;
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Dot product between rotors (for slerp)
|
|
186
|
+
*/
|
|
187
|
+
float dot(const Rotor4D& other) const noexcept;
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Compose two rotations
|
|
192
|
+
*/
|
|
193
|
+
inline Rotor4D compose(const Rotor4D& first, const Rotor4D& second) noexcept {
|
|
194
|
+
return first * second;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Slerp free function
|
|
199
|
+
*/
|
|
200
|
+
inline Rotor4D slerp(const Rotor4D& a, const Rotor4D& b, float t) noexcept {
|
|
201
|
+
return a.slerp(b, t);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
} // namespace vib3
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vec4.cpp - 4D Vector Implementation
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
#include "Vec4.hpp"
|
|
6
|
+
#include <random>
|
|
7
|
+
#include <limits>
|
|
8
|
+
|
|
9
|
+
namespace vib3 {
|
|
10
|
+
|
|
11
|
+
// Static random generator for randomUnit()
|
|
12
|
+
static std::mt19937& getRandomEngine() {
|
|
13
|
+
static std::random_device rd;
|
|
14
|
+
static std::mt19937 gen(rd());
|
|
15
|
+
return gen;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
Vec4 Vec4::randomUnit() noexcept {
|
|
19
|
+
// Marsaglia method for uniform distribution on S³
|
|
20
|
+
std::normal_distribution<float> dist(0.0f, 1.0f);
|
|
21
|
+
auto& gen = getRandomEngine();
|
|
22
|
+
|
|
23
|
+
Vec4 v(dist(gen), dist(gen), dist(gen), dist(gen));
|
|
24
|
+
v.normalize();
|
|
25
|
+
return v;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Arithmetic operators
|
|
29
|
+
|
|
30
|
+
#if defined(VIB3_HAS_SSE41)
|
|
31
|
+
|
|
32
|
+
Vec4 Vec4::operator+(const Vec4& other) const noexcept {
|
|
33
|
+
return Vec4(_mm_add_ps(simd, other.simd));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
Vec4 Vec4::operator-(const Vec4& other) const noexcept {
|
|
37
|
+
return Vec4(_mm_sub_ps(simd, other.simd));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
Vec4 Vec4::operator*(float scalar) const noexcept {
|
|
41
|
+
return Vec4(_mm_mul_ps(simd, _mm_set1_ps(scalar)));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
Vec4 Vec4::operator/(float scalar) const noexcept {
|
|
45
|
+
return Vec4(_mm_div_ps(simd, _mm_set1_ps(scalar)));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
Vec4 Vec4::operator-() const noexcept {
|
|
49
|
+
return Vec4(_mm_xor_ps(simd, _mm_set1_ps(-0.0f)));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
float Vec4::dot(const Vec4& other) const noexcept {
|
|
53
|
+
__m128 mul = _mm_mul_ps(simd, other.simd);
|
|
54
|
+
__m128 sum = _mm_hadd_ps(mul, mul);
|
|
55
|
+
sum = _mm_hadd_ps(sum, sum);
|
|
56
|
+
return _mm_cvtss_f32(sum);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
Vec4 Vec4::min(const Vec4& other) const noexcept {
|
|
60
|
+
return Vec4(_mm_min_ps(simd, other.simd));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
Vec4 Vec4::max(const Vec4& other) const noexcept {
|
|
64
|
+
return Vec4(_mm_max_ps(simd, other.simd));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
Vec4 Vec4::abs() const noexcept {
|
|
68
|
+
__m128 mask = _mm_castsi128_ps(_mm_set1_epi32(0x7FFFFFFF));
|
|
69
|
+
return Vec4(_mm_and_ps(simd, mask));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
#elif defined(__EMSCRIPTEN__)
|
|
73
|
+
|
|
74
|
+
Vec4 Vec4::operator+(const Vec4& other) const noexcept {
|
|
75
|
+
return Vec4(wasm_f32x4_add(simd, other.simd));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
Vec4 Vec4::operator-(const Vec4& other) const noexcept {
|
|
79
|
+
return Vec4(wasm_f32x4_sub(simd, other.simd));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
Vec4 Vec4::operator*(float scalar) const noexcept {
|
|
83
|
+
return Vec4(wasm_f32x4_mul(simd, wasm_f32x4_splat(scalar)));
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
Vec4 Vec4::operator/(float scalar) const noexcept {
|
|
87
|
+
return Vec4(wasm_f32x4_div(simd, wasm_f32x4_splat(scalar)));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
Vec4 Vec4::operator-() const noexcept {
|
|
91
|
+
return Vec4(wasm_f32x4_neg(simd));
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
float Vec4::dot(const Vec4& other) const noexcept {
|
|
95
|
+
v128_t mul = wasm_f32x4_mul(simd, other.simd);
|
|
96
|
+
return wasm_f32x4_extract_lane(mul, 0) +
|
|
97
|
+
wasm_f32x4_extract_lane(mul, 1) +
|
|
98
|
+
wasm_f32x4_extract_lane(mul, 2) +
|
|
99
|
+
wasm_f32x4_extract_lane(mul, 3);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
Vec4 Vec4::min(const Vec4& other) const noexcept {
|
|
103
|
+
return Vec4(wasm_f32x4_min(simd, other.simd));
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
Vec4 Vec4::max(const Vec4& other) const noexcept {
|
|
107
|
+
return Vec4(wasm_f32x4_max(simd, other.simd));
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
Vec4 Vec4::abs() const noexcept {
|
|
111
|
+
return Vec4(wasm_f32x4_abs(simd));
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
#else
|
|
115
|
+
// Scalar fallback
|
|
116
|
+
|
|
117
|
+
Vec4 Vec4::operator+(const Vec4& other) const noexcept {
|
|
118
|
+
return Vec4(x + other.x, y + other.y, z + other.z, w + other.w);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
Vec4 Vec4::operator-(const Vec4& other) const noexcept {
|
|
122
|
+
return Vec4(x - other.x, y - other.y, z - other.z, w - other.w);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
Vec4 Vec4::operator*(float scalar) const noexcept {
|
|
126
|
+
return Vec4(x * scalar, y * scalar, z * scalar, w * scalar);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
Vec4 Vec4::operator/(float scalar) const noexcept {
|
|
130
|
+
float inv = 1.0f / scalar;
|
|
131
|
+
return Vec4(x * inv, y * inv, z * inv, w * inv);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
Vec4 Vec4::operator-() const noexcept {
|
|
135
|
+
return Vec4(-x, -y, -z, -w);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
float Vec4::dot(const Vec4& other) const noexcept {
|
|
139
|
+
return x * other.x + y * other.y + z * other.z + w * other.w;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
Vec4 Vec4::min(const Vec4& other) const noexcept {
|
|
143
|
+
return Vec4(
|
|
144
|
+
std::min(x, other.x),
|
|
145
|
+
std::min(y, other.y),
|
|
146
|
+
std::min(z, other.z),
|
|
147
|
+
std::min(w, other.w)
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
Vec4 Vec4::max(const Vec4& other) const noexcept {
|
|
152
|
+
return Vec4(
|
|
153
|
+
std::max(x, other.x),
|
|
154
|
+
std::max(y, other.y),
|
|
155
|
+
std::max(z, other.z),
|
|
156
|
+
std::max(w, other.w)
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
Vec4 Vec4::abs() const noexcept {
|
|
161
|
+
return Vec4(std::abs(x), std::abs(y), std::abs(z), std::abs(w));
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
#endif
|
|
165
|
+
|
|
166
|
+
// Compound assignment (always scalar for simplicity)
|
|
167
|
+
|
|
168
|
+
Vec4& Vec4::operator+=(const Vec4& other) noexcept {
|
|
169
|
+
*this = *this + other;
|
|
170
|
+
return *this;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
Vec4& Vec4::operator-=(const Vec4& other) noexcept {
|
|
174
|
+
*this = *this - other;
|
|
175
|
+
return *this;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
Vec4& Vec4::operator*=(float scalar) noexcept {
|
|
179
|
+
*this = *this * scalar;
|
|
180
|
+
return *this;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
Vec4& Vec4::operator/=(float scalar) noexcept {
|
|
184
|
+
*this = *this / scalar;
|
|
185
|
+
return *this;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// Comparison
|
|
189
|
+
|
|
190
|
+
bool Vec4::operator==(const Vec4& other) const noexcept {
|
|
191
|
+
return x == other.x && y == other.y && z == other.z && w == other.w;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
bool Vec4::operator!=(const Vec4& other) const noexcept {
|
|
195
|
+
return !(*this == other);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// Length and normalization
|
|
199
|
+
|
|
200
|
+
float Vec4::lengthSquared() const noexcept {
|
|
201
|
+
return dot(*this);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
float Vec4::length() const noexcept {
|
|
205
|
+
return std::sqrt(lengthSquared());
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
Vec4 Vec4::normalized() const noexcept {
|
|
209
|
+
float len = length();
|
|
210
|
+
if (len > 0) {
|
|
211
|
+
return *this / len;
|
|
212
|
+
}
|
|
213
|
+
return Vec4::zero();
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
void Vec4::normalize() noexcept {
|
|
217
|
+
float len = length();
|
|
218
|
+
if (len > 0) {
|
|
219
|
+
*this /= len;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// Distance
|
|
224
|
+
|
|
225
|
+
float Vec4::distanceTo(const Vec4& other) const noexcept {
|
|
226
|
+
return (*this - other).length();
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
float Vec4::distanceSquaredTo(const Vec4& other) const noexcept {
|
|
230
|
+
return (*this - other).lengthSquared();
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// Interpolation
|
|
234
|
+
|
|
235
|
+
Vec4 Vec4::lerp(const Vec4& other, float t) const noexcept {
|
|
236
|
+
return *this + (other - *this) * t;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// Clamp
|
|
240
|
+
|
|
241
|
+
Vec4 Vec4::clamp(const Vec4& minVal, const Vec4& maxVal) const noexcept {
|
|
242
|
+
return this->max(minVal).min(maxVal);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// Projection and reflection
|
|
246
|
+
|
|
247
|
+
Vec4 Vec4::projectOnto(const Vec4& other) const noexcept {
|
|
248
|
+
float d = other.dot(other);
|
|
249
|
+
if (d > 0) {
|
|
250
|
+
return other * (dot(other) / d);
|
|
251
|
+
}
|
|
252
|
+
return Vec4::zero();
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
Vec4 Vec4::reflect(const Vec4& normal) const noexcept {
|
|
256
|
+
return *this - normal * (2.0f * dot(normal));
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// Validation
|
|
260
|
+
|
|
261
|
+
bool Vec4::isZero(float epsilon) const noexcept {
|
|
262
|
+
return lengthSquared() < epsilon * epsilon;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
bool Vec4::isNormalized(float epsilon) const noexcept {
|
|
266
|
+
return std::abs(lengthSquared() - 1.0f) < epsilon;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
// 4D -> 3D Projections
|
|
270
|
+
|
|
271
|
+
std::array<float, 3> Vec4::projectPerspective(float distance) const noexcept {
|
|
272
|
+
float denom = distance - w;
|
|
273
|
+
|
|
274
|
+
// Handle singularity
|
|
275
|
+
if (std::abs(denom) < 1e-6f) {
|
|
276
|
+
float sign = (denom >= 0) ? 1.0f : -1.0f;
|
|
277
|
+
constexpr float large = 1e6f;
|
|
278
|
+
return {x * sign * large, y * sign * large, z * sign * large};
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
float factor = distance / denom;
|
|
282
|
+
return {x * factor, y * factor, z * factor};
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
std::array<float, 3> Vec4::projectStereographic() const noexcept {
|
|
286
|
+
float denom = 1.0f - w;
|
|
287
|
+
|
|
288
|
+
// Handle singularity at w = 1
|
|
289
|
+
if (std::abs(denom) < 1e-6f) {
|
|
290
|
+
constexpr float large = 1e6f;
|
|
291
|
+
float sign = (x + y + z >= 0) ? 1.0f : -1.0f;
|
|
292
|
+
return {sign * large, sign * large, sign * large};
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
float factor = 1.0f / denom;
|
|
296
|
+
return {x * factor, y * factor, z * factor};
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
std::array<float, 3> Vec4::projectOrthographic() const noexcept {
|
|
300
|
+
return {x, y, z};
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
} // namespace vib3
|