From c639bc91b7b12a2f8159d96cf16a140c1d5773e6 Mon Sep 17 00:00:00 2001 From: Mario Date: Mon, 7 Jun 2021 10:51:01 +1000 Subject: [PATCH] CSQC implementation of r_showbboxes, potentially useful for debugging --- qcsrc/client/_mod.inc | 1 + qcsrc/client/_mod.qh | 1 + qcsrc/client/showboxes.qc | 70 +++++++++++++++++++++++++++++++++++++++ qcsrc/client/showboxes.qh | 12 +++++++ qcsrc/client/view.qc | 3 ++ 5 files changed, 87 insertions(+) create mode 100644 qcsrc/client/showboxes.qc create mode 100644 qcsrc/client/showboxes.qh diff --git a/qcsrc/client/_mod.inc b/qcsrc/client/_mod.inc index 8f56739df..24615d9d5 100644 --- a/qcsrc/client/_mod.inc +++ b/qcsrc/client/_mod.inc @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include diff --git a/qcsrc/client/_mod.qh b/qcsrc/client/_mod.qh index 5f82413c4..2f3d2e50b 100644 --- a/qcsrc/client/_mod.qh +++ b/qcsrc/client/_mod.qh @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include diff --git a/qcsrc/client/showboxes.qc b/qcsrc/client/showboxes.qc new file mode 100644 index 000000000..d7f2c0d2a --- /dev/null +++ b/qcsrc/client/showboxes.qc @@ -0,0 +1,70 @@ +#include "showboxes.qh" + +void DrawSurface(string thetexture, vector forwardright, vector forwardleft, vector backleft, vector backright, vector thecolor, float thealpha) +{ + R_BeginPolygon(thetexture, DRAWFLAG_NORMAL, false); + R_PolygonVertex(forwardright, '0 0 0', thecolor, thealpha); + R_PolygonVertex(forwardleft, '0 1 0', thecolor, thealpha); + R_PolygonVertex(backleft, '1 1 0', thecolor, thealpha); + R_PolygonVertex(backright, '0 1 0', thecolor, thealpha); + R_EndPolygon(); +} + +void DrawBox(vector org, vector themin, vector themax, string toptex, string bottomtex, string backtex, string righttex, string lefttex, string fronttex, vector thecolor, float thealpha) +{ + vector forward = '1 0 0', up = '0 0 1', right = '0 1 0'; + + vector bbox_point_topfwdleft = org + (forward * themax.x + right * (-themax.y) + up * themax.z); + vector bbox_point_topfwdright = org + (forward * themax.x + right * (-themin.y) + up * themax.z); + vector bbox_point_topbckleft = org + (forward * themin.x + right * (-themax.y) + up * themax.z); + vector bbox_point_topbckright = org + (forward * themin.x + right * (-themin.y) + up * themax.z); + vector bbox_point_btmfwdleft = org + (forward * themax.x + right * (-themax.y) + up * themin.z); + vector bbox_point_btmfwdright = org + (forward * themax.x + right * (-themin.y) + up * themin.z); + vector bbox_point_btmbckleft = org + (forward * themin.x + right * (-themax.y) + up * themin.z); + vector bbox_point_btmbckright = org + (forward * themin.x + right * (-themin.y) + up * themin.z); + + // Top face + DrawSurface(toptex, bbox_point_topfwdright, bbox_point_topfwdleft, bbox_point_topbckleft, bbox_point_topbckright, thecolor, thealpha); + + // Botton face + DrawSurface(bottomtex, bbox_point_btmfwdright, bbox_point_btmfwdleft, bbox_point_btmbckleft, bbox_point_btmbckright, thecolor, thealpha); + + // Back face + DrawSurface(backtex, bbox_point_topbckright, bbox_point_topbckleft, bbox_point_btmbckleft, bbox_point_btmbckright, thecolor, thealpha); + + // Right face + DrawSurface(righttex, bbox_point_topbckright, bbox_point_topfwdright, bbox_point_btmfwdright, bbox_point_btmbckright, thecolor, thealpha); + + // Left face + DrawSurface(lefttex, bbox_point_topbckleft, bbox_point_topfwdleft, bbox_point_btmfwdleft, bbox_point_btmbckleft, thecolor, thealpha); + + // Front face + DrawSurface(fronttex, bbox_point_topfwdright, bbox_point_topfwdleft, bbox_point_btmfwdleft, bbox_point_btmfwdright, thecolor, thealpha); +} + +void draw_bbox(entity this) +{ + vector rgb = '0 0 0'; + float alph = 0.50; + switch(this.solid) + { + case SOLID_NOT: rgb = '1 1 1'; alph = 0.05; break; + case SOLID_TRIGGER: rgb = '1 0 1'; alph = 0.10; break; + case SOLID_BBOX: rgb = '0 1 0'; alph = 0.10; break; + case SOLID_SLIDEBOX: rgb = '1 0 0'; alph = 0.10; break; + case SOLID_BSP: rgb = '0 0 1'; alph = 0.05; break; + case SOLID_CORPSE: rgb = '1 0.5 0'; alph = 0.05; break; + } + + alph *= autocvar_cl_showbboxes; + + DrawBox(this.origin, this.mins, this.maxs, "", "", "", "", "", "", rgb, alph); +} + +void draw_bboxes() +{ + if(autocvar_cl_showbboxes <= 0) + return; + // NOTE: does not include CSQC entities without a draw() function! + IL_EACH(g_drawables, autocvar_cl_showbboxes_maxdistance <= 0 || vdist(it.origin - view_origin, <=, autocvar_cl_showbboxes_maxdistance), draw_bbox(it)); +} \ No newline at end of file diff --git a/qcsrc/client/showboxes.qh b/qcsrc/client/showboxes.qh new file mode 100644 index 000000000..f8a3d20a3 --- /dev/null +++ b/qcsrc/client/showboxes.qh @@ -0,0 +1,12 @@ +#pragma once + +AUTOCVAR(cl_showbboxes, float, 0, "Show bounding boxes (client debugging)"); +AUTOCVAR(cl_showbboxes_maxdistance, float, 3000, "Max distance at which bounding boxes are drawn"); + +void DrawSurface(string thetexture, vector forwardright, vector forwardleft, vector backleft, vector backright, vector thecolor, float thealpha); + +void DrawBox(vector org, vector themin, vector themax, string toptex, string bottomtex, string backtex, string righttex, string lefttex, string fronttex, vector thecolor, float thealpha); + +void draw_bbox(entity this); + +void draw_bboxes(); diff --git a/qcsrc/client/view.qc b/qcsrc/client/view.qc index 7835908cb..2b1f5ab5a 100644 --- a/qcsrc/client/view.qc +++ b/qcsrc/client/view.qc @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -1744,6 +1745,8 @@ void CSQC_UpdateView(entity this, float w, float h) View_DemoCamera(); + draw_bboxes(); + // Draw the Crosshair setproperty(VF_DRAWCROSSHAIR, 0); //Make sure engine crosshairs are always hidden -- 2.39.2