From 4fc55f484917e48f4be8c02b77e2e779a1d05cde Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Wed, 14 Jul 2021 13:40:34 +0200 Subject: [PATCH] Add `DebugDraw::DrawTube` --- Source/Engine/Debug/DebugDraw.cpp | 20 +++++++++++++++++++- Source/Engine/Debug/DebugDraw.h | 14 ++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/Source/Engine/Debug/DebugDraw.cpp b/Source/Engine/Debug/DebugDraw.cpp index ac2b744bc..42077a8f2 100644 --- a/Source/Engine/Debug/DebugDraw.cpp +++ b/Source/Engine/Debug/DebugDraw.cpp @@ -1269,12 +1269,30 @@ void DebugDraw::DrawWireTriangles(const Array& vertices, const Array(vertices.Get(), vertices.Count()), Span(indices.Get(), indices.Count()), color, duration, depthTest); } +void DebugDraw::DrawTube(const Vector3& position, const Quaternion& orientation, float radius, float length, const Color& color, float duration, bool depthTest) +{ + // Check if has no length (just sphere) + if (length < ZeroTolerance) + { + DrawSphere(BoundingSphere(position, radius), color, duration, depthTest); + } + else + { + const Vector3 dir = orientation * Vector3::Forward; + radius = Math::Max(radius, 0.05f); + length = Math::Max(length, 0.05f); + const float halfLength = length / 2.0f; + DrawSphere(BoundingSphere(position + dir * halfLength, radius), color, duration, depthTest); + DrawSphere(BoundingSphere(position - dir * halfLength, radius), color, duration, depthTest); + DrawCylinder(position, orientation * Quaternion::Euler(90.0f, 0, 0), radius, length, color, duration, depthTest); + } +} + void DebugDraw::DrawWireTube(const Vector3& position, const Quaternion& orientation, float radius, float length, const Color& color, float duration, bool depthTest) { // Check if has no length (just sphere) if (length < ZeroTolerance) { - // Draw sphere DrawWireSphere(BoundingSphere(position, radius), color, duration, depthTest); } else diff --git a/Source/Engine/Debug/DebugDraw.h b/Source/Engine/Debug/DebugDraw.h index 31cdf88a4..41f03adc7 100644 --- a/Source/Engine/Debug/DebugDraw.h +++ b/Source/Engine/Debug/DebugDraw.h @@ -256,6 +256,18 @@ DECLARE_SCRIPTING_TYPE_NO_SPAWN(DebugDraw); /// If set to true depth test will be performed, otherwise depth will be ignored. API_FUNCTION() static void DrawSphere(const BoundingSphere& sphere, const Color& color, float duration = 0.0f, bool depthTest = true); + /// + /// Draws the tube. + /// + /// The center position. + /// The orientation. + /// The radius. + /// The length. + /// 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 DrawTube(const Vector3& position, const Quaternion& orientation, float radius, float length, const Color& color, float duration = 0.0f, bool depthTest = true); + /// /// Draws the wireframe tube. /// @@ -360,6 +372,7 @@ DECLARE_SCRIPTING_TYPE_NO_SPAWN(DebugDraw); #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) #define DEBUG_DRAW_SPHERE(sphere, color, duration, depthTest) DebugDraw::DrawSphere(sphere, color, duration, depthTest) +#define DEBUG_DRAW_TUBE(position, orientation, radius, length, color, duration, depthTest) DebugDraw::DrawTube(position, orientation, radius, length, color, duration, depthTest) #define DEBUG_DRAW_BOX(box, color, duration, depthTest) DebugDraw::DrawBox(box, color, duration, depthTest) #define DEBUG_DRAW_CYLINDER(position, orientation, radius, height, color, duration, depthTest) DebugDraw::DrawCylinder(position, orientation, radius, height, color, duration, depthTest) #define DEBUG_DRAW_WIRE_TRIANGLE(v0, v1, v2, color, duration, depthTest) DebugDraw::DrawWireTriangle(v0, v1, v2, color, duration, depthTest) @@ -383,6 +396,7 @@ DECLARE_SCRIPTING_TYPE_NO_SPAWN(DebugDraw); #define DEBUG_DRAW_TRIANGLES(vertices, color, duration, depthTest) #define DEBUG_DRAW_TRIANGLES_EX(vertices, indices, color, duration, depthTest) #define DEBUG_DRAW_SPHERE(sphere, color, duration, depthTest) +#define DEBUG_DRAW_TUBE(position, orientation, radius, length, color, duration, depthTest) #define DEBUG_DRAW_BOX(box, color, duration, depthTest) #define DEBUG_DRAW_CYLINDER(position, orientation, radius, height, color, duration, depthTest) #define DEBUG_DRAW_WIRE_TRIANGLE(v0, v1, v2, color, duration, depthTest)