Added SHDebugDraw convenience static class for debug drawing
This commit is contained in:
parent
ed446002aa
commit
5f7b28e8a0
|
@ -43,6 +43,7 @@
|
|||
#include "Assets/SHAssetManager.h"
|
||||
|
||||
#include "Tools/SHLogger.h"
|
||||
#include "Tools/SHDebugDraw.h"
|
||||
|
||||
using namespace SHADE;
|
||||
|
||||
|
@ -126,6 +127,9 @@ namespace Sandbox
|
|||
SHSceneManager::InitSceneManager<SBTestScene>("TestScene");
|
||||
|
||||
SHFrameRateController::UpdateFRC();
|
||||
|
||||
// Link up SHDebugDraw
|
||||
SHDebugDraw::Init(SHSystemManager::GetSystem<SHDebugDrawSystem>());
|
||||
}
|
||||
|
||||
void SBApplication::Update(void)
|
||||
|
@ -137,12 +141,6 @@ namespace Sandbox
|
|||
{
|
||||
SHFrameRateController::UpdateFRC();
|
||||
SHInputManager::UpdateInput(SHFrameRateController::GetRawDeltaTime());
|
||||
|
||||
auto debugDraw = SHSystemManager::GetSystem<SHDebugDrawSystem>();
|
||||
/*debugDraw->DrawLine(SHVec4(1.0f, 1.0f, 1.0f, 1.0f), SHVec3(-5.0f, 0.0f, 0.0f), SHVec3(5.0f, 0.0f, 0.0f));
|
||||
debugDraw->DrawLine(SHVec4(1.0f, 1.0f, 1.0f, 1.0f), SHVec3(-5.0f, 1.0f, 0.0f), SHVec3(5.0f, 1.0f, 0.0f));*/
|
||||
//debugDraw->DrawCube(SHVec4(1.0f, 1.0f, 1.0f, 1.0f), {}, SHVec3(1.0f, 1.0f, 1.0f));
|
||||
debugDraw->DrawSphere(SHVec4(1.0f, 1.0f, 1.0f, 1.0f), {}, 3.0f);
|
||||
SHSceneManager::UpdateSceneManager();
|
||||
#ifdef SHEDITOR
|
||||
if(editor->editorState == SHEditor::State::PLAY)
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "Math/SHColour.h"
|
||||
#include "Resource/SHResourceManager.h"
|
||||
#include "Graphics/MiddleEnd/Interface/SHDebugDrawSystem.h"
|
||||
#include "Tools/SHDebugDraw.h"
|
||||
|
||||
using namespace SHADE;
|
||||
|
||||
|
@ -188,6 +189,8 @@ namespace Sandbox
|
|||
SHADE::SHScriptEngine* scriptEngine = static_cast<SHADE::SHScriptEngine*>(SHADE::SHSystemManager::GetSystem<SHADE::SHScriptEngine>());
|
||||
scriptEngine->RemoveAllScripts(testObj);
|
||||
}
|
||||
|
||||
SHDebugDraw::Cube(SHColour::CRIMSON, SHVec3(1.0f, 0.0f, 0.0f), SHVec3(1.0f, 1.0f, 1.0f));
|
||||
}
|
||||
|
||||
void SBTestScene::Render()
|
||||
|
|
|
@ -23,29 +23,27 @@ of DigiPen Institute of Technology is prohibited.
|
|||
#include "Resource/SHHandle.h"
|
||||
#include "Graphics/Buffers/SHVkBuffer.h"
|
||||
#include "SHGraphicsConstants.h"
|
||||
#include "Math/SHColour.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Forward Declarations */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Forward Declarations */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
class SHVkBuffer;
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Type Definitions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/***********************************************************************************/
|
||||
/*!
|
||||
\brief
|
||||
Manages the Debug Draw system.
|
||||
*/
|
||||
/***********************************************************************************/
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Type Definitions */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Manages the Debug Draw system.
|
||||
/// </summary>
|
||||
class SH_API SHDebugDrawSystem final : public SHSystem
|
||||
{
|
||||
public:
|
||||
/*-------------------------------------------------------------------------------*/
|
||||
/* System Routines */
|
||||
/*-------------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* System Routines */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
class SH_API ProcessPointsRoutine final : public SHSystemRoutine
|
||||
{
|
||||
public:
|
||||
|
@ -53,27 +51,79 @@ namespace SHADE
|
|||
virtual void Execute(double dt) noexcept override final;
|
||||
};
|
||||
|
||||
/*-------------------------------------------------------------------------------*/
|
||||
/* SHSystem overrides */
|
||||
/*-------------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* SHSystem overrides */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
virtual void Init() override final;
|
||||
virtual void Exit() override final;
|
||||
|
||||
/*-------------------------------------------------------------------------------*/
|
||||
/* Configuration Functions */
|
||||
/*-------------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Configuration Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Configures the line width used to draw all lines in the Debug Draw system.
|
||||
/// </summary>
|
||||
float LineWidth = 1.0f;
|
||||
|
||||
/*-------------------------------------------------------------------------------*/
|
||||
/* Draw Functions */
|
||||
/*-------------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Draw Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Renders a line between two points in world space.
|
||||
/// </summary>
|
||||
/// <param name="color">Colour of the line.</param>
|
||||
/// <param name="startPt">First point of the line.</param>
|
||||
/// <param name="endPt">Second point of the line.</param>
|
||||
void DrawLine(const SHVec4& color, const SHVec3& startPt, const SHVec3& endPt);
|
||||
/// <summary>
|
||||
/// Renders a triangle indicated by three points in world space.
|
||||
/// </summary>
|
||||
/// <param name="color">Colour of the triangle.</param>
|
||||
/// <param name="pt1">First point of the triangle.</param>
|
||||
/// <param name="pt2">Second point of the triangle.</param>
|
||||
/// <param name="pt3">Third point of the triangle.</param>
|
||||
void DrawTri(const SHVec4& color, const SHVec3& pt1, const SHVec3& pt2, const SHVec3& pt3);
|
||||
/// <summary>
|
||||
/// Renders a quadrilateral indicated by four points in world space.
|
||||
/// </summary>
|
||||
/// <param name="color">Colour of the quadrilateral.</param>
|
||||
/// <param name="pt1">First point of the triangle.</param>
|
||||
/// <param name="pt2">Second point of the quadrilateral.</param>
|
||||
/// <param name="pt3">Third point of the quadrilateral.</param>
|
||||
/// <param name="pt4">Third point of the quadrilateral.</param>
|
||||
void DrawQuad(const SHVec4& color, const SHVec3& pt1, const SHVec3& pt2, const SHVec3& pt3, const SHVec3& pt4);
|
||||
/// <summary>
|
||||
/// Renders a polygon indicated by the specified set of points in world space.
|
||||
/// </summary>
|
||||
/// <param name="color">Colour of the polygon.</param>
|
||||
/// <param name="pointList">List of points for the polygon.</param>
|
||||
void DrawPoly(const SHVec4& color, std::initializer_list<SHVec3> pointList);
|
||||
/// <summary>
|
||||
/// Renders a polygon indicated by the specified set of points in world space.
|
||||
/// </summary>
|
||||
/// <typeparam name="IterType">Iterator for a STL-like container.</typeparam>
|
||||
/// <param name="color">Colour of the polygon.</param>
|
||||
/// <param name="pointListBegin">
|
||||
/// Iterator to the first point of the point container.
|
||||
/// </param>
|
||||
/// <param name="pointListEnd">
|
||||
/// One past last iterator of the point container.
|
||||
/// </param>
|
||||
template<typename IterType>
|
||||
void DrawPoly(const SHVec4& color, IterType pointListBegin, IterType pointListEnd);
|
||||
/// <summary>
|
||||
/// Renders a wireframe cube centered around the position specified in world space.
|
||||
/// </summary>
|
||||
/// <param name="color">Colour of the cube.</param>
|
||||
/// <param name="pos">Position where the cube wil be centered at.</param>
|
||||
/// <param name="size">Size of the rendered cube.</param>
|
||||
void DrawCube(const SHVec4& color, const SHVec3& pos, const SHVec3& size);
|
||||
/// <summary>
|
||||
/// Renders a wireframe sphere centered around the position specified in world space.
|
||||
/// </summary>
|
||||
/// <param name="color">Colour of the sphere.</param>
|
||||
/// <param name="pos">Position where the sphere wil be centered at.</param>
|
||||
/// <param name="size">Size of the rendered sphere.</param>
|
||||
void DrawSphere(const SHVec4& color, const SHVec3& pos, double radius);
|
||||
|
||||
private:
|
||||
|
|
|
@ -15,11 +15,11 @@ of DigiPen Institute of Technology is prohibited.
|
|||
|
||||
namespace SHADE
|
||||
{
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Template Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Draw Functions */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
template<typename IterType>
|
||||
void SHADE::SHDebugDrawSystem::DrawPoly(const SHVec4& color, IterType pointListBegin, IterType pointListEnd)
|
||||
void SHDebugDrawSystem::DrawPoly(const SHVec4& color, IterType pointListBegin, IterType pointListEnd)
|
||||
{
|
||||
// Ensure dereferenced type is SHVec3
|
||||
static_assert(std::is_same_v<SHVec3, std::remove_cvref_t<decltype(*pointListBegin)>>, "Parameters to DrawPoly must be SHVec3.");
|
||||
|
@ -27,22 +27,22 @@ namespace SHADE
|
|||
// Check if points exceeded max
|
||||
if (points.size() > MAX_POINTS)
|
||||
{
|
||||
SHLOG_WARNING("[DebugDraw] Exceeded maximum size of drawable debug elements.");
|
||||
return;
|
||||
SHLOG_WARNING("[DebugDraw] Exceeded maximum size of drawable debug elements.");
|
||||
return;
|
||||
}
|
||||
|
||||
const size_t POINTS_COUNT = pointListEnd - pointListBegin;
|
||||
// Invalid polygon
|
||||
if (POINTS_COUNT < 2)
|
||||
{
|
||||
SHLOG_WARNING("[SHDebugDraw] Invalid polygon provided to DrawPoly().");
|
||||
return;
|
||||
SHLOG_WARNING("[SHDebugDraw] Invalid polygon provided to DrawPoly().");
|
||||
return;
|
||||
}
|
||||
|
||||
const size_t POINTS_ROUNDED_COUNT = POINTS_COUNT / 2 * 2;
|
||||
for (auto pointIter = pointListBegin; pointIter != (pointListBegin + POINTS_ROUNDED_COUNT); ++pointIter)
|
||||
{
|
||||
points.emplace_back(PointVertex { *pointIter, color });
|
||||
points.emplace_back(PointVertex{ *pointIter, color });
|
||||
}
|
||||
}
|
||||
}
|
|
@ -218,8 +218,8 @@ namespace SHADE
|
|||
{
|
||||
SHMeshData meshData;
|
||||
|
||||
const int LAT_SLICES = 8;
|
||||
const int LONG_SLICES = 8;
|
||||
const int LAT_SLICES = 12;
|
||||
const int LONG_SLICES = 12;
|
||||
float radius = 1;
|
||||
for (int latNum = 0; latNum <= LAT_SLICES; ++latNum)
|
||||
{
|
||||
|
|
|
@ -0,0 +1,73 @@
|
|||
/************************************************************************************//*!
|
||||
\file SHDebugDrawSystem.cpp
|
||||
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||
\par email: kahwei.tng\@digipen.edu
|
||||
\date Nov 2, 2022
|
||||
\brief Contains the definition of functions of the SHDebugDrawSystem class.
|
||||
|
||||
Copyright (C) 2022 DigiPen Institute of Technology.
|
||||
Reproduction or disclosure of this file or its contents without the prior written consent
|
||||
of DigiPen Institute of Technology is prohibited.
|
||||
*//*************************************************************************************/
|
||||
// Precompiled Header
|
||||
#include "SHpch.h"
|
||||
// Primary Include
|
||||
#include "SHDebugDraw.h"
|
||||
// Project Includes
|
||||
#include "Math/Vector/SHVec4.h"
|
||||
#include "Math/SHColour.h"
|
||||
#include "Graphics/MiddleEnd/Interface/SHDebugDrawSystem.h"
|
||||
#include "ECS_Base/Managers/SHSystemManager.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Static Member Definitions */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
SHDebugDrawSystem* SHDebugDraw::dbgDrawSys = nullptr;
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Lifecycle Functions */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
void SHDebugDraw::Init(SHDebugDrawSystem* sys)
|
||||
{
|
||||
dbgDrawSys = sys;
|
||||
if (dbgDrawSys == nullptr)
|
||||
{
|
||||
SHLOG_ERROR("[SHDebugDraw] Invalid SHDebugDrawSystem provided for initialization!");
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Draw Functions */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
void SHDebugDraw::Line(const SHVec4& color, const SHVec3& startPt, const SHVec3& endPt)
|
||||
{
|
||||
dbgDrawSys->DrawLine(color, startPt, endPt);
|
||||
}
|
||||
|
||||
void SHDebugDraw::Tri(const SHVec4& color, const SHVec3& pt1, const SHVec3& pt2, const SHVec3& pt3)
|
||||
{
|
||||
dbgDrawSys->DrawTri(color, pt1, pt2, pt3);
|
||||
}
|
||||
|
||||
void SHDebugDraw::Quad(const SHVec4& color, const SHVec3& pt1, const SHVec3& pt2, const SHVec3& pt3, const SHVec3& pt4)
|
||||
{
|
||||
dbgDrawSys->DrawQuad(color, pt1, pt2, pt3, pt4);
|
||||
}
|
||||
|
||||
void SHDebugDraw::Poly(const SHVec4& color, std::initializer_list<SHVec3> pointList)
|
||||
{
|
||||
dbgDrawSys->DrawPoly(color, pointList);
|
||||
}
|
||||
|
||||
void SHDebugDraw::Cube(const SHVec4& color, const SHVec3& pos, const SHVec3& size)
|
||||
{
|
||||
dbgDrawSys->DrawCube(color, pos, size);
|
||||
}
|
||||
|
||||
void SHDebugDraw::Sphere(const SHVec4& color, const SHVec3& pos, double radius)
|
||||
{
|
||||
dbgDrawSys->DrawSphere(color, pos, radius);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,101 @@
|
|||
/************************************************************************************//*!
|
||||
\file SHDebugDraw.h
|
||||
\author Tng Kah Wei, kahwei.tng, 390009620
|
||||
\par email: kahwei.tng\@digipen.edu
|
||||
\date Nov 2, 2022
|
||||
\brief Contains the definition of the SHDebugDraw static class.
|
||||
|
||||
Copyright (C) 2022 DigiPen Institute of Technology.
|
||||
Reproduction or disclosure of this file or its contents without the prior written consent
|
||||
of DigiPen Institute of Technology is prohibited.
|
||||
*//*************************************************************************************/
|
||||
#pragma once
|
||||
|
||||
// Project Includes
|
||||
#include "SH_API.h"
|
||||
|
||||
namespace SHADE
|
||||
{
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Forward Declarations */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
class SHDebugDrawSystem;
|
||||
class SHVec4;
|
||||
class SHVec3;
|
||||
class SHColour;
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Type Definitions */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Static helper class to make it easier to do debug drawing and enable support for
|
||||
/// managed code to execute it withot dependency hell due to graphics system
|
||||
/// dependencies.
|
||||
/// </summary>
|
||||
class SH_API SHDebugDraw final
|
||||
{
|
||||
public:
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Lifecycle Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Sets up the link with the SHDebugDrawSystem. Must be called after the
|
||||
/// SHDebugDrawSystem is spawned.
|
||||
/// </summary>
|
||||
static void Init(SHDebugDrawSystem* sys);
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Draw Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Renders a line between two points in world space.
|
||||
/// </summary>
|
||||
/// <param name="color">Colour of the line.</param>
|
||||
/// <param name="startPt">First point of the line.</param>
|
||||
/// <param name="endPt">Second point of the line.</param>
|
||||
static void Line(const SHVec4& color, const SHVec3& startPt, const SHVec3& endPt);
|
||||
/// <summary>
|
||||
/// Renders a triangle indicated by three points in world space.
|
||||
/// </summary>
|
||||
/// <param name="color">Colour of the triangle.</param>
|
||||
/// <param name="pt1">First point of the triangle.</param>
|
||||
/// <param name="pt2">Second point of the triangle.</param>
|
||||
/// <param name="pt3">Third point of the triangle.</param>
|
||||
static void Tri(const SHVec4& color, const SHVec3& pt1, const SHVec3& pt2, const SHVec3& pt3);
|
||||
/// <summary>
|
||||
/// Renders a quadrilateral indicated by four points in world space.
|
||||
/// </summary>
|
||||
/// <param name="color">Colour of the quadrilateral.</param>
|
||||
/// <param name="pt1">First point of the triangle.</param>
|
||||
/// <param name="pt2">Second point of the quadrilateral.</param>
|
||||
/// <param name="pt3">Third point of the quadrilateral.</param>
|
||||
/// <param name="pt4">Third point of the quadrilateral.</param>
|
||||
static void Quad(const SHVec4& color, const SHVec3& pt1, const SHVec3& pt2, const SHVec3& pt3, const SHVec3& pt4);
|
||||
/// <summary>
|
||||
/// Renders a polygon indicated by the specified set of points in world space.
|
||||
/// </summary>
|
||||
/// <param name="color">Colour of the polygon.</param>
|
||||
/// <param name="pointList">List of points for the polygon.</param>
|
||||
static void Poly(const SHVec4& color, std::initializer_list<SHVec3> pointList);
|
||||
/// <summary>
|
||||
/// Renders a wireframe cube centered around the position specified in world space.
|
||||
/// </summary>
|
||||
/// <param name="color">Colour of the cube.</param>
|
||||
/// <param name="pos">Position where the cube wil be centered at.</param>
|
||||
/// <param name="size">Size of the rendered cube.</param>
|
||||
static void Cube(const SHVec4& color, const SHVec3& pos, const SHVec3& size);
|
||||
/// <summary>
|
||||
/// Renders a wireframe sphere centered around the position specified in world space.
|
||||
/// </summary>
|
||||
/// <param name="color">Colour of the sphere.</param>
|
||||
/// <param name="pos">Position where the sphere wil be centered at.</param>
|
||||
/// <param name="size">Size of the rendered sphere.</param>
|
||||
static void Sphere(const SHVec4& color, const SHVec3& pos, double radius);
|
||||
|
||||
private:
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Static Data Members */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
static SHDebugDrawSystem* dbgDrawSys;
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue