From: Mario Date: Mon, 7 Jun 2021 00:51:01 +0000 (+1000) Subject: CSQC implementation of r_showbboxes, potentially useful for debugging X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=refs%2Fheads%2FMario%2Fcsqc_showbboxes;p=xonotic%2Fxonotic-data.pk3dir.git CSQC implementation of r_showbboxes, potentially useful for debugging --- 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