From 8978515cb99b9c58c8ceb1b14681f1cbbf0c33cf Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Thu, 15 Dec 2022 23:25:49 +0800 Subject: [PATCH] Reworked SHDebugDraw to fit new interface of SHDebugDrawSystem --- SHADE_Engine/src/Editor/SHEditor.cpp | 59 +-- .../MiddleEnd/Interface/SHDebugDrawSystem.h | 215 +++++++++-- SHADE_Engine/src/Tools/SHDebugDraw.cpp | 159 +++++--- SHADE_Engine/src/Tools/SHDebugDraw.h | 354 +++++++++++++++--- SHADE_Managed/src/Utility/Gizmos.cxx | 2 +- 5 files changed, 636 insertions(+), 153 deletions(-) diff --git a/SHADE_Engine/src/Editor/SHEditor.cpp b/SHADE_Engine/src/Editor/SHEditor.cpp index abddf457..4f1586ac 100644 --- a/SHADE_Engine/src/Editor/SHEditor.cpp +++ b/SHADE_Engine/src/Editor/SHEditor.cpp @@ -271,7 +271,7 @@ namespace SHADE void SHEditor::SetUpGridLines(bool drawGrid, bool drawAxes) { // Clear existing lines - SHDebugDraw::ClearPersistentDraws(); + SHDebugDraw::Persistent::ClearDraws(); static constexpr float DELTA = 1.0f; static constexpr int EXTENT_COUNT = static_cast(500.0f /* TODO: Remove hard code */ / DELTA); @@ -284,30 +284,34 @@ namespace SHADE for (int i = 1; i < EXTENT_COUNT; ++i) { // X-Axis Lines - SHDebugDraw::PersistentLine - ( - GRID_COL, + SHDebugDraw::Persistent::Line + ( SHVec3 { -LINE_HALF_LENGTH, 0.0f, i * DELTA }, - SHVec3 { LINE_HALF_LENGTH, 0.0f, i * DELTA } - ); - SHDebugDraw::PersistentLine - ( + SHVec3 { LINE_HALF_LENGTH, 0.0f, i * DELTA }, GRID_COL, + true + ); + SHDebugDraw::Persistent::Line + ( SHVec3 { -LINE_HALF_LENGTH, 0.0f, i * -DELTA }, - SHVec3 { LINE_HALF_LENGTH, 0.0f, i * -DELTA } + SHVec3 { LINE_HALF_LENGTH, 0.0f, i * -DELTA }, + GRID_COL, + true ); // Y-Axis Lines - SHDebugDraw::PersistentLine + SHDebugDraw::Persistent::Line ( - GRID_COL, SHVec3 { i * DELTA, 0.0f, -LINE_HALF_LENGTH }, - SHVec3 { i * DELTA, 0.0f, LINE_HALF_LENGTH } - ); - SHDebugDraw::PersistentLine - ( + SHVec3 { i * DELTA, 0.0f, LINE_HALF_LENGTH }, GRID_COL, + true + ); + SHDebugDraw::Persistent::Line + ( SHVec3 { -i * DELTA, 0.0f, -LINE_HALF_LENGTH }, - SHVec3 { -i * DELTA, 0.0f, LINE_HALF_LENGTH } + SHVec3 { -i * DELTA, 0.0f, LINE_HALF_LENGTH }, + GRID_COL, + true ); } } @@ -319,25 +323,28 @@ namespace SHADE const SHColour Y_AXIS_COL = drawAxes ? SHColour::GREEN : GRID_COL; const SHColour Z_AXIS_COL = drawAxes ? SHColour::BLUE : GRID_COL; // X - SHDebugDraw::PersistentLine + SHDebugDraw::Persistent::Line ( - X_AXIS_COL, SHVec3 { -LINE_HALF_LENGTH, 0.0f, 0.0f }, - SHVec3 { LINE_HALF_LENGTH, 0.0f, 0.0f } + SHVec3 { LINE_HALF_LENGTH, 0.0f, 0.0f }, + X_AXIS_COL, + true ); // Y - SHDebugDraw::PersistentLine + SHDebugDraw::Persistent::Line ( - Y_AXIS_COL, SHVec3 { 0.0f, -LINE_HALF_LENGTH, 0.0f }, - SHVec3 { 0.0f, LINE_HALF_LENGTH, 0.0f } + SHVec3 { 0.0f, LINE_HALF_LENGTH, 0.0f }, + Y_AXIS_COL, + true ); // Z - SHDebugDraw::PersistentLine + SHDebugDraw::Persistent::Line ( - Z_AXIS_COL, SHVec3 { 0.0f, 0.0f, -LINE_HALF_LENGTH }, - SHVec3 { 0.0f, 0.0f, LINE_HALF_LENGTH } + SHVec3 { 0.0f, 0.0f, LINE_HALF_LENGTH }, + Z_AXIS_COL, + true ); } } @@ -353,7 +360,7 @@ namespace SHADE break; case State::PLAY: default: - SHDebugDraw::ClearPersistentDraws(); + SHDebugDraw::Persistent::ClearDraws(); break; } return eventData->handle; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHDebugDrawSystem.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHDebugDrawSystem.h index f62a099e..2978d68e 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHDebugDrawSystem.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHDebugDrawSystem.h @@ -46,35 +46,12 @@ namespace SHADE { public: /*---------------------------------------------------------------------------------*/ - /* Type Definitions */ - /*---------------------------------------------------------------------------------*/ - /// - /// Defines the rendering mode for debug lines. - /// - enum class LineRenderMode : uint32_t - { - NoDepthTest, - DepthTested, - Count - }; - /// - /// Defines the rendering mode for debug meshes. - /// - enum class MeshRenderMode : uint32_t - { - FilledNoDepthTest, - FilledDepthTested, - WireNoDepthTest, - WireDepthTested, - Count - }; - /*---------------------------------------------------------------------------------*/ /* System Routines */ /*---------------------------------------------------------------------------------*/ class SH_API ProcessPointsRoutine final : public SHSystemRoutine { public: - ProcessPointsRoutine(); + ProcessPointsRoutine(); virtual void Execute(double dt) noexcept override final; }; @@ -95,31 +72,201 @@ namespace SHADE /*---------------------------------------------------------------------------------*/ /* Draw Functions */ /*---------------------------------------------------------------------------------*/ + /// + /// Draws a line between two specified points. + /// + /// Starting point. + /// Ending point. + /// Colour to draw with. + /// Whether or not drawn object will be occluded. void DrawLine(const SHVec3& start, const SHVec3& end, const SHColour& color = SHColour::WHITE, bool depthTested = false); + /// + /// Draws a set of points as a connected set of lines that loops back. + /// + /// List of points to draw the line across. + /// Colour to draw with. + /// Whether or not drawn object will be occluded. void DrawLineLoop(std::initializer_list points, const SHColour& color = SHColour::WHITE, bool depthTested = false); + /// + /// Draws a set of points as a connected set of lines that loops back. + /// + /// + /// Type of iterator of the container that contains the points. + /// + /// Starting iterator to the line points. + /// One past end iterator to the line points. + /// Colour to draw with. + /// Whether or not drawn object will be occluded. template void DrawLineLoop(IterType pointListBegin, IterType pointListEnd, const SHColour& color = SHColour::WHITE, bool depthTested = false); + /// + /// Draws a triangle from the specified set of points. + /// + /// 1st point. + /// 2nd point. + /// 3rd point. + /// Colour to draw with. + /// Whether or not drawn object will be occluded. void DrawTri(const SHVec3& p1, const SHVec3& p2, const SHVec3& p3, const SHColour& color = SHColour::WHITE, bool depthTested = false); + /// + /// Draws a quad from the specified set of points. + /// + /// 1st point. + /// 2nd point. + /// 3rd point. + /// 4th point. + /// Colour to draw with. + /// Whether or not drawn object will be occluded. void DrawQuad(const SHVec3& p1, const SHVec3& p2, const SHVec3& p3, const SHVec3& p4, const SHColour& color = SHColour::WHITE, bool depthTested = false); + /// + /// Draws a 2-dimensional circle. + /// + /// + /// Matrix transformation that defines how the circle should be drawn. + /// + /// Colour to draw with. + /// Whether or not drawn object will be occluded. void DrawCircle(const SHMatrix& matrix, const SHColour& color = SHColour::WHITE, bool depthTested = false); + /// + /// Draws the outline of a cube. + /// + /// + /// Matrix transformation that defines how the wire cube should be drawn. + /// + /// Colour to draw with. + /// Whether or not drawn object will be occluded. void DrawWireCube(const SHMatrix& matrix, const SHColour& color = SHColour::WHITE, bool depthTested = false); + /// + /// Draws the wireframe of a sphere. + /// + /// + /// Matrix transformation that defines how the sphere should be drawn. + /// + /// Colour to draw with. + /// Whether or not drawn object will be occluded. void DrawWireSphere(const SHMatrix& matrix, const SHColour& color = SHColour::WHITE, bool depthTested = false); + /// + /// Draws a filled cube. + /// + /// + /// Matrix transformation that defines how the cube should be drawn. + /// + /// Colour to draw with. + /// Whether or not drawn object will be occluded. void DrawCube(const SHMatrix& matrix, const SHColour& color = SHColour::WHITE, bool depthTested = false); + /// + /// Draws a filled sphere. + /// + /// + /// Matrix transformation that defines how the sphere should be drawn. + /// + /// Colour to draw with. + /// Whether or not drawn object will be occluded. void DrawSphere(const SHMatrix& matrix, const SHColour& color = SHColour::WHITE, bool depthTested = false); /*---------------------------------------------------------------------------------*/ /* Persistent Draw Functions */ /*---------------------------------------------------------------------------------*/ + /// + /// Draws a persistent line between two specified points. + /// This will remain drawn until ClearPersistentDraws() is called. + /// + /// Starting point. + /// Ending point. + /// Colour to draw with. + /// Whether or not drawn object will be occluded. void DrawPersistentLine(const SHVec3& start, const SHVec3& end, const SHColour& color = SHColour::WHITE, bool depthTested = false); + /// + /// Draws a persistent set of points as a connected set of lines that loops back. + /// This will remain drawn until ClearPersistentDraws() is called. + /// + /// List of points to draw the line across. + /// Colour to draw with. + /// Whether or not drawn object will be occluded. void DrawPersistentLineLoop(std::initializer_list points, const SHColour& color = SHColour::WHITE, bool depthTested = false); + /// + /// Draws a persistent set of points as a connected set of lines that loops back. + /// This will remain drawn until ClearPersistentDraws() is called. + /// + /// + /// Type of iterator of the container that contains the points. + /// + /// Starting iterator to the line points. + /// One past end iterator to the line points. + /// Colour to draw with. + /// Whether or not drawn object will be occluded. template void DrawPersistentLineLoop(IterType pointListBegin, IterType pointListEnd, const SHColour& color = SHColour::WHITE, bool depthTested = false); + /// + /// Draws a persistent triangle from the specified set of points. + /// This will remain drawn until ClearPersistentDraws() is called. + /// + /// 1st point. + /// 2nd point. + /// 3rd point. + /// Colour to draw with. + /// Whether or not drawn object will be occluded. void DrawPersistentTri(const SHVec3& p1, const SHVec3& p2, const SHVec3& p3, const SHColour& color = SHColour::WHITE, bool depthTested = false); + /// + /// Draws a persistent quad from the specified set of points. + /// This will remain drawn until ClearPersistentDraws() is called. + /// + /// 1st point. + /// 2nd point. + /// 3rd point. + /// 4th point. + /// Colour to draw with. + /// Whether or not drawn object will be occluded. void DrawPersistentQuad(const SHVec3& p1, const SHVec3& p2, const SHVec3& p3, const SHVec3& p4, const SHColour& color = SHColour::WHITE, bool depthTested = false); + /// + /// Draws a persistent 2-dimensional circle. + /// This will remain drawn until ClearPersistentDraws() is called. + /// + /// + /// Matrix transformation that defines how the circle should be drawn. + /// + /// Colour to draw with. + /// Whether or not drawn object will be occluded. void DrawPersistentCircle(const SHMatrix& matrix, const SHColour& color = SHColour::WHITE, bool depthTested = false); + /// + /// Draws the outline of a persistent cube. + /// This will remain drawn until ClearPersistentDraws() is called. + /// + /// + /// Matrix transformation that defines how the wire cube should be drawn. + /// + /// Colour to draw with. + /// Whether or not drawn object will be occluded. void DrawPersistentWireCube(const SHMatrix& matrix, const SHColour& color = SHColour::WHITE, bool depthTested = false); + /// + /// Draws the wireframe of a persistent sphere. + /// This will remain drawn until ClearPersistentDraws() is called. + /// + /// + /// Matrix transformation that defines how the sphere should be drawn. + /// + /// Colour to draw with. + /// Whether or not drawn object will be occluded. void DrawPersistentWireSphere(const SHMatrix& matrix, const SHColour& color = SHColour::WHITE, bool depthTested = false); + /// + /// Draws a persistent filled cube. + /// This will remain drawn until ClearPersistentDraws() is called. + /// + /// + /// Matrix transformation that defines how the cube should be drawn. + /// + /// Colour to draw with. + /// Whether or not drawn object will be occluded. void DrawPersistentCube(const SHMatrix& matrix, const SHColour& color = SHColour::WHITE, bool depthTested = false); + /// + /// Draws a persistent filled sphere. + /// This will remain drawn until ClearPersistentDraws() is called. + /// + /// + /// Matrix transformation that defines how the sphere should be drawn. + /// + /// Colour to draw with. + /// Whether or not drawn object will be occluded. void DrawPersistentSphere(const SHMatrix& matrix, const SHColour& color = SHColour::WHITE, bool depthTested = false); /// /// Clears any persistent drawn debug primitives. @@ -134,6 +281,26 @@ namespace SHADE using TripleUInt = std::array; using TripleBool = std::array; /// + /// Defines the rendering mode for debug lines. + /// + enum class LineRenderMode : uint32_t + { + NoDepthTest, + DepthTested, + Count + }; + /// + /// Defines the rendering mode for debug meshes. + /// + enum class MeshRenderMode : uint32_t + { + FilledNoDepthTest, + FilledDepthTested, + WireNoDepthTest, + WireDepthTested, + Count + }; + /// /// Defines a coloured Vertex /// struct SH_API PointVertex diff --git a/SHADE_Engine/src/Tools/SHDebugDraw.cpp b/SHADE_Engine/src/Tools/SHDebugDraw.cpp index 15a4bedd..598c8aa6 100644 --- a/SHADE_Engine/src/Tools/SHDebugDraw.cpp +++ b/SHADE_Engine/src/Tools/SHDebugDraw.cpp @@ -16,6 +16,7 @@ of DigiPen Institute of Technology is prohibited. // Project Includes #include "Math/Vector/SHVec4.h" #include "Math/SHQuaternion.h" +#include "Math/SHQuaternion.h" #include "Math/SHColour.h" #include "Graphics/MiddleEnd/Interface/SHDebugDrawSystem.h" #include "ECS_Base/Managers/SHSystemManager.h" @@ -42,110 +43,180 @@ namespace SHADE /*-----------------------------------------------------------------------------------*/ /* Draw Functions */ /*-----------------------------------------------------------------------------------*/ - void SHDebugDraw::Line(const SHVec4& color, const SHVec3& startPt, const SHVec3& endPt) + void SHDebugDraw::Line(const SHVec3& startPt, const SHVec3& endPt, const SHVec4& color, bool depthTested) { - dbgDrawSys->DrawLine(startPt, endPt, color); + dbgDrawSys->DrawLine(startPt, endPt, color, depthTested); } - void SHDebugDraw::Tri(const SHVec4& color, const SHVec3& pt1, const SHVec3& pt2, const SHVec3& pt3) + void SHDebugDraw::Tri(const SHVec3& pt1, const SHVec3& pt2, const SHVec3& pt3, const SHVec4& color, bool depthTested) { - dbgDrawSys->DrawTri(pt1, pt2, pt3, color); + dbgDrawSys->DrawTri(pt1, pt2, pt3, color, depthTested); } - void SHDebugDraw::Quad(const SHVec4& color, const SHVec3& pt1, const SHVec3& pt2, const SHVec3& pt3, const SHVec3& pt4) + void SHDebugDraw::Quad(const SHVec3& pt1, const SHVec3& pt2, const SHVec3& pt3, const SHVec3& pt4, const SHVec4& color, bool depthTested) { - dbgDrawSys->DrawQuad(pt1, pt2, pt3, pt4, color); + dbgDrawSys->DrawQuad(pt1, pt2, pt3, pt4, color, depthTested); } - void SHDebugDraw::Circle(const SHMatrix& mat, const SHVec4& color) + void SHDebugDraw::Circle(const SHMatrix& mat, const SHVec4& color, bool depthTested) { - dbgDrawSys->DrawCircle(mat, color); + dbgDrawSys->DrawCircle(mat, color, depthTested); } - void SHDebugDraw::LineLoop(const SHVec4& color, std::initializer_list pointList) + void SHDebugDraw::LineLoop(const SHVec4& color, std::initializer_list pointList, bool depthTested) { - dbgDrawSys->DrawLineLoop(pointList, color); + dbgDrawSys->DrawLineLoop(pointList, color, depthTested); } - void SHDebugDraw::Cube(const SHMatrix& mat, const SHVec4& color) + void SHDebugDraw::Cube(const SHMatrix& mat, const SHVec4& color, bool depthTested) { - dbgDrawSys->DrawCube(mat, color); + dbgDrawSys->DrawCube(mat, color, depthTested); } - void SHDebugDraw::Sphere(const SHMatrix& mat, const SHVec4& color) + void SHDebugDraw::Cube(const SHVec3& center, const SHVec3& scale, const SHVec4& color, bool depthTested) { - dbgDrawSys->DrawSphere(mat, color); + dbgDrawSys->DrawCube(SHMatrix::Transform(center, SHQuaternion(), scale), color, depthTested); } - void SHDebugDraw::WireCube(const SHMatrix& mat, const SHVec4& color) + void SHDebugDraw::Cube(const SHVec3& center, const SHQuaternion& orientation, const SHVec3& scale, const SHVec4& color, bool depthTested) { - dbgDrawSys->DrawWireCube(mat, color); + dbgDrawSys->DrawCube(SHMatrix::Transform(center, orientation, scale), color, depthTested); + } + + void SHDebugDraw::Cube(const SHVec3& center, const SHVec3& eulerAngles, const SHVec3& scale, const SHVec4& color, bool depthTested) + { + dbgDrawSys->DrawCube(SHMatrix::Transform(center, eulerAngles, scale), color, depthTested); + } + + void SHDebugDraw::Sphere(const SHMatrix& mat, const SHVec4& color, bool depthTested) + { + dbgDrawSys->DrawSphere(mat, color, depthTested); + } + + void SHDebugDraw::Sphere(const SHVec3& center, const SHVec3& scale, const SHVec4& color, bool depthTested) + { + dbgDrawSys->DrawSphere(SHMatrix::Transform(center, SHQuaternion(), scale), color, depthTested); + } + + void SHDebugDraw::Sphere(const SHVec3& center, const SHQuaternion& orientation, SHVec3& scale, const SHVec4& color, bool depthTested) + { + dbgDrawSys->DrawSphere(SHMatrix::Transform(center, orientation, scale), color, depthTested); + } + + void SHDebugDraw::Sphere(const SHVec3& center, const SHVec3& eulerAngles, SHVec3& scale, const SHVec4& color, bool depthTested) + { + dbgDrawSys->DrawSphere(SHMatrix::Transform(center, eulerAngles, scale), color, depthTested); + } + + void SHDebugDraw::WireCube(const SHMatrix& mat, const SHVec4& color, bool depthTested) + { + dbgDrawSys->DrawWireCube(mat, color, depthTested); } - void SHDebugDraw::WireCube(const SHVec3& center, const SHVec3& scale, const SHVec4& color) + void SHDebugDraw::WireCube(const SHVec3& center, const SHVec3& scale, const SHVec4& color, bool depthTested) { - dbgDrawSys->DrawWireCube(SHMatrix::Transform(center, SHQuaternion(), scale), color); + dbgDrawSys->DrawWireCube(SHMatrix::Transform(center, SHQuaternion(), scale), color, depthTested); } - void SHDebugDraw::WireSphere(const SHMatrix& mat, const SHVec4& color) + void SHDebugDraw::WireSphere(const SHMatrix& mat, const SHVec4& color, bool depthTested) { - dbgDrawSys->DrawWireSphere(mat, color); + dbgDrawSys->DrawWireSphere(mat, color, depthTested); } - void SHDebugDraw::WireSphere(const SHVec3& center, const SHVec3& scale, const SHVec4& color) + void SHDebugDraw::WireSphere(const SHVec3& center, const SHVec3& scale, const SHVec4& color, bool depthTested) { - dbgDrawSys->DrawWireSphere(SHMatrix::Transform(center, SHQuaternion(), scale), color); + dbgDrawSys->DrawWireSphere(SHMatrix::Transform(center, SHQuaternion(), scale), color, depthTested); } /*-----------------------------------------------------------------------------------*/ /* Persistent Draw Functions */ /*-----------------------------------------------------------------------------------*/ - void SHDebugDraw::PersistentLine(const SHVec4& color, const SHVec3& startPt, const SHVec3& endPt) + void SHDebugDraw::Persistent::Line(const SHVec3& startPt, const SHVec3& endPt, const SHVec4& color, bool depthTested) { - dbgDrawSys->DrawPersistentLine(startPt, endPt, color); + dbgDrawSys->DrawPersistentLine(startPt, endPt, color, depthTested); } - void SHDebugDraw::PersistentTri(const SHVec4& color, const SHVec3& pt1, const SHVec3& pt2, const SHVec3& pt3) + void SHDebugDraw::Persistent::Tri(const SHVec3& pt1, const SHVec3& pt2, const SHVec3& pt3, const SHVec4& color, bool depthTested) { - dbgDrawSys->DrawPersistentTri(pt1, pt2, pt3, color); + dbgDrawSys->DrawPersistentTri(pt1, pt2, pt3, color, depthTested); } - void SHDebugDraw::PersistentQuad(const SHVec4& color, const SHVec3& pt1, const SHVec3& pt2, const SHVec3& pt3, const SHVec3& pt4) + void SHDebugDraw::Persistent::Quad(const SHVec3& pt1, const SHVec3& pt2, const SHVec3& pt3, const SHVec3& pt4, const SHVec4& color, bool depthTested) { - dbgDrawSys->DrawPersistentQuad(pt1, pt2, pt3, pt4, color); + dbgDrawSys->DrawPersistentQuad(pt1, pt2, pt3, pt4, color, depthTested); } - void SHDebugDraw::PersistentCircle(const SHMatrix& mat, const SHVec4& color) + void SHDebugDraw::Persistent::Circle(const SHMatrix& mat, const SHVec4& color, bool depthTested) { - dbgDrawSys->DrawPersistentCircle(mat, color); + dbgDrawSys->DrawPersistentCircle(mat, color, depthTested); } - void SHDebugDraw::PersistentLineLoop(const SHVec4& color, std::initializer_list pointList) + void SHDebugDraw::Persistent::LineLoop(const SHVec4& color, std::initializer_list pointList, bool depthTested) { - dbgDrawSys->DrawPersistentLineLoop(pointList, color); + dbgDrawSys->DrawPersistentLineLoop(pointList, color, depthTested); + } + + void SHDebugDraw::Persistent::Cube(const SHMatrix& mat, const SHVec4& color, bool depthTested) + { + dbgDrawSys->DrawPersistentCube(mat, color, depthTested); + } + + void SHDebugDraw::Persistent::Cube(const SHVec3& center, const SHVec3& scale, const SHVec4& color, bool depthTested) + { + dbgDrawSys->DrawPersistentCube(SHMatrix::Transform(center, SHQuaternion(), scale), color, depthTested); + } + + void SHDebugDraw::Persistent::Cube(const SHVec3& center, const SHQuaternion& orientation, const SHVec3& scale, const SHVec4& color, bool depthTested) + { + dbgDrawSys->DrawPersistentCube(SHMatrix::Transform(center, orientation, scale), color, depthTested); + } + + void SHDebugDraw::Persistent::Cube(const SHVec3& center, const SHVec3& eulerAngles, const SHVec3& scale, const SHVec4& color, bool depthTested) + { + dbgDrawSys->DrawPersistentCube(SHMatrix::Transform(center, eulerAngles, scale), color, depthTested); + } + + void SHDebugDraw::Persistent::Sphere(const SHMatrix& mat, const SHVec4& color, bool depthTested) + { + dbgDrawSys->DrawPersistentSphere(mat, color, depthTested); + } + + void SHDebugDraw::Persistent::Sphere(const SHVec3& center, const SHVec3& scale, const SHVec4& color, bool depthTested) + { + dbgDrawSys->DrawPersistentSphere(SHMatrix::Transform(center, SHQuaternion(), scale), color, depthTested); + } + + void SHDebugDraw::Persistent::Sphere(const SHVec3& center, const SHQuaternion& orientation, SHVec3& scale, const SHVec4& color, bool depthTested) + { + dbgDrawSys->DrawPersistentSphere(SHMatrix::Transform(center, orientation, scale), color, depthTested); + } + + void SHDebugDraw::Persistent::Sphere(const SHVec3& center, const SHVec3& eulerAngles, SHVec3& scale, const SHVec4& color, bool depthTested) + { + dbgDrawSys->DrawPersistentSphere(SHMatrix::Transform(center, eulerAngles, scale), color, depthTested); + } + + void SHDebugDraw::Persistent::WireCube(const SHMatrix& mat, const SHVec4& color, bool depthTested) + { + dbgDrawSys->DrawPersistentWireCube(mat, color, depthTested); } - void SHDebugDraw::PersistentCube(const SHMatrix& mat, const SHVec4& color) + void SHDebugDraw::Persistent::WireCube(const SHVec3& center, const SHVec3& scale, const SHVec4& color, bool depthTested) { - dbgDrawSys->DrawPersistentCube(mat, color); + dbgDrawSys->DrawPersistentWireCube(SHMatrix::Transform(center, SHQuaternion(), scale), color, depthTested); } - void SHDebugDraw::PersistentSphere(const SHMatrix& mat, const SHVec4& color) + void SHDebugDraw::Persistent::WireSphere(const SHMatrix& mat, const SHVec4& color, bool depthTested) { - dbgDrawSys->DrawPersistentSphere(mat, color); + dbgDrawSys->DrawPersistentWireSphere(mat, color, depthTested); } - void SHDebugDraw::PersistentWireCube(const SHMatrix& mat, const SHVec4& color) + void SHDebugDraw::Persistent::WireSphere(const SHVec3& center, const SHVec3& scale, const SHVec4& color, bool depthTested) { - dbgDrawSys->DrawPersistentWireCube(mat, color); + dbgDrawSys->DrawPersistentWireSphere(SHMatrix::Transform(center, SHQuaternion(), scale), color, depthTested); } - void SHDebugDraw::PersistentWireSphere(const SHMatrix& mat, const SHVec4& color) - { - dbgDrawSys->DrawPersistentWireSphere(mat, color); - } - - void SHDebugDraw::ClearPersistentDraws() + void SHDebugDraw::Persistent::ClearDraws() { dbgDrawSys->ClearPersistentDraws(); } diff --git a/SHADE_Engine/src/Tools/SHDebugDraw.h b/SHADE_Engine/src/Tools/SHDebugDraw.h index 5438d8f3..4b1f44f0 100644 --- a/SHADE_Engine/src/Tools/SHDebugDraw.h +++ b/SHADE_Engine/src/Tools/SHDebugDraw.h @@ -22,6 +22,7 @@ namespace SHADE class SHDebugDrawSystem; class SHVec4; class SHVec3; + class SHQuaternion; class SHMatrix; class SHColour; @@ -51,87 +52,324 @@ namespace SHADE /// /// Renders a line between two points in world space. /// - /// Colour of the line. /// First point of the line. /// Second point of the line. - static void Line(const SHVec4& color, const SHVec3& startPt, const SHVec3& endPt); + /// Colour of the line. + /// Whether or not drawn object will be occluded. + static void Line(const SHVec3& startPt, const SHVec3& endPt, const SHVec4& color, bool depthTested = false); /// /// Renders a triangle indicated by three points in world space. /// - /// Colour of the triangle. /// First point of the triangle. /// Second point of the triangle. /// Third point of the triangle. - static void Tri(const SHVec4& color, const SHVec3& pt1, const SHVec3& pt2, const SHVec3& pt3); + /// Colour of the triangle. + /// Whether or not drawn object will be occluded. + static void Tri(const SHVec3& pt1, const SHVec3& pt2, const SHVec3& pt3, const SHVec4& color, bool depthTested = false); /// /// Renders a quadrilateral indicated by four points in world space. /// - /// Colour of the quadrilateral. /// First point of the triangle. /// Second point of the quadrilateral. /// Third point of the quadrilateral. /// Third point of the quadrilateral. - static void Quad(const SHVec4& color, const SHVec3& pt1, const SHVec3& pt2, const SHVec3& pt3, const SHVec3& pt4); - static void Circle(const SHMatrix& mat,const SHVec4& color); + /// Colour of the quadrilateral. + /// Whether or not drawn object will be occluded. + static void Quad(const SHVec3& pt1, const SHVec3& pt2, const SHVec3& pt3, const SHVec3& pt4, const SHVec4& color, bool depthTested = false); + /// + /// Draws a 2-dimensional circle in world space. + /// + /// + /// Matrix transformation that defines how the circle should be drawn. + /// + /// Colour to draw with. + /// Whether or not drawn object will be occluded. + static void Circle(const SHMatrix& mat,const SHVec4& color, bool depthTested = false); /// /// Renders a polygon indicated by the specified set of points in world space. /// /// Colour of the polygon. /// List of points for the polygon. - static void LineLoop(const SHVec4& color, std::initializer_list pointList); - static void Cube(const SHMatrix& mat, const SHVec4& color); - static void Sphere(const SHMatrix& mat, const SHVec4& color); - static void WireCube(const SHMatrix& mat, const SHVec4& color); - static void WireCube(const SHVec3& center, const SHVec3& scale, const SHVec4& color); - static void WireSphere(const SHMatrix& mat, const SHVec4& color); - static void WireSphere(const SHVec3& center, const SHVec3& scale, const SHVec4& color); + /// Whether or not drawn object will be occluded. + static void LineLoop(const SHVec4& color, std::initializer_list pointList, bool depthTested = false); + /// + /// Draws a filled cube in world space. + /// + /// + /// Matrix transformation that defines how the cube should be drawn. + /// + /// Colour to draw with. + /// Whether or not drawn object will be occluded. + static void Cube(const SHMatrix& mat, const SHVec4& color, bool depthTested = false); + /// + /// Draws a filled cube in world space. + /// + /// Center of the Cube. + /// Size of the Cube. + /// Colour to draw with. + /// Whether or not drawn object will be occluded. + static void Cube(const SHVec3& center, const SHVec3& scale, const SHVec4& color, bool depthTested = false); + /// + /// Draws a filled cube in world space. + /// + /// Center of the Cube. + /// Orientation of the cube. + /// Size of the Cube. + /// Colour to draw with. + /// Whether or not drawn object will be occluded. + static void Cube(const SHVec3& center, const SHQuaternion& orientation, const SHVec3& scale, const SHVec4& color, bool depthTested = false); + /// + /// Draws a filled cube in world space. + /// + /// Center of the Cube. + /// Euler angle rotation of the cube in radians. + /// Size of the Cube. + /// Colour to draw with. + /// Whether or not drawn object will be occluded. + static void Cube(const SHVec3& center, const SHVec3& eulerAngles, const SHVec3& scale, const SHVec4& color, bool depthTested = false); + /// + /// Draws a filled sphere in world space. + /// + /// + /// Matrix transformation that defines how the sphere should be drawn. + /// + /// Colour to draw with. + /// Whether or not drawn object will be occluded. + static void Sphere(const SHMatrix& mat, const SHVec4& color, bool depthTested = false); + /// + /// Draws a filled sphere in world space. + /// + /// Center point of the sphere. + /// Size of the sphere. + /// Colour to draw with. + /// Whether or not drawn object will be occluded. + static void Sphere(const SHVec3& center, const SHVec3& scale, const SHVec4& color, bool depthTested = false); + /// + /// Draws a filled sphere in world space. + /// + /// Center point of the sphere. + /// Orientation of the sphere. + /// Colour to draw with. + /// Whether or not drawn object will be occluded. + static void Sphere(const SHVec3& center, const SHQuaternion& orientation, SHVec3& scale, const SHVec4& color, bool depthTested = false); + /// + /// Draws a filled sphere in world space. + /// + /// Center point of the sphere. + /// Euler angle rotation of the sphere in radians. + /// Colour to draw with. + /// Whether or not drawn object will be occluded. + static void Sphere(const SHVec3& center, const SHVec3& eulerAngles, SHVec3& scale, const SHVec4& color, bool depthTested = false); + /// + /// Draws the outline of a cube in world space. + /// + /// + /// Matrix transformation that defines how the wire cube should be drawn. + /// + /// Colour to draw with. + /// Whether or not drawn object will be occluded. + static void WireCube(const SHMatrix& mat, const SHVec4& color, bool depthTested = false); + /// + /// Draws the outline of a cube in world space. + /// + /// Center of the Cube. + /// Size of the Cube. + /// Colour to draw with. + /// Whether or not drawn object will be occluded. + static void WireCube(const SHVec3& center, const SHVec3& scale, const SHVec4& color, bool depthTested = false); + /// + /// Draws the wireframe of a sphere in world space. + /// + /// + /// Matrix transformation that defines how the sphere should be drawn. + /// + /// Colour to draw with. + /// Whether or not drawn object will be occluded. + static void WireSphere(const SHMatrix& mat, const SHVec4& color, bool depthTested = false); + /// + /// Draws the wireframe of a sphere in world space. + /// + /// Center point of the sphere. + /// Size of the sphere. + /// Colour to draw with. + /// Whether or not drawn object will be occluded. + static void WireSphere(const SHVec3& center, const SHVec3& scale, const SHVec4& color, bool depthTested = false); /*---------------------------------------------------------------------------------*/ - /* Persistent Draw Functions */ + /* Persistent Draw Function Class "Folder" */ /*---------------------------------------------------------------------------------*/ - /// - /// Renders a line between two points in world space that will persist until - /// ClearPersistentDraws() is called. - /// - /// Colour of the line. - /// First point of the line. - /// Second point of the line. - static void PersistentLine(const SHVec4& color, const SHVec3& startPt, const SHVec3& endPt); - /// - /// Renders a triangle indicated by three points in world space that will persist - /// until ClearPersistentDraws() is called. - /// - /// Colour of the triangle. - /// First point of the triangle. - /// Second point of the triangle. - /// Third point of the triangle. - static void PersistentTri(const SHVec4& color, const SHVec3& pt1, const SHVec3& pt2, const SHVec3& pt3); - /// - /// Renders a quadrilateral indicated by four points in world space that will persist - /// until ClearPersistentDraws() is called. - /// - /// Colour of the quadrilateral. - /// First point of the triangle. - /// Second point of the quadrilateral. - /// Third point of the quadrilateral. - /// Third point of the quadrilateral. - static void PersistentQuad(const SHVec4& color, const SHVec3& pt1, const SHVec3& pt2, const SHVec3& pt3, const SHVec3& pt4); - static void PersistentCircle(const SHMatrix& mat,const SHVec4& color); - /// - /// Renders a polygon indicated by the specified set of points in world space that - /// will persist until ClearPersistentDraws() is called. - /// - /// Colour of the polygon. - /// List of points for the polygon. - static void PersistentLineLoop(const SHVec4& color, std::initializer_list pointList); - static void PersistentCube(const SHMatrix& mat, const SHVec4& color); - static void PersistentSphere(const SHMatrix& mat, const SHVec4& color); - static void PersistentWireCube(const SHMatrix& mat, const SHVec4& color); - static void PersistentWireSphere(const SHMatrix& mat, const SHVec4& color); - /// - /// Clears any persistent drawn debug primitives. - /// - static void ClearPersistentDraws(); + struct SH_API Persistent + { + /*-------------------------------------------------------------------------------*/ + /* Persistent Draw Functions */ + /*-------------------------------------------------------------------------------*/ + /// + /// Renders a line between two points in world space. + /// This will remain drawn until ClearDraws() is called. + /// + /// First point of the line. + /// Second point of the line. + /// Colour of the line. + /// Whether or not drawn object will be occluded. + static void Line(const SHVec3& startPt, const SHVec3& endPt, const SHVec4& color, bool depthTested = false); + /// + /// Renders a triangle indicated by three points in world space. + /// This will remain drawn until ClearDraws() is called. + /// + /// First point of the triangle. + /// Second point of the triangle. + /// Third point of the triangle. + /// Colour of the triangle. + /// Whether or not drawn object will be occluded. + static void Tri(const SHVec3& pt1, const SHVec3& pt2, const SHVec3& pt3, const SHVec4& color, bool depthTested = false); + /// + /// Renders a quadrilateral indicated by four points in world space. + /// This will remain drawn until ClearDraws() is called. + /// + /// First point of the triangle. + /// Second point of the quadrilateral. + /// Third point of the quadrilateral. + /// Third point of the quadrilateral. + /// Colour of the quadrilateral. + /// Whether or not drawn object will be occluded. + static void Quad(const SHVec3& pt1, const SHVec3& pt2, const SHVec3& pt3, const SHVec3& pt4, const SHVec4& color, bool depthTested = false); + /// + /// Draws a 2-dimensional circle in world space. + /// This will remain drawn until ClearDraws() is called. + /// + /// + /// Matrix transformation that defines how the circle should be drawn. + /// + /// Colour to draw with. + /// Whether or not drawn object will be occluded. + static void Circle(const SHMatrix& mat,const SHVec4& color, bool depthTested = false); + /// + /// Renders a polygon indicated by the specified set of points in world space. + /// This will remain drawn until ClearDraws() is called. + /// + /// Colour of the polygon. + /// List of points for the polygon. + /// Whether or not drawn object will be occluded. + static void LineLoop(const SHVec4& color, std::initializer_list pointList, bool depthTested = false); + /// + /// Draws a filled cube in world space. + /// This will remain drawn until ClearDraws() is called. + /// + /// + /// Matrix transformation that defines how the cube should be drawn. + /// + /// Colour to draw with. + /// Whether or not drawn object will be occluded. + static void Cube(const SHMatrix& mat, const SHVec4& color, bool depthTested = false); + /// + /// Draws a filled cube in world space. + /// This will remain drawn until ClearDraws() is called. + /// + /// Center of the Cube. + /// Size of the Cube. + /// Colour to draw with. + /// Whether or not drawn object will be occluded. + static void Cube(const SHVec3& center, const SHVec3& scale, const SHVec4& color, bool depthTested = false); + /// + /// Draws a filled cube in world space. + /// This will remain drawn until ClearDraws() is called. + /// + /// Center of the Cube. + /// Orientation of the cube. + /// Size of the Cube. + /// Colour to draw with. + /// Whether or not drawn object will be occluded. + static void Cube(const SHVec3& center, const SHQuaternion& orientation, const SHVec3& scale, const SHVec4& color, bool depthTested = false); + /// + /// Draws a filled cube in world space. + /// This will remain drawn until ClearDraws() is called. + /// + /// Center of the Cube. + /// Euler angle rotation of the cube in radians. + /// Size of the Cube. + /// Colour to draw with. + /// Whether or not drawn object will be occluded. + static void Cube(const SHVec3& center, const SHVec3& eulerAngles, const SHVec3& scale, const SHVec4& color, bool depthTested = false); + /// + /// Draws a filled sphere in world space. + /// This will remain drawn until ClearDraws() is called. + /// + /// + /// Matrix transformation that defines how the sphere should be drawn. + /// + /// Colour to draw with. + /// Whether or not drawn object will be occluded. + static void Sphere(const SHMatrix& mat, const SHVec4& color, bool depthTested = false); + /// + /// Draws a filled sphere in world space. + /// This will remain drawn until ClearDraws() is called. + /// + /// Center point of the sphere. + /// Size of the sphere. + /// Colour to draw with. + /// Whether or not drawn object will be occluded. + static void Sphere(const SHVec3& center, const SHVec3& scale, const SHVec4& color, bool depthTested = false); + /// + /// Draws a filled sphere in world space. + /// This will remain drawn until ClearDraws() is called. + /// + /// Center point of the sphere. + /// Orientation of the sphere. + /// Colour to draw with. + /// Whether or not drawn object will be occluded. + static void Sphere(const SHVec3& center, const SHQuaternion& orientation, SHVec3& scale, const SHVec4& color, bool depthTested = false); + /// + /// Draws a filled sphere in world space. + /// This will remain drawn until ClearDraws() is called. + /// + /// Center point of the sphere. + /// Euler angle rotation of the sphere in radians. + /// Colour to draw with. + /// Whether or not drawn object will be occluded. + static void Sphere(const SHVec3& center, const SHVec3& eulerAngles, SHVec3& scale, const SHVec4& color, bool depthTested = false); + /// + /// Draws the outline of a cube in world space. + /// This will remain drawn until ClearDraws() is called. + /// + /// + /// Matrix transformation that defines how the wire cube should be drawn. + /// + /// Colour to draw with. + /// Whether or not drawn object will be occluded. + static void WireCube(const SHMatrix& mat, const SHVec4& color, bool depthTested = false); + /// + /// Draws the outline of a cube in world space. + /// This will remain drawn until ClearDraws() is called. + /// + /// Center of the Cube. + /// Size of the Cube. + /// Colour to draw with. + /// Whether or not drawn object will be occluded. + static void WireCube(const SHVec3& center, const SHVec3& scale, const SHVec4& color, bool depthTested = false); + /// + /// Draws the wireframe of a sphere in world space. + /// This will remain drawn until ClearDraws() is called. + /// + /// + /// Matrix transformation that defines how the sphere should be drawn. + /// + /// Colour to draw with. + /// Whether or not drawn object will be occluded. + static void WireSphere(const SHMatrix& mat, const SHVec4& color, bool depthTested = false); + /// + /// Draws the wireframe of a sphere in world space. + /// This will remain drawn until ClearDraws() is called. + /// + /// Center point of the sphere. + /// Size of the sphere. + /// Colour to draw with. + /// Whether or not drawn object will be occluded. + static void WireSphere(const SHVec3& center, const SHVec3& scale, const SHVec4& color, bool depthTested = false); + /// + /// Clears any persistent drawn debug primitives. + /// + static void ClearDraws(); + }; private: /*---------------------------------------------------------------------------------*/ diff --git a/SHADE_Managed/src/Utility/Gizmos.cxx b/SHADE_Managed/src/Utility/Gizmos.cxx index fe29e2ff..458b64b6 100644 --- a/SHADE_Managed/src/Utility/Gizmos.cxx +++ b/SHADE_Managed/src/Utility/Gizmos.cxx @@ -44,7 +44,7 @@ namespace SHADE void Gizmos::DrawLine(Vector3 from, Vector3 to, SHADE::Color color) { - SHDebugDraw::Line(Convert::ToNative(color), Convert::ToNative(from), Convert::ToNative(to)); + SHDebugDraw::Line(Convert::ToNative(from), Convert::ToNative(to), Convert::ToNative(color)); } void Gizmos::DrawWireCube(Vector3 center, Vector3 extents)