From: terencehill Date: Sun, 16 Jun 2024 15:09:18 +0000 (+0200) Subject: Optimize Draw_CylindricLine: replace a normalize call with a cheaper division, avoid... X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=23b9f7c450d34bd2f8edf2d0397540340bc59614;p=xonotic%2Fxonotic-data.pk3dir.git Optimize Draw_CylindricLine: replace a normalize call with a cheaper division, avoid repeating a few operations --- diff --git a/qcsrc/lib/draw.qh b/qcsrc/lib/draw.qh index 82ae7c58d..0d0f9c38b 100644 --- a/qcsrc/lib/draw.qh +++ b/qcsrc/lib/draw.qh @@ -13,25 +13,23 @@ // 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(); }