mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
Debug overlay improvements and new render utilities.
Fixed internal RenderBox transforms (origin and angles are packed in xmm registers). Added new render utilities in the SDK similar to the script ones.
This commit is contained in:
parent
2be140f09d
commit
856b386945
@ -114,24 +114,61 @@ void DrawOverlay(OverlayBase_t* pOverlay)
|
||||
{
|
||||
case OverlayType_t::OVERLAY_BOX:
|
||||
{
|
||||
//printf("%p\n", pOverlay);
|
||||
|
||||
OverlayBox_t* pBox = static_cast<OverlayBox_t*>(pOverlay);
|
||||
if (pBox->a < 1)
|
||||
pBox->a = 255;
|
||||
{
|
||||
if (r_debug_overlay_invisible->GetBool())
|
||||
{
|
||||
pBox->a = 255;
|
||||
}
|
||||
else
|
||||
{
|
||||
LeaveCriticalSection(&*s_OverlayMutex);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
DrawAngledBox({ pBox->origin_X, pBox->origin_Y, pBox->origin_Z }, { 0,0,0 }, pBox->mins, pBox->maxs, pBox->r, pBox->g, pBox->b, pBox->a, false);
|
||||
v_RenderBox(&*pBox->transforms, pBox->mins, pBox->maxs, Color(pBox->r, pBox->g, pBox->b, pBox->a), false);
|
||||
break;
|
||||
}
|
||||
case OverlayType_t::OVERLAY_SPHERE:
|
||||
{
|
||||
OverlaySphere_t* pSphere = static_cast<OverlaySphere_t*>(pOverlay);
|
||||
v_RenderWireframeSphere(pSphere->vOrigin, pSphere->flRadius, pSphere->nTheta, pSphere->nPhi, Color(pSphere->r, pSphere->g, pSphere->b, pSphere->a), false);
|
||||
if (pSphere->a < 1)
|
||||
{
|
||||
if (r_debug_overlay_invisible->GetBool())
|
||||
{
|
||||
pSphere->a = 255;
|
||||
}
|
||||
else
|
||||
{
|
||||
LeaveCriticalSection(&*s_OverlayMutex);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (r_debug_overlay_wireframe->GetBool())
|
||||
v_RenderWireframeSphere(pSphere->vOrigin, pSphere->flRadius, pSphere->nTheta, pSphere->nPhi, Color(pSphere->r, pSphere->g, pSphere->b, pSphere->a), false);
|
||||
else
|
||||
DebugDrawSphere(pSphere->vOrigin, pSphere->flRadius, Color(pSphere->r, pSphere->g, pSphere->b, pSphere->a), 16);
|
||||
break;
|
||||
}
|
||||
case OverlayType_t::OVERLAY_LINE:
|
||||
{
|
||||
OverlayLine_t* pLine = static_cast<OverlayLine_t*>(pOverlay);
|
||||
if (pLine->a < 1)
|
||||
{
|
||||
if (r_debug_overlay_invisible->GetBool())
|
||||
{
|
||||
pLine->a = 255;
|
||||
}
|
||||
else
|
||||
{
|
||||
LeaveCriticalSection(&*s_OverlayMutex);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
v_RenderLine(pLine->origin, pLine->dest, Color(pLine->r, pLine->g, pLine->b, pLine->a), pLine->noDepthTest);
|
||||
break;
|
||||
}
|
||||
|
@ -71,14 +71,9 @@ struct OverlayBox_t : public OverlayBase_t
|
||||
{
|
||||
OverlayBox_t(void) { m_Type = OverlayType_t::OVERLAY_BOX; }
|
||||
|
||||
RadianEuler angles{}; //0x0020 - this isn't angles but idrk where it is
|
||||
float origin_X{}; //0x002C
|
||||
RadianEuler unk30{}; //0x0030
|
||||
float origin_Y{}; //0x003C
|
||||
RadianEuler unk40{}; //0x0040
|
||||
float origin_Z{}; //0x004C
|
||||
Vector3D mins{}; //0x0050
|
||||
Vector3D maxs{}; //0x005C
|
||||
__m128i transforms[3];
|
||||
Vector3D mins{};
|
||||
Vector3D maxs{};
|
||||
int r{};
|
||||
int g{};
|
||||
int b{};
|
||||
@ -152,14 +147,14 @@ void DebugOverlays_Detach();
|
||||
inline CMemory p_DrawAllOverlays;
|
||||
inline auto v_DrawAllOverlays = p_DrawAllOverlays.RCast<void (*)(char a1)>();
|
||||
|
||||
inline CMemory p_RenderWireframeBox; // one of the vector parameters is probably the angles, vmins might no longer be used.
|
||||
inline auto v_RenderWireframeBox = p_RenderWireframeBox.RCast<void* (*)(Vector3D origin, Vector3D vMins, Vector3D vMaxs, Color color, bool bZBuffer)>();
|
||||
|
||||
inline CMemory p_RenderLine;
|
||||
inline auto v_RenderLine = p_RenderLine.RCast<void* (*)(Vector3D origin, Vector3D dest, Color color, bool bZBuffer)>();
|
||||
inline auto v_RenderLine = p_RenderLine.RCast<void* (*)(const Vector3D& vOrigin, const Vector3D& vDest, Color color, bool bZBuffer)>();
|
||||
|
||||
inline CMemory p_RenderBox;
|
||||
inline auto v_RenderBox = p_RenderBox.RCast<void* (*)(const __m128i* vTransforms, const Vector3D& vMins, const Vector3D& vMaxs, Color color, bool bZBuffer)>();
|
||||
|
||||
inline CMemory p_RenderWireframeSphere;
|
||||
inline auto v_RenderWireframeSphere = p_RenderWireframeSphere.RCast<void* (*)(Vector3D vCenter, float flRadius, int nTheta, int nPhi, Color c, bool bZBuffer)>();
|
||||
inline auto v_RenderWireframeSphere = p_RenderWireframeSphere.RCast<void* (*)(const Vector3D& vCenter, float flRadius, int nTheta, int nPhi, Color color, bool bZBuffer)>();
|
||||
|
||||
inline CMemory p_DestroyOverlay;
|
||||
inline auto v_DestroyOverlay = p_DestroyOverlay.RCast<void (*)(OverlayBase_t* pOverlay)>();
|
||||
@ -179,9 +174,9 @@ class VDebugOverlay : public IDetour
|
||||
virtual void GetAdr(void) const
|
||||
{
|
||||
spdlog::debug("| FUN: DrawAllOverlays : {:#18x} |\n", p_DrawAllOverlays.GetPtr());
|
||||
spdlog::debug("| FUN: RenderWireframeBox : {:#18x} |\n", p_RenderWireframeBox.GetPtr());
|
||||
spdlog::debug("| FUN: RenderWireframeSphere : {:#18x} |\n", p_RenderWireframeSphere.GetPtr());
|
||||
spdlog::debug("| FUN: RenderLine : {:#18x} |\n", p_RenderLine.GetPtr());
|
||||
spdlog::debug("| FUN: RenderBox : {:#18x} |\n", p_RenderBox.GetPtr());
|
||||
spdlog::debug("| FUN: RenderWireframeSphere : {:#18x} |\n", p_RenderWireframeSphere.GetPtr());
|
||||
spdlog::debug("| FUN: DestroyOverlay : {:#18x} |\n", p_DestroyOverlay.GetPtr());
|
||||
spdlog::debug("| VAR: s_pOverlays : {:#18x} |\n", reinterpret_cast<uintptr_t>(s_pOverlays));
|
||||
spdlog::debug("| VAR: s_OverlayMutex : {:#18x} |\n", reinterpret_cast<uintptr_t>(s_OverlayMutex));
|
||||
@ -198,17 +193,17 @@ class VDebugOverlay : public IDetour
|
||||
p_RenderWireframeBox = g_mGameDll.FindPatternSIMD(reinterpret_cast<rsig_t>("\x48\x89\x5C\x24\x00\x48\x89\x6C\x24\x00\x44\x89\x4C\x24\x00"), "xxxx?xxxx?xxxx?");
|
||||
#elif defined (GAMEDLL_S2) || defined (GAMEDLL_S3)
|
||||
p_DrawAllOverlays = g_mGameDll.FindPatternSIMD(reinterpret_cast<rsig_t>("\x40\x55\x48\x83\xEC\x30\x48\x8B\x05\x00\x00\x00\x00\x0F\xB6\xE9"), "xxxxxxxxx????xxx");
|
||||
p_RenderWireframeBox = g_mGameDll.FindPatternSIMD(reinterpret_cast<rsig_t>("\x48\x89\x5C\x24\x00\x48\x89\x6C\x24\x00\x44\x89\x4C\x24\x00"), "xxxx?xxxx?xxxx?");
|
||||
p_RenderBox = g_mGameDll.FindPatternSIMD(reinterpret_cast<rsig_t>("\x48\x89\x5C\x24\x00\x48\x89\x6C\x24\x00\x44\x89\x4C\x24\x00"), "xxxx?xxxx?xxxx?");
|
||||
#endif
|
||||
p_DestroyOverlay = g_mGameDll.FindPatternSIMD(reinterpret_cast<rsig_t>("\x40\x53\x48\x83\xEC\x20\x48\x8B\xD9\x48\x8D\x0D\x00\x00\x00\x00\xFF\x15\x00\x00\x00\x00\x48\x63\x03"), "xxxxxxxxxxxx????xx????xxx");
|
||||
p_RenderWireframeSphere = g_mGameDll.FindPatternSIMD(reinterpret_cast<rsig_t>("\x40\x56\x41\x54\x41\x55\x48\x81\xEC\x00\x00\x00\x00"), "xxxxxxxxx????");
|
||||
p_RenderLine = g_mGameDll.FindPatternSIMD(reinterpret_cast<rsig_t>("\x48\x89\x74\x24\x00\x44\x89\x44\x24\x00\x57\x41\x56"), "xxxx?xxxx?xxx");
|
||||
|
||||
v_DrawAllOverlays = p_DrawAllOverlays.RCast<void (*)(char)>(); /*40 55 48 83 EC 30 48 8B 05 ?? ?? ?? ?? 0F B6 E9*/
|
||||
v_DestroyOverlay = p_DestroyOverlay.RCast<void (*)(OverlayBase_t*)>(); /*40 53 48 83 EC 20 48 8B D9 48 8D 0D ?? ?? ?? ?? FF 15 ?? ?? ?? ?? 48 63 03 */
|
||||
v_RenderWireframeBox = p_RenderWireframeBox.RCast<void* (*)(Vector3D, Vector3D, Vector3D, Color, bool)>(); /*48 89 5C 24 ?? 48 89 6C 24 ?? 44 89 4C 24 ??*/
|
||||
v_RenderWireframeSphere = p_RenderWireframeSphere.RCast<void* (*)(Vector3D, float, int, int, Color, bool)>(); /*40 56 41 54 41 55 48 81 EC ?? ?? ?? ??*/
|
||||
v_RenderLine = p_RenderLine.RCast<void* (*)(Vector3D, Vector3D, Color, bool)>(); /*48 89 74 24 ?? 44 89 44 24 ?? 57 41 56*/
|
||||
v_DrawAllOverlays = p_DrawAllOverlays.RCast<void (*)(char)>(); /*40 55 48 83 EC 30 48 8B 05 ?? ?? ?? ?? 0F B6 E9*/
|
||||
v_DestroyOverlay = p_DestroyOverlay.RCast<void (*)(OverlayBase_t*)>(); /*40 53 48 83 EC 20 48 8B D9 48 8D 0D ?? ?? ?? ?? FF 15 ?? ?? ?? ?? 48 63 03 */
|
||||
v_RenderBox = p_RenderBox.RCast<void* (*)(const __m128i*, const Vector3D&, const Vector3D&, Color, bool)>(); /*48 89 5C 24 ?? 48 89 6C 24 ?? 44 89 4C 24 ??*/
|
||||
v_RenderWireframeSphere = p_RenderWireframeSphere.RCast<void* (*)(const Vector3D&, float, int, int, Color, bool)>(); /*40 56 41 54 41 55 48 81 EC ?? ?? ?? ??*/
|
||||
v_RenderLine = p_RenderLine.RCast<void* (*)(const Vector3D&, const Vector3D&, Color, bool)>(); /*48 89 74 24 ?? 44 89 44 24 ?? 57 41 56*/
|
||||
}
|
||||
virtual void GetVar(void) const
|
||||
{
|
||||
|
@ -74,6 +74,7 @@
|
||||
#define VecToString(v) (static_cast<const char *>(CFmtStr("(%f, %f, %f)", (v).x, (v).y, (v).z))) // ** Note: this generates a temporary, don't hold reference!
|
||||
|
||||
class VectorByValue;
|
||||
class QAngle;
|
||||
|
||||
//=========================================================
|
||||
// 3D Vector
|
||||
@ -109,6 +110,10 @@ public:
|
||||
Vector2D& AsVector2D();
|
||||
const Vector2D& AsVector2D() const;
|
||||
|
||||
// Cast to QAngle...
|
||||
QAngle& AsQAngle();
|
||||
const QAngle& AsQAngle() const;
|
||||
|
||||
// Initialization methods
|
||||
void Random(vec_t minVal, vec_t maxVal);
|
||||
inline void Zero(); ///< zero out a vector
|
||||
@ -757,6 +762,20 @@ inline const Vector2D& Vector3D::AsVector2D() const
|
||||
return *(const Vector2D*)this;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Cast to QAngle...
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
inline QAngle& Vector3D::AsQAngle()
|
||||
{
|
||||
return *(QAngle*)this;
|
||||
}
|
||||
|
||||
inline const QAngle& Vector3D::AsQAngle() const
|
||||
{
|
||||
return *(const QAngle*)this;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// IsValid?
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -53,6 +53,8 @@ void ConVar::Init(void) const
|
||||
rcon_password = new ConVar("rcon_password", "" , FCVAR_SERVER_CANNOT_QUERY | FCVAR_DONTRECORD | FCVAR_RELEASE, "Remote server access password (rcon is disabled if empty).", false, 0.f, false, 0.f, nullptr, nullptr);
|
||||
|
||||
r_debug_overlay_nodecay = new ConVar("r_debug_overlay_nodecay" , "0", FCVAR_DEVELOPMENTONLY | FCVAR_CHEAT, "Keeps all debug overlays alive regardless of their lifetime. Use command 'clear_debug_overlays' to clear everything.", false, 0.f, false, 0.f, nullptr, nullptr);
|
||||
r_debug_overlay_invisible = new ConVar("r_debug_overlay_invisible" , "1", FCVAR_DEVELOPMENTONLY | FCVAR_CHEAT, "Show invisible debug overlays (alpha < 1 = 255).", false, 0.f, false, 0.f, nullptr, nullptr);
|
||||
r_debug_overlay_wireframe = new ConVar("r_debug_overlay_wireframe" , "1", FCVAR_DEVELOPMENTONLY | FCVAR_CHEAT, "Use of wireframe in debug overlays.", false, 0.f, false, 0.f, nullptr, nullptr);
|
||||
r_drawWorldMeshes = new ConVar("r_drawWorldMeshes" , "1", FCVAR_DEVELOPMENTONLY | FCVAR_CHEAT, "Render world meshes.", false, 0.f, false, 0.f, nullptr, nullptr);
|
||||
r_drawWorldMeshesDepthOnly = new ConVar("r_drawWorldMeshesDepthOnly" , "1", FCVAR_DEVELOPMENTONLY | FCVAR_CHEAT, "Render world meshes (depth only).", false, 0.f, false, 0.f, nullptr, nullptr);
|
||||
r_drawWorldMeshesDepthAtTheEnd = new ConVar("r_drawWorldMeshesDepthAtTheEnd", "1", FCVAR_DEVELOPMENTONLY | FCVAR_CHEAT, "Render world meshes (depth at the end).", false, 0.f, false, 0.f, nullptr, nullptr);
|
||||
|
@ -32,6 +32,8 @@ ConVar* rcon_address = nullptr;
|
||||
ConVar* rcon_password = nullptr;
|
||||
|
||||
ConVar* r_debug_overlay_nodecay = nullptr;
|
||||
ConVar* r_debug_overlay_invisible = nullptr;
|
||||
ConVar* r_debug_overlay_wireframe = nullptr;
|
||||
ConVar* r_drawWorldMeshes = nullptr;
|
||||
ConVar* r_drawWorldMeshesDepthOnly = nullptr;
|
||||
ConVar* r_drawWorldMeshesDepthAtTheEnd = nullptr;
|
||||
@ -131,7 +133,7 @@ ConVar* net_encryptionEnable = nullptr;
|
||||
ConVar* net_useRandomKey = nullptr;
|
||||
ConVar* net_usesocketsforloopback = nullptr;
|
||||
ConVar* pylon_matchmaking_hostname = nullptr;
|
||||
ConVar* pylon_showdebug = nullptr;
|
||||
ConVar* pylon_showdebug = nullptr;
|
||||
//-----------------------------------------------------------------------------
|
||||
// RTECH API |
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -31,6 +31,8 @@ extern ConVar* rcon_address;
|
||||
extern ConVar* rcon_password;
|
||||
|
||||
extern ConVar* r_debug_overlay_nodecay;
|
||||
extern ConVar* r_debug_overlay_invisible;
|
||||
extern ConVar* r_debug_overlay_wireframe;
|
||||
extern ConVar* r_drawWorldMeshes;
|
||||
extern ConVar* r_drawWorldMeshesDepthOnly;
|
||||
extern ConVar* r_drawWorldMeshesDepthAtTheEnd;
|
||||
|
@ -3,6 +3,8 @@
|
||||
// Purpose: A set of utilities to render standard shapes
|
||||
//
|
||||
//===========================================================================//
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "core/stdafx.h"
|
||||
#include "mathlib/color.h"
|
||||
@ -13,28 +15,270 @@
|
||||
#include "tier2/renderutils.h"
|
||||
#include "engine/debugoverlay.h"
|
||||
|
||||
void DrawAngledBox(const Vector3D& origin, const QAngle& angles, Vector3D mins, Vector3D maxs, int r, int g, int b, int a, bool throughSolid)
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: render angled box:
|
||||
// +y _+z
|
||||
// ^ /|
|
||||
// | /
|
||||
// | +----------+
|
||||
// | /| /|
|
||||
// / | / |
|
||||
// +----------+ |
|
||||
// | +-------|--+
|
||||
// | / | /
|
||||
// |/ |/
|
||||
// +----------+ --> +x
|
||||
//-----------------------------------------------------------------------------
|
||||
void DebugDrawBox(const Vector3D& vOrigin, const QAngle& vAngles, const Vector3D& vMins, const Vector3D& vMaxs, Color color, bool bZBuffer)
|
||||
{
|
||||
Vector3D orgs[8];
|
||||
PointsFromAngledBox(angles, mins, maxs, &*orgs);
|
||||
Vector3D vPoints[8];
|
||||
PointsFromAngledBox(vAngles, vMins, vMaxs, &*vPoints);
|
||||
|
||||
v_RenderLine(origin + orgs[0], origin + orgs[1], Color(r, g, b, a), throughSolid);
|
||||
v_RenderLine(origin + orgs[1], origin + orgs[2], Color(r, g, b, a), throughSolid);
|
||||
v_RenderLine(origin + orgs[2], origin + orgs[3], Color(r, g, b, a), throughSolid);
|
||||
v_RenderLine(origin + orgs[3], origin + orgs[0], Color(r, g, b, a), throughSolid);
|
||||
v_RenderLine(vOrigin + vPoints[0], vOrigin + vPoints[1], color, bZBuffer);
|
||||
v_RenderLine(vOrigin + vPoints[1], vOrigin + vPoints[2], color, bZBuffer);
|
||||
v_RenderLine(vOrigin + vPoints[2], vOrigin + vPoints[3], color, bZBuffer);
|
||||
v_RenderLine(vOrigin + vPoints[3], vOrigin + vPoints[0], color, bZBuffer);
|
||||
|
||||
v_RenderLine(origin + orgs[4], origin + orgs[5], Color(r, g, b, a), throughSolid);
|
||||
v_RenderLine(origin + orgs[5], origin + orgs[6], Color(r, g, b, a), throughSolid);
|
||||
v_RenderLine(origin + orgs[6], origin + orgs[7], Color(r, g, b, a), throughSolid);
|
||||
v_RenderLine(origin + orgs[7], origin + orgs[4], Color(r, g, b, a), throughSolid);
|
||||
v_RenderLine(vOrigin + vPoints[4], vOrigin + vPoints[5], color, bZBuffer);
|
||||
v_RenderLine(vOrigin + vPoints[5], vOrigin + vPoints[6], color, bZBuffer);
|
||||
v_RenderLine(vOrigin + vPoints[6], vOrigin + vPoints[7], color, bZBuffer);
|
||||
v_RenderLine(vOrigin + vPoints[7], vOrigin + vPoints[4], color, bZBuffer);
|
||||
|
||||
v_RenderLine(origin + orgs[0], origin + orgs[4], Color(r, g, b, a), throughSolid);
|
||||
v_RenderLine(origin + orgs[1], origin + orgs[5], Color(r, g, b, a), throughSolid);
|
||||
v_RenderLine(origin + orgs[2], origin + orgs[6], Color(r, g, b, a), throughSolid);
|
||||
v_RenderLine(origin + orgs[3], origin + orgs[7], Color(r, g, b, a), throughSolid);
|
||||
v_RenderLine(vOrigin + vPoints[0], vOrigin + vPoints[4], color, bZBuffer);
|
||||
v_RenderLine(vOrigin + vPoints[1], vOrigin + vPoints[5], color, bZBuffer);
|
||||
v_RenderLine(vOrigin + vPoints[2], vOrigin + vPoints[6], color, bZBuffer);
|
||||
v_RenderLine(vOrigin + vPoints[3], vOrigin + vPoints[7], color, bZBuffer);
|
||||
}
|
||||
|
||||
void RenderCapsule(const Vector3D& vStart, const Vector3D& vEnd, const float& flRadius, Color c)
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: render cylinder:
|
||||
// +y _+z
|
||||
// ^ /|
|
||||
// | /
|
||||
// |.-'""'-. /
|
||||
// ( )
|
||||
// |'-.__.-'|
|
||||
// | |
|
||||
// | |
|
||||
// | <----> |--> +r
|
||||
// | |
|
||||
// | |
|
||||
// "-.__.-" --> +x
|
||||
//-----------------------------------------------------------------------------
|
||||
void DebugDrawCylinder(const Vector3D& vOrigin, const QAngle& vAngles, float flRadius, float flHeight, Color color, int nSides, bool bZBuffer)
|
||||
{
|
||||
float flDegrees = 360.f / float(nSides);
|
||||
vector<Vector3D> vvPoints;
|
||||
Vector3D vForward;
|
||||
QAngle vComposed;
|
||||
|
||||
AngleVectors(vAngles, &vForward);
|
||||
|
||||
for (int i = 0; i < nSides; i++)
|
||||
{
|
||||
Vector3D right;
|
||||
|
||||
AngleCompose(vAngles, { 0.f, 0.f, flDegrees * i }, vComposed);
|
||||
AngleVectors(vComposed, nullptr, &right, nullptr);
|
||||
vvPoints.push_back(vOrigin + (right * flRadius));
|
||||
}
|
||||
|
||||
for (int i = 0; i < nSides; i++)
|
||||
{
|
||||
Vector3D vStart = vvPoints[i];
|
||||
Vector3D vEnd = i == 0 ? vvPoints[nSides - 1] : vvPoints[i - 1];
|
||||
|
||||
v_RenderLine(vStart, vEnd, color, bZBuffer);
|
||||
v_RenderLine(vStart + (vForward * flHeight), vEnd + (vForward * flHeight), color, bZBuffer);
|
||||
v_RenderLine(vStart, vStart + (vForward * flHeight), color, bZBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: render sphere:
|
||||
// +y _+z
|
||||
// ^ /|
|
||||
// | /
|
||||
// | .--"|"--. /
|
||||
// .' | '.
|
||||
// / | \
|
||||
// | <----( )---->-|--> +r
|
||||
// \ | /
|
||||
// '. | .'
|
||||
// "-.._|_..-" --> +x
|
||||
//-----------------------------------------------------------------------------
|
||||
void DebugDrawSphere(const Vector3D& vOrigin, float flRadius, Color color, int nSegments, bool bZBuffer)
|
||||
{
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
DebugDrawCircle(vOrigin, { 0.f, 0.f, 90.f * i }, flRadius, color, nSegments, bZBuffer);
|
||||
DebugDrawCircle(vOrigin, { 90.f * i, 0.f, 0.f }, flRadius, color, nSegments, bZBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: render circle:
|
||||
// +y _+z
|
||||
// ^ /|
|
||||
// | /
|
||||
// | .--"""--. /
|
||||
// .' '.
|
||||
// / \
|
||||
// | <----( )---->-|--> +r
|
||||
// \ /
|
||||
// '. .'
|
||||
// "-..___..-" --> +x
|
||||
//-----------------------------------------------------------------------------
|
||||
void DebugDrawCircle(const Vector3D& vOrigin, const QAngle& vAngles, float flRadius, Color color, int nSegments, bool bZBuffer)
|
||||
{
|
||||
bool bFirstLoop = true;
|
||||
Vector3D vStart;
|
||||
Vector3D vEnd;
|
||||
Vector3D vFirstend;
|
||||
Vector3D vForward;
|
||||
QAngle vComposed;
|
||||
float flDegrees = 360.f / float(nSegments);
|
||||
|
||||
for (int i = 0; i < nSegments; i++)
|
||||
{
|
||||
AngleCompose(vAngles, { 0.f, flDegrees * i, 0.f }, vComposed);
|
||||
AngleVectors(vComposed, &vForward);
|
||||
vEnd = vOrigin + (vForward * flRadius);
|
||||
|
||||
if (bFirstLoop)
|
||||
vFirstend = vEnd;
|
||||
|
||||
if (!bFirstLoop)
|
||||
v_RenderLine(vStart, vEnd, color, bZBuffer);
|
||||
|
||||
vStart = vEnd;
|
||||
|
||||
bFirstLoop = false;
|
||||
}
|
||||
|
||||
v_RenderLine(vEnd, vFirstend, color, bZBuffer);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: render square:
|
||||
// +y _+z
|
||||
// | /|
|
||||
// .--------------.
|
||||
// | |
|
||||
// | |
|
||||
// | |
|
||||
// | |
|
||||
// | |
|
||||
// | |
|
||||
// '--------------' --> +x
|
||||
//-----------------------------------------------------------------------------
|
||||
void DebugDrawSquare(const Vector3D& vOrigin, const QAngle& vAngles, float flSquareSize, Color color, bool bZBuffer)
|
||||
{
|
||||
DebugDrawCircle(vOrigin, vAngles, flSquareSize, color, 4, bZBuffer);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: render triangle:
|
||||
// +y _+z
|
||||
// | /|
|
||||
// | /\ /
|
||||
// | / \ /
|
||||
// | / \ /
|
||||
// | / \
|
||||
// | / \
|
||||
// | / \
|
||||
// / \
|
||||
// '--------------' --> +x
|
||||
//-----------------------------------------------------------------------------
|
||||
void DebugDrawTriangle(const Vector3D& vOrigin, const QAngle& vAngles, float flTriangleSize, Color color, bool bZBuffer)
|
||||
{
|
||||
DebugDrawCircle(vOrigin, vAngles, flTriangleSize, color, 3, bZBuffer);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: render mark:
|
||||
// +y _+z
|
||||
// | /|
|
||||
// | /
|
||||
// \ /--> +r
|
||||
// ___\/___
|
||||
// /\
|
||||
// / \
|
||||
// / --> +x
|
||||
//-----------------------------------------------------------------------------
|
||||
void DebugDrawMark(const Vector3D& vOrigin, float flRadius, const vector<int>& vColor, bool bZBuffer)
|
||||
{
|
||||
v_RenderLine((vOrigin - Vector3D{ flRadius, 0.f, 0.f }), (vOrigin + Vector3D{ flRadius, 0.f, 0.f }), Color(vColor[0], vColor[1], vColor[2], vColor[3]), bZBuffer);
|
||||
v_RenderLine((vOrigin - Vector3D{ 0.f, flRadius, 0.f }), (vOrigin + Vector3D{ 0.f, flRadius, 0.f }), Color(vColor[0], vColor[1], vColor[2], vColor[3]), bZBuffer);
|
||||
v_RenderLine((vOrigin - Vector3D{ 0.f, 0.f, flRadius }), (vOrigin + Vector3D{ 0.f, 0.f, flRadius }), Color(vColor[0], vColor[1], vColor[2], vColor[3]), bZBuffer);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: render star:
|
||||
// +y _+z
|
||||
// | /|
|
||||
// | /
|
||||
// \ /--> +r
|
||||
// ___\/___
|
||||
// /\
|
||||
// / \
|
||||
// --> +x
|
||||
//-----------------------------------------------------------------------------
|
||||
void DrawStar(const Vector3D& vRrigin, float flRadius, bool bZBuffer)
|
||||
{
|
||||
Vector3D vForward;
|
||||
for (int i = 0; i < 50; i++)
|
||||
{
|
||||
AngleVectors({ RandomFloat(0.f, 360.f), RandomFloat(0.f, 360.f), RandomFloat(0.f, 360.f) }, &vForward);
|
||||
v_RenderLine(vRrigin, vRrigin + vForward * flRadius, Color(RandomInt(0, 255), RandomInt(0, 255), RandomInt(0, 255), 255), bZBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: render arrow:
|
||||
// +y _+z
|
||||
// | /|
|
||||
// | . /
|
||||
// | / \
|
||||
// / \
|
||||
// /_____\ --> r
|
||||
// |
|
||||
// |
|
||||
// | --> +x
|
||||
//-----------------------------------------------------------------------------
|
||||
void DebugDrawArrow(const Vector3D& vOrigin, const Vector3D& vEnd, float flArraySize, Color color, bool bZBuffer)
|
||||
{
|
||||
Vector3D vAngles;
|
||||
|
||||
v_RenderLine(vOrigin, vEnd, color, bZBuffer);
|
||||
AngleVectors(Vector3D(vEnd - vOrigin).Normalized().AsQAngle(), &vAngles);
|
||||
DebugDrawCircle(vEnd, vAngles.AsQAngle(), flArraySize, color, 3, bZBuffer);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: render 3d axis:
|
||||
// +y
|
||||
// ^
|
||||
// | _+z
|
||||
// | /|
|
||||
// | /
|
||||
// | /
|
||||
// |/
|
||||
// +----------> +x
|
||||
//-----------------------------------------------------------------------------
|
||||
void DebugDrawAxis(const Vector3D& vOrigin, const QAngle& vAngles, float flScale, bool bZBuffer)
|
||||
{
|
||||
Vector3D vForward;
|
||||
Vector3D vRight;
|
||||
Vector3D vUp;
|
||||
AngleVectors(vAngles, &vForward, &vRight, &vUp);
|
||||
|
||||
v_RenderLine(vOrigin, vOrigin + vForward * flScale, Color(0, 255, 0, 255), bZBuffer);
|
||||
v_RenderLine(vOrigin, vOrigin + vUp * flScale, Color(255, 0, 0, 255), bZBuffer);
|
||||
v_RenderLine(vOrigin, vOrigin + vRight * flScale, Color(0, 0, 255, 255), bZBuffer);
|
||||
}
|
||||
|
||||
void DebugDrawCapsule(const Vector3D& vStart, const Vector3D& vEnd, const float& flRadius, Color color, bool bZBuffer)
|
||||
{
|
||||
// !FIXME:
|
||||
}
|
@ -2,7 +2,15 @@
|
||||
#define RENDERUTILS_H
|
||||
#include "mathlib/vector.h"
|
||||
|
||||
void DrawAngledBox(const Vector3D& origin, const QAngle& angles, Vector3D mins, Vector3D maxs, int r, int g, int b, int a, bool throughSolid);
|
||||
void RenderCapsule(const Vector3D& vStart, const Vector3D& vEnd, const float& flRadius, Color c);
|
||||
|
||||
void DebugDrawBox(const Vector3D& vOrigin, const QAngle& vAngles, const Vector3D& vMins, const Vector3D& vMaxs, Color color, bool bZBuffer);
|
||||
void DebugDrawCylinder(const Vector3D& vOrigin, const QAngle& vAngles, float flRadius, float flHeight, Color color, int nSides = 16, bool bZBuffer = false);
|
||||
void DebugDrawSphere(const Vector3D& vOrigin, float flRadius, Color color, int nSegments = 16, bool bZBuffer = false);
|
||||
void DebugDrawCircle(const Vector3D& vOrigin, const QAngle& vAngles, float flRadius, Color color, int nSegments = 16, bool bZBuffer = false);
|
||||
void DebugDrawSquare(const Vector3D& vOrigin, const QAngle& vAngles, float flSquareSize, Color color, bool bZBuffer = false);
|
||||
void DebugDrawTriangle(const Vector3D& vOrigin, const QAngle& vAngles, float flTriangleSize, Color color, bool bZBuffer = false);
|
||||
void DebugDrawMark(const Vector3D& vOrigin, float flRadius, const vector<int>& vColor, bool bZBuffer = false);
|
||||
void DrawStar(const Vector3D& vRrigin, float flRadius, bool bZBuffer = false);
|
||||
void DebugDrawArrow(const Vector3D& vOrigin, const Vector3D& vEnd, float flArraySize, Color color, bool bZBuffer = false);
|
||||
void DebugDrawAxis(const Vector3D& vOrigin, const QAngle& vAngles = { 0, 0, 0 }, float flScale = 50.f, bool bZBuffer = false);
|
||||
void DebugDrawCapsule(const Vector3D& vStart, const Vector3D& vEnd, const float& flRadius, Color color, bool bZBuffer = false);
|
||||
#endif // RENDERUTILS_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user