From 1960ddd62b325cd79e8fcdc089068073800d642b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20B=C3=B6klin?= Date: Tue, 22 Jun 2021 15:32:13 +0200 Subject: [PATCH] Make debug lines visible from more directions --- voxygen/src/scene/debug.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/voxygen/src/scene/debug.rs b/voxygen/src/scene/debug.rs index e4ddf857ac..94bfb8f877 100644 --- a/voxygen/src/scene/debug.rs +++ b/voxygen/src/scene/debug.rs @@ -24,8 +24,24 @@ impl DebugShape { }; match self { DebugShape::Line([a, b]) => { - let h = Vec3::new(0.0, 1.0, 0.0); - mesh.push_quad(quad(*a, a + h, b + h, *b)); + // Creates two quads to make the line visible from all directions (except when + // perfectly parallel to the view). Duplicate both quads with + // opposite normals to make them double-sided. + + // Width + let w = 0.05; + + let vert = Vec3::unit_z() * w; + mesh.push_quad(quad(*a - vert, a + vert, b + vert, *b - vert)); + mesh.push_quad(quad(*b - vert, b + vert, a + vert, *a - vert)); + + let horiz = (b - a) + .cross(Vec3::unit_z()) + .try_normalized() + .unwrap_or_else(Vec3::unit_y) + * w; + mesh.push_quad(quad(*a - horiz, a + horiz, b + horiz, *b - horiz)); + mesh.push_quad(quad(*b - horiz, b + horiz, a + horiz, *a - horiz)); }, DebugShape::Cylinder { radius, height } => { const SUBDIVISIONS: usize = 16;