From b9c93970d082fd7ddb50b5af4e9835e8f573e1c4 Mon Sep 17 00:00:00 2001 From: Tyler Gregorcyk Date: Fri, 26 Jun 2026 13:01:45 -0500 Subject: [PATCH 1/4] Adds camera facing point to debug draw closes #4133 Signed-off-by: Tyler Gregorcyk --- Source/Engine/Debug/DebugDraw.cpp | 39 +++++++++++++++++++++++++++++++ Source/Engine/Debug/DebugDraw.h | 11 +++++++++ 2 files changed, 50 insertions(+) diff --git a/Source/Engine/Debug/DebugDraw.cpp b/Source/Engine/Debug/DebugDraw.cpp index 0e1768f63..aeb2cb747 100644 --- a/Source/Engine/Debug/DebugDraw.cpp +++ b/Source/Engine/Debug/DebugDraw.cpp @@ -1526,6 +1526,45 @@ void DebugDraw::DrawCircle(const Vector3& position, const Float3& normal, float } } +void DebugDraw::DrawPoint(const Vector3& position, float radius, const Color& color, float duration, bool depthTest) +{ + Float3 normal = (Float3)(Context->LastViewPosition - position); + if (normal.Length() < ZeroTolerance) + normal = Float3::Up; + normal.Normalize(); + + // Create matrix transform for unit circle points + Matrix world, scale, matrix; + Float3 right, up; + if (Float3::Dot(normal, Float3::Up) > 0.99f) + right = Float3::Right; + else if (Float3::Dot(normal, Float3::Down) > 0.99f) + right = Float3::Left; + else + Float3::Cross(normal, Float3::Up, right); + Float3::Cross(right, normal, up); + Matrix::Scaling(radius, scale); + const Float3 positionF = position - Context->Origin; + Matrix::CreateWorld(positionF, normal, up, world); + Matrix::Multiply(scale, world, matrix); + + // Draw lines of the unit circle after linear transform + PROFILE_MEM(EngineDebug); + Float3 prev = Float3::Transform(CircleCache[0], matrix); + for (int32 i = 1; i < DEBUG_DRAW_CIRCLE_VERTICES;) + { + Float3 cur = Float3::Transform(CircleCache[i++], matrix); + DebugTriangle t; + t.Color = Color32(color); + t.TimeLeft = duration; + t.V0 = positionF; + t.V1 = prev; + t.V2 = cur; + (depthTest ? Context->DebugDrawDepthTest : Context->DebugDrawDefault).Add(t); + prev = cur; + } +} + void DebugDraw::DrawWireTriangle(const Vector3& v0, const Vector3& v1, const Vector3& v2, const Color& color, float duration, bool depthTest) { DrawLine(v0, v1, color, duration, depthTest); diff --git a/Source/Engine/Debug/DebugDraw.h b/Source/Engine/Debug/DebugDraw.h index c4ae12283..9084ab962 100644 --- a/Source/Engine/Debug/DebugDraw.h +++ b/Source/Engine/Debug/DebugDraw.h @@ -267,6 +267,16 @@ API_CLASS(Static) class FLAXENGINE_API DebugDraw /// The duration (in seconds). Use 0 to draw it only once. /// If set to true depth test will be performed, otherwise depth will be ignored. API_FUNCTION() static void DrawCircle(const Vector3& position, const Float3& normal, float radius, const Color& color = Color::White, float duration = 0.0f, bool depthTest = true); + + /// + /// Draws the point facing camera. + /// + /// The center position. + /// The radius. + /// The color. + /// The duration (in seconds). Use 0 to draw it only once. + /// If set to true depth test will be performed, otherwise depth will be ignored. + API_FUNCTION() static void DrawPoint(const Vector3& position, float radius, const Color& color = Color::White, float duration = 0.0f, bool depthTest = true); /// /// Draws the wireframe triangle. @@ -780,6 +790,7 @@ API_CLASS(Static) class FLAXENGINE_API DebugDraw #define DEBUG_DRAW_LINES(lines, transform, color, duration, depthTest) DebugDraw::DrawLines(lines, transform, color, duration, depthTest) #define DEBUG_DRAW_BEZIER(p1, p2, p3, p4, color, duration, depthTest) DebugDraw::DrawBezier(p1, p2, p3, p4, color, duration, depthTest) #define DEBUG_DRAW_CIRCLE(position, normal, radius, color, duration, depthTest) DebugDraw::DrawCircle(position, normal, radius, color, duration, depthTest) +#define DEBUG_DRAW_POINT(position, radius, color, duration, depthTest) DebugDraw::DrawPoint(position, radius, color, duration, depthTest) #define DEBUG_DRAW_TRIANGLE(v0, v1, v2, color, duration, depthTest) DebugDraw::DrawTriangle(v0, v1, v2, color, duration, depthTest) #define DEBUG_DRAW_TRIANGLES(vertices, color, duration, depthTest) DebugDraw::DrawTriangles(vertices, color, duration, depthTest) #define DEBUG_DRAW_TRIANGLES_EX(vertices, indices, color, duration, depthTest) DebugDraw::DrawTriangles(vertices, indices, color, duration, depthTest) From ff10fa64e26c9377118e1258d54206d042ebeccc Mon Sep 17 00:00:00 2001 From: Tyler Gregorcyk Date: Fri, 26 Jun 2026 13:06:52 -0500 Subject: [PATCH 2/4] Corrected comment in DebugDraw::DrawPoint Signed-off-by: Tyler Gregorcyk --- Source/Engine/Debug/DebugDraw.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Engine/Debug/DebugDraw.cpp b/Source/Engine/Debug/DebugDraw.cpp index aeb2cb747..0f6ea9c2f 100644 --- a/Source/Engine/Debug/DebugDraw.cpp +++ b/Source/Engine/Debug/DebugDraw.cpp @@ -1548,7 +1548,7 @@ void DebugDraw::DrawPoint(const Vector3& position, float radius, const Color& co Matrix::CreateWorld(positionF, normal, up, world); Matrix::Multiply(scale, world, matrix); - // Draw lines of the unit circle after linear transform + // Build a filled disc as a triangle fan from the center over the transformed unit circle points PROFILE_MEM(EngineDebug); Float3 prev = Float3::Transform(CircleCache[0], matrix); for (int32 i = 1; i < DEBUG_DRAW_CIRCLE_VERTICES;) From b23f4571ab8a53b0e608b94a8246a72450aa37c1 Mon Sep 17 00:00:00 2001 From: Tyler Gregorcyk Date: Fri, 26 Jun 2026 13:39:12 -0500 Subject: [PATCH 3/4] Halved DrawPoints traingle count by skipping degenerate wedges Signed-off-by: Tyler Gregorcyk --- Source/Engine/Debug/DebugDraw.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/Source/Engine/Debug/DebugDraw.cpp b/Source/Engine/Debug/DebugDraw.cpp index 0f6ea9c2f..d025448b1 100644 --- a/Source/Engine/Debug/DebugDraw.cpp +++ b/Source/Engine/Debug/DebugDraw.cpp @@ -1550,18 +1550,15 @@ void DebugDraw::DrawPoint(const Vector3& position, float radius, const Color& co // Build a filled disc as a triangle fan from the center over the transformed unit circle points PROFILE_MEM(EngineDebug); - Float3 prev = Float3::Transform(CircleCache[0], matrix); - for (int32 i = 1; i < DEBUG_DRAW_CIRCLE_VERTICES;) + for (int32 i = 0; i < DEBUG_DRAW_CIRCLE_VERTICES; i += 2) { - Float3 cur = Float3::Transform(CircleCache[i++], matrix); DebugTriangle t; t.Color = Color32(color); t.TimeLeft = duration; t.V0 = positionF; - t.V1 = prev; - t.V2 = cur; + t.V1 = Float3::Transform(CircleCache[i], matrix); + t.V2 = Float3::Transform(CircleCache[i + 1], matrix); (depthTest ? Context->DebugDrawDepthTest : Context->DebugDrawDefault).Add(t); - prev = cur; } } From db24203b8ab5c1701b5500078168010048246189 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Tue, 30 Jun 2026 08:42:47 +0200 Subject: [PATCH 4/4] Minor adjustment to #4165 --- Source/Engine/Debug/DebugDraw.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Source/Engine/Debug/DebugDraw.cpp b/Source/Engine/Debug/DebugDraw.cpp index d025448b1..1699626aa 100644 --- a/Source/Engine/Debug/DebugDraw.cpp +++ b/Source/Engine/Debug/DebugDraw.cpp @@ -1550,6 +1550,8 @@ void DebugDraw::DrawPoint(const Vector3& position, float radius, const Color& co // Build a filled disc as a triangle fan from the center over the transformed unit circle points PROFILE_MEM(EngineDebug); + auto& debugDrawData = depthTest ? Context->DebugDrawDepthTest : Context->DebugDrawDefault; + auto& debugDrawList = duration > 0 ? debugDrawData.DefaultTriangles : debugDrawData.OneFrameTriangles; for (int32 i = 0; i < DEBUG_DRAW_CIRCLE_VERTICES; i += 2) { DebugTriangle t; @@ -1558,7 +1560,7 @@ void DebugDraw::DrawPoint(const Vector3& position, float radius, const Color& co t.V0 = positionF; t.V1 = Float3::Transform(CircleCache[i], matrix); t.V2 = Float3::Transform(CircleCache[i + 1], matrix); - (depthTest ? Context->DebugDrawDepthTest : Context->DebugDrawDefault).Add(t); + debugDrawList.Add(t); } }