]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Optimize Draw_CylindricLine: replace a normalize call with a cheaper division, avoid...
authorterencehill <piuntn@gmail.com>
Sun, 16 Jun 2024 15:09:18 +0000 (17:09 +0200)
committerterencehill <piuntn@gmail.com>
Sun, 16 Jun 2024 15:09:18 +0000 (17:09 +0200)
qcsrc/lib/draw.qh

index 82ae7c58dde6383faf684a1796d17a0a5f49215b..0d0f9c38bed6b4768de0b582ebd44710227e8c0b 100644 (file)
                // I want to draw a quad...
                // from and to are MIDPOINTS.
 
-               vector axis, thickdir, A, B, C, D;
-               float length_tex;
+               float len = vlen(to - from);
+               if (!len)
+                       return;
 
-               axis = normalize(to - from);
-               length_tex = aspect * vlen(to - from) / thickness;
+               float length_tex = aspect * len / thickness;
+               vector axis = (to - from) / len; // same as axis = normalize(to - from) but cheaper
 
                // direction is perpendicular to the view normal, and perpendicular to the axis
-               thickdir = normalize(cross(axis, vieworg - from));
+               vector thickdir = normalize(cross(axis, vieworg - from));
 
-               A = from - thickdir * (thickness / 2);
-               B = from + thickdir * (thickness / 2);
-               C = to + thickdir * (thickness / 2);
-               D = to - thickdir * (thickness / 2);
+               vector ofs = thickdir * (thickness / 2);
 
                R_BeginPolygon(texture, drawflag, false);
-               R_PolygonVertex(A, '0 0 0' + shift * '1 0 0', rgb, theAlpha);
-               R_PolygonVertex(B, '0 1 0' + shift * '1 0 0', rgb, theAlpha);
-               R_PolygonVertex(C, '0 1 0' + (shift + length_tex) * '1 0 0', rgb, theAlpha);
-               R_PolygonVertex(D, '0 0 0' + (shift + length_tex) * '1 0 0', rgb, theAlpha);
+               R_PolygonVertex(from - ofs, '0 0 0' + shift * '1 0 0', rgb, theAlpha);
+               R_PolygonVertex(from + ofs, '0 1 0' + shift * '1 0 0', rgb, theAlpha);
+               R_PolygonVertex(to + ofs,   '0 1 0' + (shift + length_tex) * '1 0 0', rgb, theAlpha);
+               R_PolygonVertex(to - ofs,   '0 0 0' + (shift + length_tex) * '1 0 0', rgb, theAlpha);
                R_EndPolygon();
        }