From 44374a84a7d47de4860f9f4642441136f8f1138b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20L=C3=BCbe=C3=9F?= Date: Sat, 11 Sep 2021 17:50:30 +0200 Subject: [PATCH] Added DrawCoordinateCross function --- GlitchyEngine/src/Renderer/DebugRenderer.bf | 28 ++++++++++++++++++--- Sandbox/src/SandboxApp.bf | 4 +-- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/GlitchyEngine/src/Renderer/DebugRenderer.bf b/GlitchyEngine/src/Renderer/DebugRenderer.bf index 52472ca..82ff729 100644 --- a/GlitchyEngine/src/Renderer/DebugRenderer.bf +++ b/GlitchyEngine/src/Renderer/DebugRenderer.bf @@ -7,6 +7,8 @@ namespace GlitchyEngine.Renderer public static class DebugRenderer { private static GeometryBinding CoordinateCross; + + public static bool DrawEntityTransforms = true; public static void Init(GraphicsContext context) { @@ -24,7 +26,27 @@ namespace GlitchyEngine.Renderer CoordinateCross.ReleaseRef(); } - public static bool DrawEntityTransforms = true; + /** + * Draws a coordinate cross for the given matrix. + * @param transform The transform matrix. + * @param length Can be used to set a fixed length for the rendered lines that represent the axes. + * Set to 0 if you want transform to affect the length of the lines. + */ + public static void DrawCoordinateCross(Matrix transform, float length = 0.0f) + { + var transform; + + if(length != 0.0f) + { + transform.Columns[0]..Normalize() *= length; + transform.Columns[1]..Normalize() *= length; + transform.Columns[2]..Normalize() *= length; + } + + Renderer.DrawLine(.Zero, .Right, .Red, transform); + Renderer.DrawLine(.Zero, .Up, .Lime, transform); + Renderer.DrawLine(.Zero, .Forward, .Blue, transform); + } public static void Render(EcsWorld world) { @@ -32,9 +54,7 @@ namespace GlitchyEngine.Renderer { for(var (entity, transform) in world.Enumerate()) { - Renderer.DrawLine(.Zero, Vector3(1f, 0, 0), .Red, transform.WorldTransform); - Renderer.DrawLine(.Zero, Vector3(0, 1f, 0), .Lime, transform.WorldTransform); - Renderer.DrawLine(.Zero, Vector3(0, 0, 1f), .Blue, transform.WorldTransform); + DrawCoordinateCross(transform.WorldTransform); } } } diff --git a/Sandbox/src/SandboxApp.bf b/Sandbox/src/SandboxApp.bf index ca54a57..c5bb686 100644 --- a/Sandbox/src/SandboxApp.bf +++ b/Sandbox/src/SandboxApp.bf @@ -464,9 +464,7 @@ namespace Sandbox Renderer.DrawLine(start, end, .Black, transform.WorldTransform); } - Renderer.DrawLine(.Zero, Vector3(0.1f, 0, 0), .Red, transform.WorldTransform * mat); - Renderer.DrawLine(.Zero, Vector3(0, 0.1f, 0), .Lime, transform.WorldTransform * mat); - Renderer.DrawLine(.Zero, Vector3(0, 0, 0.1f), .Blue, transform.WorldTransform * mat); + DebugRenderer.DrawCoordinateCross(transform.WorldTransform * mat, 2.0f); i++; }