From f6f3c13fcd287774a458730722854baab8a17366 Mon Sep 17 00:00:00 2001 From: skal Date: Thu, 5 Feb 2026 16:40:27 +0100 Subject: feat(physics): Implement SDF-based physics engine and BVH Completed Task #49. - Implemented CPU-side SDF library (sphere, box, torus, plane). - Implemented Dynamic BVH construction (rebuilt every frame). - Implemented PhysicsSystem with semi-implicit Euler integration and collision resolution. - Added visual debugging for BVH nodes. - Created test_3d_physics interactive test and test_physics unit tests. - Updated project docs and triaged new tasks. --- src/3d/visual_debug.cc | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/3d/visual_debug.cc') diff --git a/src/3d/visual_debug.cc b/src/3d/visual_debug.cc index f8d9bed..ab4cb6c 100644 --- a/src/3d/visual_debug.cc +++ b/src/3d/visual_debug.cc @@ -182,6 +182,25 @@ void VisualDebug::add_box(const mat4& transform, const vec3& local_extent, } } +void VisualDebug::add_aabb(const vec3& min, const vec3& max, const vec3& color) { + vec3 p[] = {{min.x, min.y, min.z}, {max.x, min.y, min.z}, {max.x, max.y, min.z}, + {min.x, max.y, min.z}, {min.x, min.y, max.z}, {max.x, min.y, max.z}, + {max.x, max.y, max.z}, {min.x, max.y, max.z}}; + + DebugLine edges[] = { + {p[0], p[1], color}, {p[1], p[2], color}, {p[2], p[3], color}, + {p[3], p[0], color}, // Front + {p[4], p[5], color}, {p[5], p[6], color}, {p[6], p[7], color}, + {p[7], p[4], color}, // Back + {p[0], p[4], color}, {p[1], p[5], color}, {p[2], p[6], color}, + {p[3], p[7], color} // Connections + }; + + for (const auto& l : edges) { + lines_.push_back(l); + } +} + void VisualDebug::update_buffers(const mat4& view_proj) { // Update Uniforms wgpuQueueWriteBuffer(wgpuDeviceGetQueue(device_), uniform_buffer_, 0, -- cgit v1.2.3