From ba319d8499ff20e6a34b82be8888b5d2b64e5d9b Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Sat, 29 Apr 2023 12:09:36 +0200 Subject: [PATCH] Add scale parameter to `DebugDraw` text drawing to rescale text without reducing font size --- Source/Engine/Debug/DebugDraw.cpp | 10 ++++++++-- Source/Engine/Debug/DebugDraw.h | 3 ++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Source/Engine/Debug/DebugDraw.cpp b/Source/Engine/Debug/DebugDraw.cpp index a1dfa0b61..47a2b6534 100644 --- a/Source/Engine/Debug/DebugDraw.cpp +++ b/Source/Engine/Debug/DebugDraw.cpp @@ -454,7 +454,12 @@ inline void DrawText3D(const DebugText3D& t, const RenderContext& renderContext, { Matrix w, fw, m; if (t.FaceCamera) - Matrix::CreateWorld(t.Transform.Translation, renderContext.View.Direction, viewUp, w); + { + Matrix s, ss; + Matrix::Scaling(t.Transform.Scale.X, s); + Matrix::CreateWorld(t.Transform.Translation, renderContext.View.Direction, viewUp, ss); + Matrix::Multiply(s, ss, w); + } else t.Transform.GetWorld(w); Matrix::Multiply(f, w, fw); @@ -1993,7 +1998,7 @@ void DebugDraw::DrawText(const StringView& text, const Float2& position, const C t.TimeLeft = duration; } -void DebugDraw::DrawText(const StringView& text, const Vector3& position, const Color& color, int32 size, float duration) +void DebugDraw::DrawText(const StringView& text, const Vector3& position, const Color& color, int32 size, float duration, float scale) { if (text.Length() == 0 || size < 4) return; @@ -2003,6 +2008,7 @@ void DebugDraw::DrawText(const StringView& text, const Vector3& position, const Platform::MemoryCopy(t.Text.Get(), text.Get(), text.Length() * sizeof(Char)); t.Text[text.Length()] = 0; t.Transform = position - Context->Origin; + t.Transform.Scale.X = scale; t.FaceCamera = true; t.Size = size; t.Color = color; diff --git a/Source/Engine/Debug/DebugDraw.h b/Source/Engine/Debug/DebugDraw.h index b37080d0f..8cc5452ed 100644 --- a/Source/Engine/Debug/DebugDraw.h +++ b/Source/Engine/Debug/DebugDraw.h @@ -590,7 +590,8 @@ API_CLASS(Static) class FLAXENGINE_API DebugDraw /// The color. /// The font size. /// The duration (in seconds). Use 0 to draw it only once. - API_FUNCTION() static void DrawText(const StringView& text, const Vector3& position, const Color& color, int32 size = 32, float duration = 0.0f); + /// The text scale. + API_FUNCTION() static void DrawText(const StringView& text, const Vector3& position, const Color& color, int32 size = 32, float duration = 0.0f, float scale = 1.0f); /// /// Draws the text (3D).