summaryrefslogtreecommitdiff
path: root/src/3d/visual_debug.cc
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-02-08 07:40:29 +0100
committerskal <pascal.massimino@gmail.com>2026-02-08 07:40:29 +0100
commitc9195f997f3e797f03ab90464e4158717198a167 (patch)
tree331304f42870246efdc64cc97ad42de59444ef3a /src/3d/visual_debug.cc
parentb8e6929cafa41681f0b27ac104c9cf1d4e510837 (diff)
style: Apply clang-format to all source files
Diffstat (limited to 'src/3d/visual_debug.cc')
-rw-r--r--src/3d/visual_debug.cc67
1 files changed, 39 insertions, 28 deletions
diff --git a/src/3d/visual_debug.cc b/src/3d/visual_debug.cc
index 78c751b..35ab60d 100644
--- a/src/3d/visual_debug.cc
+++ b/src/3d/visual_debug.cc
@@ -215,25 +215,28 @@ void VisualDebug::add_mesh_normals(const mat4& transform, uint32_t num_vertices,
vec4 p_world = transform * vec4(v.p[0], v.p[1], v.p[2], 1.0f);
vec3 n_object = vec3(v.n[0], v.n[1], v.n[2]);
- vec4 n_world_h = normal_matrix * vec4(n_object.x, n_object.y, n_object.z, 0.0f);
+ vec4 n_world_h =
+ normal_matrix * vec4(n_object.x, n_object.y, n_object.z, 0.0f);
vec3 n_world = n_world_h.xyz().normalize();
- lines_.push_back(
- {p_world.xyz(), p_world.xyz() + n_world * 0.1f, // 0.1 is the length
- {0.0f, 1.0f, 1.0f} // Cyan color
- });
+ lines_.push_back({
+ p_world.xyz(),
+ p_world.xyz() + n_world * 0.1f, // 0.1 is the length
+ {0.0f, 1.0f, 1.0f} // Cyan color
+ });
}
}
-void VisualDebug::add_mesh_wireframe(const mat4& transform, uint32_t num_vertices,
- const MeshVertex* vertices, uint32_t num_indices,
- const uint32_t* indices, const vec3& color) {
+void VisualDebug::add_mesh_wireframe(
+ const mat4& transform, uint32_t num_vertices, const MeshVertex* vertices,
+ uint32_t num_indices, const uint32_t* indices, const vec3& color) {
if (!vertices || !indices || num_indices == 0)
return;
for (uint32_t i = 0; i < num_indices; i += 3) {
- if (i + 2 >= num_indices) break;
-
+ if (i + 2 >= num_indices)
+ break;
+
uint32_t idx0 = indices[i];
uint32_t idx1 = indices[i + 1];
uint32_t idx2 = indices[i + 2];
@@ -241,9 +244,12 @@ void VisualDebug::add_mesh_wireframe(const mat4& transform, uint32_t num_vertice
if (idx0 >= num_vertices || idx1 >= num_vertices || idx2 >= num_vertices)
continue;
- vec4 p0_world = transform * vec4(vertices[idx0].p[0], vertices[idx0].p[1], vertices[idx0].p[2], 1.0f);
- vec4 p1_world = transform * vec4(vertices[idx1].p[0], vertices[idx1].p[1], vertices[idx1].p[2], 1.0f);
- vec4 p2_world = transform * vec4(vertices[idx2].p[0], vertices[idx2].p[1], vertices[idx2].p[2], 1.0f);
+ vec4 p0_world = transform * vec4(vertices[idx0].p[0], vertices[idx0].p[1],
+ vertices[idx0].p[2], 1.0f);
+ vec4 p1_world = transform * vec4(vertices[idx1].p[0], vertices[idx1].p[1],
+ vertices[idx1].p[2], 1.0f);
+ vec4 p2_world = transform * vec4(vertices[idx2].p[0], vertices[idx2].p[1],
+ vertices[idx2].p[2], 1.0f);
add_line(p0_world.xyz(), p1_world.xyz(), color);
add_line(p1_world.xyz(), p2_world.xyz(), color);
@@ -251,7 +257,8 @@ void VisualDebug::add_mesh_wireframe(const mat4& transform, uint32_t num_vertice
}
}
-void VisualDebug::add_line(const vec3& start, const vec3& end, const vec3& color) {
+void VisualDebug::add_line(const vec3& start, const vec3& end,
+ const vec3& color) {
lines_.push_back({start, end, color});
}
@@ -262,7 +269,8 @@ void VisualDebug::add_cross(const vec3& center, float size, const vec3& color) {
add_line(center - vec3(0, 0, s), center + vec3(0, 0, s), color);
}
-void VisualDebug::add_sphere(const vec3& center, float radius, const vec3& color) {
+void VisualDebug::add_sphere(const vec3& center, float radius,
+ const vec3& color) {
const int kSegments = 16;
const float kStep = 6.2831853f / kSegments;
@@ -272,14 +280,14 @@ void VisualDebug::add_sphere(const vec3& center, float radius, const vec3& color
float a2 = (i + 1) * kStep;
vec3 p1 = center;
vec3 p2 = center;
-
+
// axis mapping: 0=x, 1=y, 2=z
p1[axis1] += std::cos(a1) * radius;
p1[axis2] += std::sin(a1) * radius;
-
+
p2[axis1] += std::cos(a2) * radius;
p2[axis2] += std::sin(a2) * radius;
-
+
add_line(p1, p2, color);
}
};
@@ -289,30 +297,31 @@ void VisualDebug::add_sphere(const vec3& center, float radius, const vec3& color
draw_circle(1, 2); // YZ
}
-void VisualDebug::add_cone(const vec3& apex, const vec3& dir, float height, float radius, const vec3& color) {
+void VisualDebug::add_cone(const vec3& apex, const vec3& dir, float height,
+ float radius, const vec3& color) {
vec3 d = dir.normalize();
vec3 base_center = apex + d * height;
-
+
// Rotation to align (0, 1, 0) with d
quat q = quat::from_to(vec3(0, 1, 0), d);
-
+
const int kSegments = 16;
const float kStep = 6.2831853f / kSegments;
-
+
for (int i = 0; i < kSegments; ++i) {
float a1 = i * kStep;
float a2 = (i + 1) * kStep;
-
+
// Circle points in XZ plane (local space, y=0)
vec3 p1_local(std::cos(a1) * radius, 0, std::sin(a1) * radius);
vec3 p2_local(std::cos(a2) * radius, 0, std::sin(a2) * radius);
-
+
// Rotate and translate to base_center
vec3 p1 = base_center + q.rotate(p1_local);
vec3 p2 = base_center + q.rotate(p2_local);
-
+
add_line(p1, p2, color); // Base circle
-
+
// Connect to apex (draw every 4th segment to avoid clutter)
if (i % 4 == 0) {
add_line(apex, p1, color);
@@ -320,8 +329,10 @@ void VisualDebug::add_cone(const vec3& apex, const vec3& dir, float height, floa
}
}
-void VisualDebug::add_trajectory(const std::vector<vec3>& points, const vec3& color) {
- if (points.size() < 2) return;
+void VisualDebug::add_trajectory(const std::vector<vec3>& points,
+ const vec3& color) {
+ if (points.size() < 2)
+ return;
for (size_t i = 0; i < points.size() - 1; ++i) {
add_line(points[i], points[i + 1], color);
}