]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
strafehud: improve visual fidelity of arrows
authorJuhu <5894800-Juhu_@users.noreply.gitlab.com>
Tue, 23 Mar 2021 18:47:36 +0000 (19:47 +0100)
committerJuhu <5894800-Juhu_@users.noreply.gitlab.com>
Tue, 23 Mar 2021 18:47:36 +0000 (19:47 +0100)
_hud_common.cfg
qcsrc/client/hud/panel/strafehud.qc
qcsrc/client/hud/panel/strafehud.qh

index 271bafbd3b019175ec1ed3b99c609c981171fbb3..e1a9d8af42bd1128b6c637a5337504ef032ebee4 100644 (file)
@@ -154,8 +154,7 @@ seta hud_panel_strafehud_angle_neutral_color "1 1 0" "color of the indicator sho
 seta hud_panel_strafehud_angle_accel_color "0 1 1" "color of the indicator showing the player's current angle if it is within the acceleration zone"
 seta hud_panel_strafehud_angle_overturn_color "1 0 1" "color of the indicator showing the player's current angle if it is within the overturn zone"
 seta hud_panel_strafehud_angle_arrow "1" "set the angle indicator's arrow style: 0 = none, 1 = top, 2 = bottom, 3 = both"
-seta hud_panel_strafehud_angle_arrow_height "0.5" "height of the arrow (relative to the panel height)"
-seta hud_panel_strafehud_angle_arrow_width "0.03" "width of the arrow (relative to the panel width)"
+seta hud_panel_strafehud_angle_arrow_size "0.5" "size of the arrow (relative to the panel height)"
 seta hud_panel_strafehud_switch_minspeed "-1" "minimum speed in qu/s at which switch indicator(s) which are used to aid changing strafe direction will be shown (set to -1 for dynamic minspeed)"
 seta hud_panel_strafehud_switch_color "1 1 0" "color of the switch indicator"
 seta hud_panel_strafehud_switch_alpha "1" "opacity of the switch indicator"
index eada3b57dfb173f35b9beeadbafe9e0787570d21..86827b62b8c6ea923ca10a8b7f4c16432c814054 100644 (file)
@@ -705,37 +705,13 @@ void HUD_StrafeHUD()
 
             if(autocvar_hud_panel_strafehud_angle_arrow > 0)
             {
-                vector arrow_size = currentangle_size;
-                arrow_size.x = panel_size.x * autocvar_hud_panel_strafehud_angle_arrow_width;
-                arrow_size.y = panel_size.y * min(autocvar_hud_panel_strafehud_angle_arrow_height, 10);
-                vector arrow_fragment = '0 0.2 0';
-
-                if(arrow_size.x > 0 && arrow_size.y > 0)
+                float arrow_size = panel_size.y * min(autocvar_hud_panel_strafehud_angle_arrow_size, 10); // there's only one size cvar, arrows always have a 45° angle to ensure proper rendering without antialiasing
+                if(arrow_size > 0)
                 {
-                    // find a suitable fragment size to draw all the parts evenly
-                    float fragment_divisor1 = arrow_size.y / arrow_fragment.y;
-                    float fragment_divisor2 = fragment_divisor1 - floor(fragment_divisor1);
-                    fragment_divisor1 = floor(fragment_divisor1);
-                    if(fragment_divisor1 >= 1)
-                    {
-                        if(fragment_divisor2 < 0.5)
-                            arrow_fragment.y += arrow_fragment.y * fragment_divisor2 / fragment_divisor1;
-                        else
-                            arrow_fragment.y -= arrow_fragment.y * (1 - fragment_divisor2) / (fragment_divisor1 + 1);
-                    }
-                    else
-                    {
-                        arrow_fragment.y = arrow_size.y;
-                    }
-
-                    for(float i = arrow_size.y; i > 0; i -= arrow_fragment.y)
-                    {
-                        arrow_fragment.x = arrow_size.x * (i/arrow_size.y);
-                        if(autocvar_hud_panel_strafehud_angle_arrow == 1 || autocvar_hud_panel_strafehud_angle_arrow >= 3)
-                            drawfill(panel_pos - eY * ((currentangle_size.y - panel_size.y) / 2 + i) + eX * (currentangle_offset - arrow_fragment.x/2), arrow_fragment, currentangle_color, autocvar_hud_panel_strafehud_angle_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
-                        if(autocvar_hud_panel_strafehud_angle_arrow >= 2)
-                            drawfill(panel_pos + eY * (-(currentangle_size.y - panel_size.y) / 2 + currentangle_size.y + i - arrow_fragment.y) + eX * (currentangle_offset - arrow_fragment.x/2), arrow_fragment, currentangle_color, autocvar_hud_panel_strafehud_angle_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
-                    }
+                    if(autocvar_hud_panel_strafehud_angle_arrow == 1 || autocvar_hud_panel_strafehud_angle_arrow >= 3)
+                        StrafeHUD_drawStrafeArrow(panel_pos + eY * ((panel_size.y - currentangle_size.y) / 2) + eX * currentangle_offset, arrow_size, currentangle_color, autocvar_hud_panel_strafehud_angle_alpha * panel_fg_alpha, true);
+                    if(autocvar_hud_panel_strafehud_angle_arrow >= 2)
+                        StrafeHUD_drawStrafeArrow(panel_pos + eY * ((panel_size.y - currentangle_size.y) / 2 + currentangle_size.y) + eX * currentangle_offset, arrow_size, currentangle_color, autocvar_hud_panel_strafehud_angle_alpha * panel_fg_alpha, false);
                 }
             }
         }
@@ -968,6 +944,17 @@ void StrafeHUD_drawGradient(vector color1, vector color2, vector size, float ori
     }
 }
 
+// draw the strafe arrows (inspired by drawspritearrow() in common/mutators/mutator/waypoints/waypointsprites.qc)
+void StrafeHUD_drawStrafeArrow(vector origin, float size, vector color, float alpha, bool flipped)
+{
+    if(flipped) origin -= size*eY;
+    R_BeginPolygon("", DRAWFLAG_NORMAL, true);
+    R_PolygonVertex(origin + (flipped ? size*eY : '0 0 0')          , '0 0 0', color, alpha);
+    R_PolygonVertex(origin + (flipped ? '0 0 0' : size*eY) - size*eX, '0 0 0', color, alpha);
+    R_PolygonVertex(origin + (flipped ? '0 0 0' : size*eY) + size*eX, '0 0 0', color, alpha);
+    R_EndPolygon();
+}
+
 // length unit conversion (km and miles are only included to match the GetSpeedUnit* functions)
 float GetLengthUnitFactor(int length_unit)
 {
index 3e3aeca3be5d52fe4d6db03dded995db3e2acff4..d25c7e249ba10e9749df93e9588f9f1699bac42b 100644 (file)
@@ -24,8 +24,7 @@ vector autocvar_hud_panel_strafehud_angle_neutral_color = '1 1 0';
 vector autocvar_hud_panel_strafehud_angle_accel_color = '0 1 1';
 vector autocvar_hud_panel_strafehud_angle_overturn_color = '1 0 1';
 int autocvar_hud_panel_strafehud_angle_arrow = 1;
-float autocvar_hud_panel_strafehud_angle_arrow_height = 0.5;
-float autocvar_hud_panel_strafehud_angle_arrow_width = 0.03;
+float autocvar_hud_panel_strafehud_angle_arrow_size = 0.5;
 float autocvar_hud_panel_strafehud_switch_minspeed = -1;
 vector autocvar_hud_panel_strafehud_switch_color = '1 1 0';
 float autocvar_hud_panel_strafehud_switch_alpha = 1;
@@ -57,3 +56,4 @@ vector StrafeHUD_mixColors(vector, vector, float);
 void StrafeHUD_drawGradient(vector, vector, vector, float, float, float, float, int);
 float GetLengthUnitFactor(int);
 string GetLengthUnit(int);
+void StrafeHUD_drawStrafeArrow(vector, float, vector, float, bool);