Merge branch 'divVerent/simpler-clipped-rectangle' into 'master'
authorRudolf Polzer <divverent@gmail.com>
Sat, 18 Apr 2020 00:20:07 +0000 (00:20 +0000)
committerRudolf Polzer <divverent@gmail.com>
Sat, 18 Apr 2020 00:20:07 +0000 (00:20 +0000)
Simplify clipped circle pictures (e.g. crosshair ring).

See merge request xonotic/xonotic-data.pk3dir!759

1  2 
qcsrc/client/miscfunctions.qc

index d801ceabd7d7ccde6edf099e3aacd4b6f67b1a44,684224c710100cc64101425a1b3de9c6df0bcc41..a7af09c7c82a146fcc259558ae8c46e9bd789a2c
@@@ -214,28 -214,6 +214,28 @@@ vector expandingbox_resize_centered_box
        return boxsize * (0.5 * (1 - sz));
  }
  
 +// NOTE base is the central value
 +// freq: circle frequency, = 2*pi*frequency in hertz
 +// start_pos:
 +//  -1 start from the lower value
 +//   0 start from the base value
 +//   1 start from the higher value
 +float blink_synced(float base, float range, float freq, float start_time, int start_pos)
 +{
 +      // note:
 +      //   RMS = sqrt(base^2 + 0.5 * range^2)
 +      // thus
 +      //   base = sqrt(RMS^2 - 0.5 * range^2)
 +      // ensure RMS == 1
 +
 +      return base + range * sin((time - start_time - (M_PI / 2) * start_pos) * freq);
 +}
 +
 +float blink(float base, float range, float freq)
 +{
 +      return blink_synced(base, range, freq, 0, 0);
 +}
 +
  void drawborderlines(float thickness, vector pos, vector dim, vector color, float theAlpha, float drawflag)
  {
        vector line_dim = '0 0 0';
@@@ -422,7 -400,6 +422,6 @@@ void PolyDrawModel(entity e
  
  void DrawCircleClippedPic(vector centre, float radi, string pic, float f, vector rgb, float a, float drawflag)
  {
-       float d;
        vector ringsize, v, t;
        ringsize = radi * '1 1 0';
        centre = HUD_Shift(centre);
                        v.y -= 0.5 * ringsize.y;        t -= '0.5 -0.5 0';
                        R_PolygonVertex(v, t, rgb, a);
                R_EndPolygon();
-               d = q - 1;
-               if(d > 0)
-               {
-                       R_BeginPolygon(pic, drawflag, true);
-                               v = centre;                     t = '0.5 0.5 0';
-                               R_PolygonVertex(v, t, rgb, a);
-                               v = centre;                     t = '0.5 0.5 0';
-                               v.x += 0.5 * ringsize.x;        t += '0.5 0.5 0';
-                               R_PolygonVertex(v, t, rgb, a);
-               }
+               return;  // Complete rectangle, nothing more needed.
        }
        else if(f > 0.75)
        {
-               // draw upper and first triangle
+               // draw upper half in full
                R_BeginPolygon(pic, drawflag, true);
                        v = centre;                     t = '0.5 0.5 0';
                        v.x += 0.5 * ringsize.x;        t += '0.5 0.5 0';
                        v.x -= 0.5 * ringsize.x;        t -= '0.5 0.5 0';
                        R_PolygonVertex(v, t, rgb, a);
                R_EndPolygon();
+               // draw clipped lower half as a quad
                R_BeginPolygon(pic, drawflag, true);
                        v = centre;                     t = '0.5 0.5 0';
                        R_PolygonVertex(v, t, rgb, a);
                        v = centre;                     t = '0.5 0.5 0';
                        v.y -= 0.5 * ringsize.y;        t -= '0.5 -0.5 0';
                        R_PolygonVertex(v, t, rgb, a);
-               d = q - 0.75;
-               if(d <= 0)
-                       R_EndPolygon();
        }
        else if(f > 0.5)
        {
-               // draw upper triangle
+               // draw upper half in full
                R_BeginPolygon(pic, drawflag, true);
                        v = centre;                     t = '0.5 0.5 0';
                        v.x += 0.5 * ringsize.x;        t += '0.5 0.5 0';
                        v.x -= 0.5 * ringsize.x;        t -= '0.5 0.5 0';
                        R_PolygonVertex(v, t, rgb, a);
                R_EndPolygon();
+               // draw clipped lower half as a triangle
+               R_BeginPolygon(pic, drawflag, true);
+                       v = centre;                     t = '0.5 0.5 0';
+                       R_PolygonVertex(v, t, rgb, a);
  
-               d = q - 0.5;
-               if(d > 0)
-               {
-                       R_BeginPolygon(pic, drawflag, true);
-                               v = centre;                     t = '0.5 0.5 0';
-                               R_PolygonVertex(v, t, rgb, a);
-                               v = centre;                     t = '0.5 0.5 0';
-                               v.x -= 0.5 * ringsize.x;        t -= '0.5 0.5 0';
-                               R_PolygonVertex(v, t, rgb, a);
-               }
+                       v = centre;                     t = '0.5 0.5 0';
+                       v.x -= 0.5 * ringsize.x;        t -= '0.5 0.5 0';
+                       R_PolygonVertex(v, t, rgb, a);
        }
        else if(f > 0.25)
        {
-               // draw first triangle
+               // draw clipped lower half as a quad
                R_BeginPolygon(pic, drawflag, true);
                        v = centre;                     t = '0.5 0.5 0';
                        R_PolygonVertex(v, t, rgb, a);
                        v = centre;                     t = '0.5 0.5 0';
                        v.y += 0.5 * ringsize.y;        t += '0.5 -0.5 0';
                        R_PolygonVertex(v, t, rgb, a);
-               d = q - 0.25;
-               if(d <= 0)
-                       R_EndPolygon();
        }
-       else
+       else if (f > 0)
        {
-               d = q;
-               if(d > 0)
-               {
-                       R_BeginPolygon(pic, drawflag, true);
-                               v = centre;                     t = '0.5 0.5 0';
-                               R_PolygonVertex(v, t, rgb, a);
-                               v = centre;                     t = '0.5 0.5 0';
-                               v.x += 0.5 * ringsize.x;        t += '0.5 0.5 0';
-                               R_PolygonVertex(v, t, rgb, a);
-               }
-       }
+               // draw clipped lower half as a triangle
+               R_BeginPolygon(pic, drawflag, true);
+                       v = centre;                     t = '0.5 0.5 0';
+                       R_PolygonVertex(v, t, rgb, a);
  
-       if(d > 0)
-       {
                        v = centre;                     t = '0.5 0.5 0';
-                       v.x += co * 0.5 * ringsize.x;   t += co * '0.5 0.5 0';
-                       v.y += si * 0.5 * ringsize.y;   t += si * '0.5 -0.5 0';
+                       v.x += 0.5 * ringsize.x;        t += '0.5 0.5 0';
                        R_PolygonVertex(v, t, rgb, a);
-               R_EndPolygon();
        }
+       else
+       {
+               // Nothing to draw.
+               return;
+       }
+       // The last, moving vertex.
+               v = centre;                     t = '0.5 0.5 0';
+               v.x += co * 0.5 * ringsize.x;   t += co * '0.5 0.5 0';
+               v.y += si * 0.5 * ringsize.y;   t += si * '0.5 -0.5 0';
+               R_PolygonVertex(v, t, rgb, a);
+       R_EndPolygon();
  }
  
  /** engine callback */