]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
CSQC implementation of r_showbboxes, potentially useful for debugging Mario/csqc_showbboxes
authorMario <mario.mario@y7mail.com>
Mon, 7 Jun 2021 00:51:01 +0000 (10:51 +1000)
committerMario <mario.mario@y7mail.com>
Mon, 7 Jun 2021 00:51:01 +0000 (10:51 +1000)
qcsrc/client/_mod.inc
qcsrc/client/_mod.qh
qcsrc/client/showboxes.qc [new file with mode: 0644]
qcsrc/client/showboxes.qh [new file with mode: 0644]
qcsrc/client/view.qc

index 8f56739df0f66ea1458555cb83643b9df60e5bf1..24615d9d511d623e50bb1d8e41b466fb781b8834 100644 (file)
@@ -7,6 +7,7 @@
 #include <client/mapvoting.qc>
 #include <client/player_skeleton.qc>
 #include <client/resources.qc>
+#include <client/showboxes.qc>
 #include <client/shownames.qc>
 #include <client/teamradar.qc>
 #include <client/view.qc>
index 5f82413c4633f25f2b2b14d528c2d52b46283e68..2f3d2e50b47b77a2f5aa7bbaf8e1933877b74f6f 100644 (file)
@@ -7,6 +7,7 @@
 #include <client/mapvoting.qh>
 #include <client/player_skeleton.qh>
 #include <client/resources.qh>
+#include <client/showboxes.qh>
 #include <client/shownames.qh>
 #include <client/teamradar.qh>
 #include <client/view.qh>
diff --git a/qcsrc/client/showboxes.qc b/qcsrc/client/showboxes.qc
new file mode 100644 (file)
index 0000000..d7f2c0d
--- /dev/null
@@ -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 (file)
index 0000000..f8a3d20
--- /dev/null
@@ -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();
index 7835908cb88ec1e88b0ba8aed8a1bc12c8346c89..2b1f5ab5a4c1bb357ea93cc960868bfcfa10ecf0 100644 (file)
@@ -8,6 +8,7 @@
 #include <client/hud/panel/scoreboard.qh>
 #include <client/mapvoting.qh>
 #include <client/mutators/_mod.qh>
+#include <client/showboxes.qh>
 #include <client/shownames.qh>
 #include <common/anim.qh>
 #include <common/animdecide.qh>
@@ -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