@vib3code/sdk 2.0.1 → 2.0.3-canary.6f35b4c

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.
Files changed (96) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/DOCS/AGENT_HARNESS_ARCHITECTURE.md +243 -0
  3. package/DOCS/CLI_ONBOARDING.md +1 -1
  4. package/DOCS/CROSS_SITE_DESIGN_PATTERNS.md +117 -0
  5. package/DOCS/EPIC_SCROLL_EVENTS.md +773 -0
  6. package/DOCS/HANDOFF_LANDING_PAGE.md +154 -0
  7. package/DOCS/HANDOFF_SDK_DEVELOPMENT.md +493 -0
  8. package/DOCS/MULTIVIZ_CHOREOGRAPHY_PATTERNS.md +937 -0
  9. package/DOCS/PRODUCT_STRATEGY.md +63 -0
  10. package/DOCS/README.md +103 -0
  11. package/DOCS/REFERENCE_SCROLL_ANALYSIS.md +97 -0
  12. package/DOCS/ROADMAP.md +111 -0
  13. package/DOCS/SCROLL_TIMELINE_v3.md +269 -0
  14. package/DOCS/SITE_REFACTOR_PLAN.md +100 -0
  15. package/DOCS/STATUS.md +24 -0
  16. package/DOCS/SYSTEM_INVENTORY.md +33 -30
  17. package/DOCS/VISUAL_ANALYSIS_CLICKERSS.md +85 -0
  18. package/DOCS/VISUAL_ANALYSIS_FACETAD.md +133 -0
  19. package/DOCS/VISUAL_ANALYSIS_SIMONE.md +95 -0
  20. package/DOCS/VISUAL_ANALYSIS_TABLESIDE.md +86 -0
  21. package/DOCS/{BLUEPRINT_EXECUTION_PLAN_2026-01-07.md → archive/BLUEPRINT_EXECUTION_PLAN_2026-01-07.md} +1 -1
  22. package/DOCS/{DEV_TRACK_ANALYSIS.md → archive/DEV_TRACK_ANALYSIS.md} +3 -0
  23. package/DOCS/{SYSTEM_AUDIT_2026-01-30.md → archive/SYSTEM_AUDIT_2026-01-30.md} +3 -0
  24. package/DOCS/{DEV_TRACK_SESSION_2026-01-31.md → dev-tracks/DEV_TRACK_SESSION_2026-01-31.md} +1 -1
  25. package/DOCS/dev-tracks/DEV_TRACK_SESSION_2026-02-06.md +231 -0
  26. package/DOCS/dev-tracks/DEV_TRACK_SESSION_2026-02-13.md +127 -0
  27. package/DOCS/dev-tracks/README.md +10 -0
  28. package/README.md +26 -13
  29. package/cpp/CMakeLists.txt +236 -0
  30. package/cpp/bindings/embind.cpp +269 -0
  31. package/cpp/build.sh +129 -0
  32. package/cpp/geometry/Crystal.cpp +103 -0
  33. package/cpp/geometry/Fractal.cpp +136 -0
  34. package/cpp/geometry/GeometryGenerator.cpp +262 -0
  35. package/cpp/geometry/KleinBottle.cpp +71 -0
  36. package/cpp/geometry/Sphere.cpp +134 -0
  37. package/cpp/geometry/Tesseract.cpp +94 -0
  38. package/cpp/geometry/Tetrahedron.cpp +83 -0
  39. package/cpp/geometry/Torus.cpp +65 -0
  40. package/cpp/geometry/WarpFunctions.cpp +238 -0
  41. package/cpp/geometry/Wave.cpp +85 -0
  42. package/cpp/include/vib3_ffi.h +238 -0
  43. package/cpp/math/Mat4x4.cpp +409 -0
  44. package/cpp/math/Mat4x4.hpp +209 -0
  45. package/cpp/math/Projection.cpp +142 -0
  46. package/cpp/math/Projection.hpp +148 -0
  47. package/cpp/math/Rotor4D.cpp +322 -0
  48. package/cpp/math/Rotor4D.hpp +204 -0
  49. package/cpp/math/Vec4.cpp +303 -0
  50. package/cpp/math/Vec4.hpp +225 -0
  51. package/cpp/src/vib3_ffi.cpp +607 -0
  52. package/cpp/tests/Geometry_test.cpp +213 -0
  53. package/cpp/tests/Mat4x4_test.cpp +494 -0
  54. package/cpp/tests/Projection_test.cpp +298 -0
  55. package/cpp/tests/Rotor4D_test.cpp +423 -0
  56. package/cpp/tests/Vec4_test.cpp +489 -0
  57. package/package.json +31 -27
  58. package/src/agent/mcp/MCPServer.js +722 -0
  59. package/src/agent/mcp/stdio-server.js +264 -0
  60. package/src/agent/mcp/tools.js +367 -0
  61. package/src/cli/index.js +0 -0
  62. package/src/core/CanvasManager.js +97 -204
  63. package/src/core/ErrorReporter.js +1 -1
  64. package/src/core/Parameters.js +1 -1
  65. package/src/core/VIB3Engine.js +38 -1
  66. package/src/core/VitalitySystem.js +53 -0
  67. package/src/core/renderers/HolographicRendererAdapter.js +2 -2
  68. package/src/creative/AestheticMapper.js +628 -0
  69. package/src/creative/ChoreographyPlayer.js +481 -0
  70. package/src/export/TradingCardManager.js +3 -4
  71. package/src/faceted/FacetedSystem.js +237 -388
  72. package/src/holograms/HolographicVisualizer.js +29 -12
  73. package/src/holograms/RealHolographicSystem.js +68 -12
  74. package/src/polychora/PolychoraSystem.js +77 -0
  75. package/src/quantum/QuantumEngine.js +103 -66
  76. package/src/quantum/QuantumVisualizer.js +7 -2
  77. package/src/render/UnifiedRenderBridge.js +3 -0
  78. package/src/shaders/faceted/faceted.frag.glsl +220 -80
  79. package/src/shaders/faceted/faceted.frag.wgsl +138 -97
  80. package/src/shaders/holographic/holographic.frag.glsl +28 -9
  81. package/src/shaders/holographic/holographic.frag.wgsl +107 -38
  82. package/src/shaders/quantum/quantum.frag.glsl +1 -0
  83. package/src/shaders/quantum/quantum.frag.wgsl +1 -1
  84. package/src/viewer/index.js +1 -1
  85. package/tools/headless-renderer.js +258 -0
  86. package/tools/shader-sync-verify.js +8 -4
  87. package/tools/site-analysis/all-reports.json +32 -0
  88. package/tools/site-analysis/combined-analysis.md +50 -0
  89. package/tools/site-analyzer.mjs +779 -0
  90. package/tools/visual-catalog/capture.js +276 -0
  91. package/tools/visual-catalog/composite.js +138 -0
  92. /package/DOCS/{DEV_TRACK_PLAN_2026-01-07.md → archive/DEV_TRACK_PLAN_2026-01-07.md} +0 -0
  93. /package/DOCS/{SESSION_014_PLAN.md → archive/SESSION_014_PLAN.md} +0 -0
  94. /package/DOCS/{SESSION_LOG_2026-01-07.md → archive/SESSION_LOG_2026-01-07.md} +0 -0
  95. /package/DOCS/{STRATEGIC_BLUEPRINT_2026-01-07.md → archive/STRATEGIC_BLUEPRINT_2026-01-07.md} +0 -0
  96. /package/src/viewer/{ReactivityManager.js → ViewerInputHandler.js} +0 -0
@@ -0,0 +1,238 @@
1
+ /**
2
+ * VIB3+ FFI Header
3
+ *
4
+ * C interface for cross-platform FFI bindings.
5
+ * Used by Flutter, React Native, and other FFI-capable frameworks.
6
+ */
7
+
8
+ #ifndef VIB3_FFI_H
9
+ #define VIB3_FFI_H
10
+
11
+ #include <stdint.h>
12
+ #include <stdbool.h>
13
+
14
+ #ifdef __cplusplus
15
+ extern "C" {
16
+ #endif
17
+
18
+ // Platform export macros
19
+ #if defined(_WIN32) || defined(_WIN64)
20
+ #define VIB3_EXPORT __declspec(dllexport)
21
+ #else
22
+ #define VIB3_EXPORT __attribute__((visibility("default")))
23
+ #endif
24
+
25
+ // ============================================================================
26
+ // Types
27
+ // ============================================================================
28
+
29
+ /**
30
+ * 4D Vector (16-byte aligned)
31
+ */
32
+ typedef struct VIB3_EXPORT Vib3Vec4 {
33
+ float x, y, z, w;
34
+ } Vib3Vec4;
35
+
36
+ /**
37
+ * 4D Rotor (8 components for proper 4D rotation)
38
+ */
39
+ typedef struct VIB3_EXPORT Vib3Rotor4D {
40
+ float s; // Scalar
41
+ float xy; // Bivector XY
42
+ float xz; // Bivector XZ
43
+ float yz; // Bivector YZ
44
+ float xw; // Bivector XW
45
+ float yw; // Bivector YW
46
+ float zw; // Bivector ZW
47
+ float xyzw; // Pseudoscalar
48
+ } Vib3Rotor4D;
49
+
50
+ /**
51
+ * 4x4 Matrix (column-major)
52
+ */
53
+ typedef struct VIB3_EXPORT Vib3Mat4x4 {
54
+ float data[16];
55
+ } Vib3Mat4x4;
56
+
57
+ /**
58
+ * Rotation plane enumeration
59
+ */
60
+ typedef enum VIB3_EXPORT Vib3RotationPlane {
61
+ VIB3_PLANE_XY = 0,
62
+ VIB3_PLANE_XZ = 1,
63
+ VIB3_PLANE_YZ = 2,
64
+ VIB3_PLANE_XW = 3,
65
+ VIB3_PLANE_YW = 4,
66
+ VIB3_PLANE_ZW = 5
67
+ } Vib3RotationPlane;
68
+
69
+ /**
70
+ * Projection type enumeration
71
+ */
72
+ typedef enum VIB3_EXPORT Vib3ProjectionType {
73
+ VIB3_PROJ_PERSPECTIVE = 0,
74
+ VIB3_PROJ_STEREOGRAPHIC = 1,
75
+ VIB3_PROJ_ORTHOGRAPHIC = 2,
76
+ VIB3_PROJ_OBLIQUE = 3
77
+ } Vib3ProjectionType;
78
+
79
+ /**
80
+ * Command batch result
81
+ */
82
+ typedef struct VIB3_EXPORT Vib3BatchResult {
83
+ int32_t success_count;
84
+ int32_t error_count;
85
+ int32_t result_size;
86
+ } Vib3BatchResult;
87
+
88
+ /**
89
+ * Engine handle (opaque)
90
+ */
91
+ typedef struct Vib3Engine* Vib3EngineHandle;
92
+
93
+ /**
94
+ * Texture handle for rendering
95
+ */
96
+ typedef struct {
97
+ void* native_handle; // Platform-specific texture handle
98
+ int32_t width;
99
+ int32_t height;
100
+ int32_t format;
101
+ } Vib3TextureHandle;
102
+
103
+ // ============================================================================
104
+ // Vec4 Functions
105
+ // ============================================================================
106
+
107
+ VIB3_EXPORT Vib3Vec4* vib3_vec4_create(float x, float y, float z, float w);
108
+ VIB3_EXPORT void vib3_vec4_free(Vib3Vec4* v);
109
+ VIB3_EXPORT float vib3_vec4_dot(const Vib3Vec4* a, const Vib3Vec4* b);
110
+ VIB3_EXPORT float vib3_vec4_length(const Vib3Vec4* v);
111
+ VIB3_EXPORT void vib3_vec4_normalize(Vib3Vec4* v);
112
+ VIB3_EXPORT Vib3Vec4* vib3_vec4_add(const Vib3Vec4* a, const Vib3Vec4* b);
113
+ VIB3_EXPORT Vib3Vec4* vib3_vec4_sub(const Vib3Vec4* a, const Vib3Vec4* b);
114
+ VIB3_EXPORT Vib3Vec4* vib3_vec4_scale(const Vib3Vec4* v, float s);
115
+ VIB3_EXPORT Vib3Vec4* vib3_vec4_lerp(const Vib3Vec4* a, const Vib3Vec4* b, float t);
116
+
117
+ // ============================================================================
118
+ // Rotor4D Functions
119
+ // ============================================================================
120
+
121
+ VIB3_EXPORT Vib3Rotor4D* vib3_rotor4d_identity(void);
122
+ VIB3_EXPORT Vib3Rotor4D* vib3_rotor4d_from_plane_angle(Vib3RotationPlane plane, float angle);
123
+ VIB3_EXPORT Vib3Rotor4D* vib3_rotor4d_from_euler6(
124
+ float xy, float xz, float yz,
125
+ float xw, float yw, float zw
126
+ );
127
+ VIB3_EXPORT void vib3_rotor4d_free(Vib3Rotor4D* r);
128
+ VIB3_EXPORT Vib3Rotor4D* vib3_rotor4d_multiply(const Vib3Rotor4D* a, const Vib3Rotor4D* b);
129
+ VIB3_EXPORT Vib3Vec4* vib3_rotor4d_rotate(const Vib3Rotor4D* r, const Vib3Vec4* v);
130
+ VIB3_EXPORT Vib3Rotor4D* vib3_rotor4d_slerp(const Vib3Rotor4D* a, const Vib3Rotor4D* b, float t);
131
+ VIB3_EXPORT void vib3_rotor4d_normalize(Vib3Rotor4D* r);
132
+ VIB3_EXPORT Vib3Mat4x4* vib3_rotor4d_to_matrix(const Vib3Rotor4D* r);
133
+
134
+ // ============================================================================
135
+ // Mat4x4 Functions
136
+ // ============================================================================
137
+
138
+ VIB3_EXPORT Vib3Mat4x4* vib3_mat4x4_identity(void);
139
+ VIB3_EXPORT Vib3Mat4x4* vib3_mat4x4_rotation_xy(float angle);
140
+ VIB3_EXPORT Vib3Mat4x4* vib3_mat4x4_rotation_xz(float angle);
141
+ VIB3_EXPORT Vib3Mat4x4* vib3_mat4x4_rotation_yz(float angle);
142
+ VIB3_EXPORT Vib3Mat4x4* vib3_mat4x4_rotation_xw(float angle);
143
+ VIB3_EXPORT Vib3Mat4x4* vib3_mat4x4_rotation_yw(float angle);
144
+ VIB3_EXPORT Vib3Mat4x4* vib3_mat4x4_rotation_zw(float angle);
145
+ VIB3_EXPORT Vib3Mat4x4* vib3_mat4x4_rotation_from_angles(
146
+ float xy, float xz, float yz,
147
+ float xw, float yw, float zw
148
+ );
149
+ VIB3_EXPORT void vib3_mat4x4_free(Vib3Mat4x4* m);
150
+ VIB3_EXPORT Vib3Mat4x4* vib3_mat4x4_multiply(const Vib3Mat4x4* a, const Vib3Mat4x4* b);
151
+ VIB3_EXPORT Vib3Vec4* vib3_mat4x4_multiply_vec4(const Vib3Mat4x4* m, const Vib3Vec4* v);
152
+ VIB3_EXPORT void vib3_mat4x4_get_data(const Vib3Mat4x4* m, float* out);
153
+
154
+ // ============================================================================
155
+ // Projection Functions
156
+ // ============================================================================
157
+
158
+ VIB3_EXPORT Vib3Vec4* vib3_project_perspective(const Vib3Vec4* v, float distance);
159
+ VIB3_EXPORT Vib3Vec4* vib3_project_stereographic(const Vib3Vec4* v);
160
+ VIB3_EXPORT Vib3Vec4* vib3_project_orthographic(const Vib3Vec4* v);
161
+ VIB3_EXPORT Vib3Vec4* vib3_project_oblique(const Vib3Vec4* v, float shear_x, float shear_y);
162
+
163
+ // Batch projection (for geometry arrays)
164
+ VIB3_EXPORT int32_t vib3_project_batch(
165
+ const float* positions, // Input: [x,y,z,w, x,y,z,w, ...]
166
+ int32_t count, // Number of Vec4s
167
+ Vib3ProjectionType type,
168
+ float param, // Distance for perspective, unused for others
169
+ float* out // Output: [x,y,z, x,y,z, ...]
170
+ );
171
+
172
+ // ============================================================================
173
+ // Command Batching
174
+ // ============================================================================
175
+
176
+ /**
177
+ * Process a batch of commands
178
+ *
179
+ * @param commands Binary command buffer
180
+ * @param size Size of command buffer in bytes
181
+ * @param results Output buffer for results
182
+ * @return Number of bytes written to results
183
+ */
184
+ VIB3_EXPORT int32_t vib3_process_command_batch(
185
+ const uint8_t* commands,
186
+ uint32_t size,
187
+ uint8_t* results
188
+ );
189
+
190
+ // ============================================================================
191
+ // Engine Functions
192
+ // ============================================================================
193
+
194
+ VIB3_EXPORT Vib3EngineHandle vib3_engine_create(void);
195
+ VIB3_EXPORT void vib3_engine_destroy(Vib3EngineHandle engine);
196
+
197
+ VIB3_EXPORT bool vib3_engine_initialize(
198
+ Vib3EngineHandle engine,
199
+ int32_t width,
200
+ int32_t height
201
+ );
202
+
203
+ VIB3_EXPORT void vib3_engine_set_system(Vib3EngineHandle engine, const char* system);
204
+ VIB3_EXPORT void vib3_engine_set_geometry(Vib3EngineHandle engine, int32_t index);
205
+ VIB3_EXPORT void vib3_engine_set_rotation(
206
+ Vib3EngineHandle engine,
207
+ Vib3RotationPlane plane,
208
+ float angle
209
+ );
210
+ VIB3_EXPORT void vib3_engine_set_all_rotations(
211
+ Vib3EngineHandle engine,
212
+ float xy, float xz, float yz,
213
+ float xw, float yw, float zw
214
+ );
215
+ VIB3_EXPORT void vib3_engine_reset_rotation(Vib3EngineHandle engine);
216
+
217
+ VIB3_EXPORT void vib3_engine_set_visual_param(
218
+ Vib3EngineHandle engine,
219
+ const char* param,
220
+ float value
221
+ );
222
+
223
+ VIB3_EXPORT void vib3_engine_render(Vib3EngineHandle engine);
224
+ VIB3_EXPORT Vib3TextureHandle vib3_engine_get_texture(Vib3EngineHandle engine);
225
+
226
+ // ============================================================================
227
+ // Utility Functions
228
+ // ============================================================================
229
+
230
+ VIB3_EXPORT const char* vib3_version(void);
231
+ VIB3_EXPORT const char* vib3_geometry_name(int32_t index);
232
+ VIB3_EXPORT bool vib3_has_simd(void);
233
+
234
+ #ifdef __cplusplus
235
+ }
236
+ #endif
237
+
238
+ #endif // VIB3_FFI_H
@@ -0,0 +1,409 @@
1
+ /**
2
+ * Mat4x4.cpp - 4x4 Matrix Implementation
3
+ */
4
+
5
+ #include "Mat4x4.hpp"
6
+ #include <cmath>
7
+ #include <algorithm>
8
+
9
+ namespace vib3 {
10
+
11
+ // Constructors
12
+
13
+ Mat4x4::Mat4x4() noexcept : data{} {
14
+ // Zero-initialized
15
+ }
16
+
17
+ Mat4x4::Mat4x4(float diagonal) noexcept : data{} {
18
+ data[0] = diagonal;
19
+ data[5] = diagonal;
20
+ data[10] = diagonal;
21
+ data[15] = diagonal;
22
+ }
23
+
24
+ Mat4x4::Mat4x4(const std::array<float, 16>& elements) noexcept : data(elements) {}
25
+
26
+ Mat4x4::Mat4x4(const Vec4& col0, const Vec4& col1, const Vec4& col2, const Vec4& col3) noexcept {
27
+ setColumn(0, col0);
28
+ setColumn(1, col1);
29
+ setColumn(2, col2);
30
+ setColumn(3, col3);
31
+ }
32
+
33
+ // Static factories
34
+
35
+ Mat4x4 Mat4x4::identity() noexcept {
36
+ return Mat4x4(1.0f);
37
+ }
38
+
39
+ Mat4x4 Mat4x4::zero() noexcept {
40
+ return Mat4x4();
41
+ }
42
+
43
+ // Rotation matrices
44
+
45
+ Mat4x4 Mat4x4::rotationXY(float angle) noexcept {
46
+ float c = std::cos(angle);
47
+ float s = std::sin(angle);
48
+
49
+ Mat4x4 m = identity();
50
+ m.at(0, 0) = c;
51
+ m.at(0, 1) = -s;
52
+ m.at(1, 0) = s;
53
+ m.at(1, 1) = c;
54
+ return m;
55
+ }
56
+
57
+ Mat4x4 Mat4x4::rotationXZ(float angle) noexcept {
58
+ float c = std::cos(angle);
59
+ float s = std::sin(angle);
60
+
61
+ Mat4x4 m = identity();
62
+ m.at(0, 0) = c;
63
+ m.at(0, 2) = -s;
64
+ m.at(2, 0) = s;
65
+ m.at(2, 2) = c;
66
+ return m;
67
+ }
68
+
69
+ Mat4x4 Mat4x4::rotationYZ(float angle) noexcept {
70
+ float c = std::cos(angle);
71
+ float s = std::sin(angle);
72
+
73
+ Mat4x4 m = identity();
74
+ m.at(1, 1) = c;
75
+ m.at(1, 2) = -s;
76
+ m.at(2, 1) = s;
77
+ m.at(2, 2) = c;
78
+ return m;
79
+ }
80
+
81
+ Mat4x4 Mat4x4::rotationXW(float angle) noexcept {
82
+ float c = std::cos(angle);
83
+ float s = std::sin(angle);
84
+
85
+ Mat4x4 m = identity();
86
+ m.at(0, 0) = c;
87
+ m.at(0, 3) = -s;
88
+ m.at(3, 0) = s;
89
+ m.at(3, 3) = c;
90
+ return m;
91
+ }
92
+
93
+ Mat4x4 Mat4x4::rotationYW(float angle) noexcept {
94
+ float c = std::cos(angle);
95
+ float s = std::sin(angle);
96
+
97
+ Mat4x4 m = identity();
98
+ m.at(1, 1) = c;
99
+ m.at(1, 3) = -s;
100
+ m.at(3, 1) = s;
101
+ m.at(3, 3) = c;
102
+ return m;
103
+ }
104
+
105
+ Mat4x4 Mat4x4::rotationZW(float angle) noexcept {
106
+ float c = std::cos(angle);
107
+ float s = std::sin(angle);
108
+
109
+ Mat4x4 m = identity();
110
+ m.at(2, 2) = c;
111
+ m.at(2, 3) = -s;
112
+ m.at(3, 2) = s;
113
+ m.at(3, 3) = c;
114
+ return m;
115
+ }
116
+
117
+ Mat4x4 Mat4x4::rotationFromAngles(float xy, float xz, float yz,
118
+ float xw, float yw, float zw) noexcept {
119
+ // Compose rotations: XY * XZ * YZ * XW * YW * ZW
120
+ Mat4x4 result = identity();
121
+
122
+ if (std::abs(xy) > 1e-8f) result *= rotationXY(xy);
123
+ if (std::abs(xz) > 1e-8f) result *= rotationXZ(xz);
124
+ if (std::abs(yz) > 1e-8f) result *= rotationYZ(yz);
125
+ if (std::abs(xw) > 1e-8f) result *= rotationXW(xw);
126
+ if (std::abs(yw) > 1e-8f) result *= rotationYW(yw);
127
+ if (std::abs(zw) > 1e-8f) result *= rotationZW(zw);
128
+
129
+ return result;
130
+ }
131
+
132
+ Mat4x4 Mat4x4::rotationFromAngles(const std::array<float, 6>& angles) noexcept {
133
+ return rotationFromAngles(angles[0], angles[1], angles[2],
134
+ angles[3], angles[4], angles[5]);
135
+ }
136
+
137
+ // Scale matrices
138
+
139
+ Mat4x4 Mat4x4::scale(float sx, float sy, float sz, float sw) noexcept {
140
+ Mat4x4 m;
141
+ m.at(0, 0) = sx;
142
+ m.at(1, 1) = sy;
143
+ m.at(2, 2) = sz;
144
+ m.at(3, 3) = sw;
145
+ return m;
146
+ }
147
+
148
+ Mat4x4 Mat4x4::scale(float uniform) noexcept {
149
+ return scale(uniform, uniform, uniform, uniform);
150
+ }
151
+
152
+ Mat4x4 Mat4x4::scale(const Vec4& s) noexcept {
153
+ return scale(s.x, s.y, s.z, s.w);
154
+ }
155
+
156
+ // Translation (homogeneous coordinates style)
157
+
158
+ Mat4x4 Mat4x4::translation(float tx, float ty, float tz, float tw) noexcept {
159
+ Mat4x4 m = identity();
160
+ m.at(0, 3) = tx;
161
+ m.at(1, 3) = ty;
162
+ m.at(2, 3) = tz;
163
+ m.at(3, 3) = 1.0f + tw;
164
+ return m;
165
+ }
166
+
167
+ Mat4x4 Mat4x4::translation(const Vec4& t) noexcept {
168
+ return translation(t.x, t.y, t.z, t.w);
169
+ }
170
+
171
+ // Element access
172
+
173
+ float& Mat4x4::at(size_t row, size_t col) noexcept {
174
+ return data[col * 4 + row]; // Column-major
175
+ }
176
+
177
+ const float& Mat4x4::at(size_t row, size_t col) const noexcept {
178
+ return data[col * 4 + row];
179
+ }
180
+
181
+ Vec4 Mat4x4::column(size_t col) const noexcept {
182
+ size_t base = col * 4;
183
+ return Vec4(data[base], data[base + 1], data[base + 2], data[base + 3]);
184
+ }
185
+
186
+ void Mat4x4::setColumn(size_t col, const Vec4& v) noexcept {
187
+ size_t base = col * 4;
188
+ data[base] = v.x;
189
+ data[base + 1] = v.y;
190
+ data[base + 2] = v.z;
191
+ data[base + 3] = v.w;
192
+ }
193
+
194
+ Vec4 Mat4x4::row(size_t r) const noexcept {
195
+ return Vec4(at(r, 0), at(r, 1), at(r, 2), at(r, 3));
196
+ }
197
+
198
+ void Mat4x4::setRow(size_t r, const Vec4& v) noexcept {
199
+ at(r, 0) = v.x;
200
+ at(r, 1) = v.y;
201
+ at(r, 2) = v.z;
202
+ at(r, 3) = v.w;
203
+ }
204
+
205
+ // Matrix operations
206
+
207
+ Mat4x4 Mat4x4::operator*(const Mat4x4& other) const noexcept {
208
+ Mat4x4 result;
209
+
210
+ for (size_t col = 0; col < 4; ++col) {
211
+ Vec4 c = other.column(col);
212
+ result.setColumn(col, *this * c);
213
+ }
214
+
215
+ return result;
216
+ }
217
+
218
+ Mat4x4& Mat4x4::operator*=(const Mat4x4& other) noexcept {
219
+ *this = *this * other;
220
+ return *this;
221
+ }
222
+
223
+ Vec4 Mat4x4::operator*(const Vec4& v) const noexcept {
224
+ return Vec4(
225
+ at(0, 0) * v.x + at(0, 1) * v.y + at(0, 2) * v.z + at(0, 3) * v.w,
226
+ at(1, 0) * v.x + at(1, 1) * v.y + at(1, 2) * v.z + at(1, 3) * v.w,
227
+ at(2, 0) * v.x + at(2, 1) * v.y + at(2, 2) * v.z + at(2, 3) * v.w,
228
+ at(3, 0) * v.x + at(3, 1) * v.y + at(3, 2) * v.z + at(3, 3) * v.w
229
+ );
230
+ }
231
+
232
+ Vec4 Mat4x4::multiplyVec4(const Vec4& v) const noexcept {
233
+ return *this * v;
234
+ }
235
+
236
+ Mat4x4 Mat4x4::operator*(float scalar) const noexcept {
237
+ Mat4x4 result;
238
+ for (size_t i = 0; i < 16; ++i) {
239
+ result.data[i] = data[i] * scalar;
240
+ }
241
+ return result;
242
+ }
243
+
244
+ Mat4x4& Mat4x4::operator*=(float scalar) noexcept {
245
+ for (float& elem : data) {
246
+ elem *= scalar;
247
+ }
248
+ return *this;
249
+ }
250
+
251
+ Mat4x4 Mat4x4::operator+(const Mat4x4& other) const noexcept {
252
+ Mat4x4 result;
253
+ for (size_t i = 0; i < 16; ++i) {
254
+ result.data[i] = data[i] + other.data[i];
255
+ }
256
+ return result;
257
+ }
258
+
259
+ Mat4x4& Mat4x4::operator+=(const Mat4x4& other) noexcept {
260
+ for (size_t i = 0; i < 16; ++i) {
261
+ data[i] += other.data[i];
262
+ }
263
+ return *this;
264
+ }
265
+
266
+ Mat4x4 Mat4x4::operator-(const Mat4x4& other) const noexcept {
267
+ Mat4x4 result;
268
+ for (size_t i = 0; i < 16; ++i) {
269
+ result.data[i] = data[i] - other.data[i];
270
+ }
271
+ return result;
272
+ }
273
+
274
+ Mat4x4& Mat4x4::operator-=(const Mat4x4& other) noexcept {
275
+ for (size_t i = 0; i < 16; ++i) {
276
+ data[i] -= other.data[i];
277
+ }
278
+ return *this;
279
+ }
280
+
281
+ Mat4x4 Mat4x4::transposed() const noexcept {
282
+ Mat4x4 result;
283
+ for (size_t r = 0; r < 4; ++r) {
284
+ for (size_t c = 0; c < 4; ++c) {
285
+ result.at(c, r) = at(r, c);
286
+ }
287
+ }
288
+ return result;
289
+ }
290
+
291
+ void Mat4x4::transpose() noexcept {
292
+ std::swap(at(0, 1), at(1, 0));
293
+ std::swap(at(0, 2), at(2, 0));
294
+ std::swap(at(0, 3), at(3, 0));
295
+ std::swap(at(1, 2), at(2, 1));
296
+ std::swap(at(1, 3), at(3, 1));
297
+ std::swap(at(2, 3), at(3, 2));
298
+ }
299
+
300
+ // Determinant using cofactor expansion
301
+
302
+ float Mat4x4::determinant() const noexcept {
303
+ float a00 = at(0, 0), a01 = at(0, 1), a02 = at(0, 2), a03 = at(0, 3);
304
+ float a10 = at(1, 0), a11 = at(1, 1), a12 = at(1, 2), a13 = at(1, 3);
305
+ float a20 = at(2, 0), a21 = at(2, 1), a22 = at(2, 2), a23 = at(2, 3);
306
+ float a30 = at(3, 0), a31 = at(3, 1), a32 = at(3, 2), a33 = at(3, 3);
307
+
308
+ float b00 = a00 * a11 - a01 * a10;
309
+ float b01 = a00 * a12 - a02 * a10;
310
+ float b02 = a00 * a13 - a03 * a10;
311
+ float b03 = a01 * a12 - a02 * a11;
312
+ float b04 = a01 * a13 - a03 * a11;
313
+ float b05 = a02 * a13 - a03 * a12;
314
+ float b06 = a20 * a31 - a21 * a30;
315
+ float b07 = a20 * a32 - a22 * a30;
316
+ float b08 = a20 * a33 - a23 * a30;
317
+ float b09 = a21 * a32 - a22 * a31;
318
+ float b10 = a21 * a33 - a23 * a31;
319
+ float b11 = a22 * a33 - a23 * a32;
320
+
321
+ return b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
322
+ }
323
+
324
+ // Inverse using adjugate method
325
+
326
+ Mat4x4 Mat4x4::inverse() const noexcept {
327
+ float a00 = at(0, 0), a01 = at(0, 1), a02 = at(0, 2), a03 = at(0, 3);
328
+ float a10 = at(1, 0), a11 = at(1, 1), a12 = at(1, 2), a13 = at(1, 3);
329
+ float a20 = at(2, 0), a21 = at(2, 1), a22 = at(2, 2), a23 = at(2, 3);
330
+ float a30 = at(3, 0), a31 = at(3, 1), a32 = at(3, 2), a33 = at(3, 3);
331
+
332
+ float b00 = a00 * a11 - a01 * a10;
333
+ float b01 = a00 * a12 - a02 * a10;
334
+ float b02 = a00 * a13 - a03 * a10;
335
+ float b03 = a01 * a12 - a02 * a11;
336
+ float b04 = a01 * a13 - a03 * a11;
337
+ float b05 = a02 * a13 - a03 * a12;
338
+ float b06 = a20 * a31 - a21 * a30;
339
+ float b07 = a20 * a32 - a22 * a30;
340
+ float b08 = a20 * a33 - a23 * a30;
341
+ float b09 = a21 * a32 - a22 * a31;
342
+ float b10 = a21 * a33 - a23 * a31;
343
+ float b11 = a22 * a33 - a23 * a32;
344
+
345
+ float det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
346
+
347
+ if (std::abs(det) < 1e-10f) {
348
+ return identity(); // Singular matrix
349
+ }
350
+
351
+ float invDet = 1.0f / det;
352
+
353
+ Mat4x4 result;
354
+ result.at(0, 0) = (a11 * b11 - a12 * b10 + a13 * b09) * invDet;
355
+ result.at(0, 1) = (-a01 * b11 + a02 * b10 - a03 * b09) * invDet;
356
+ result.at(0, 2) = (a31 * b05 - a32 * b04 + a33 * b03) * invDet;
357
+ result.at(0, 3) = (-a21 * b05 + a22 * b04 - a23 * b03) * invDet;
358
+ result.at(1, 0) = (-a10 * b11 + a12 * b08 - a13 * b07) * invDet;
359
+ result.at(1, 1) = (a00 * b11 - a02 * b08 + a03 * b07) * invDet;
360
+ result.at(1, 2) = (-a30 * b05 + a32 * b02 - a33 * b01) * invDet;
361
+ result.at(1, 3) = (a20 * b05 - a22 * b02 + a23 * b01) * invDet;
362
+ result.at(2, 0) = (a10 * b10 - a11 * b08 + a13 * b06) * invDet;
363
+ result.at(2, 1) = (-a00 * b10 + a01 * b08 - a03 * b06) * invDet;
364
+ result.at(2, 2) = (a30 * b04 - a31 * b02 + a33 * b00) * invDet;
365
+ result.at(2, 3) = (-a20 * b04 + a21 * b02 - a23 * b00) * invDet;
366
+ result.at(3, 0) = (-a10 * b09 + a11 * b07 - a12 * b06) * invDet;
367
+ result.at(3, 1) = (a00 * b09 - a01 * b07 + a02 * b06) * invDet;
368
+ result.at(3, 2) = (-a30 * b03 + a31 * b01 - a32 * b00) * invDet;
369
+ result.at(3, 3) = (a20 * b03 - a21 * b01 + a22 * b00) * invDet;
370
+
371
+ return result;
372
+ }
373
+
374
+ bool Mat4x4::isOrthogonal(float epsilon) const noexcept {
375
+ // Check if M * M^T = I
376
+ Mat4x4 product = *this * transposed();
377
+
378
+ for (size_t i = 0; i < 4; ++i) {
379
+ for (size_t j = 0; j < 4; ++j) {
380
+ float expected = (i == j) ? 1.0f : 0.0f;
381
+ if (std::abs(product.at(i, j) - expected) > epsilon) {
382
+ return false;
383
+ }
384
+ }
385
+ }
386
+ return true;
387
+ }
388
+
389
+ bool Mat4x4::isIdentity(float epsilon) const noexcept {
390
+ for (size_t i = 0; i < 4; ++i) {
391
+ for (size_t j = 0; j < 4; ++j) {
392
+ float expected = (i == j) ? 1.0f : 0.0f;
393
+ if (std::abs(at(i, j) - expected) > epsilon) {
394
+ return false;
395
+ }
396
+ }
397
+ }
398
+ return true;
399
+ }
400
+
401
+ bool Mat4x4::operator==(const Mat4x4& other) const noexcept {
402
+ return data == other.data;
403
+ }
404
+
405
+ bool Mat4x4::operator!=(const Mat4x4& other) const noexcept {
406
+ return !(*this == other);
407
+ }
408
+
409
+ } // namespace vib3