Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- TAXIROUTE_LINEFACTOR = 32/30; -- Multiplying factor for texture coordinates
- TAXIROUTE_LINEFACTOR_2 = TAXIROUTE_LINEFACTOR / 2; -- Half o that
- -- T - Texture
- -- C - Canvas Frame (for anchoring)
- -- sx,sy - Coordinate of start of line
- -- ex,ey - Coordinate of end of line
- -- w - Width of line
- -- relPoint - Relative point on canvas to interpret coords (Default BOTTOMLEFT)
- function DrawRouteLine(T, C, sx, sy, ex, ey, w, relPoint)
- if (not relPoint) then relPoint = "BOTTOMLEFT"; end
- -- Determine dimensions and center point of line
- local dx,dy = ex - sx, ey - sy;
- local cx,cy = (sx + ex) / 2, (sy + ey) / 2;
- -- Normalize direction if necessary
- if (dx < 0) then
- dx,dy = -dx,-dy;
- end
- -- Calculate actual length of line
- local l = sqrt((dx * dx) + (dy * dy));
- -- Quick escape if it's zero length
- if (l == 0) then
- T:SetTexCoord(0,0,0,0,0,0,0,0);
- T:SetPoint("BOTTOMLEFT", C, relPoint, cx,cy);
- T:SetPoint("TOPRIGHT", C, relPoint, cx,cy);
- return;
- end
- -- Sin and Cosine of rotation, and combination (for later)
- local s,c = -dy / l, dx / l;
- local sc = s * c;
- -- Calculate bounding box size and texture coordinates
- local Bwid, Bhgt, BLx, BLy, TLx, TLy, TRx, TRy, BRx, BRy;
- if (dy >= 0) then
- Bwid = ((l * c) - (w * s)) * TAXIROUTE_LINEFACTOR_2;
- Bhgt = ((w * c) - (l * s)) * TAXIROUTE_LINEFACTOR_2;
- BLx, BLy, BRy = (w / l) * sc, s * s, (l / w) * sc;
- BRx, TLx, TLy, TRx = 1 - BLy, BLy, 1 - BRy, 1 - BLx;
- TRy = BRx;
- else
- Bwid = ((l * c) + (w * s)) * TAXIROUTE_LINEFACTOR_2;
- Bhgt = ((w * c) + (l * s)) * TAXIROUTE_LINEFACTOR_2;
- BLx, BLy, BRx = s * s, -(l / w) * sc, 1 + (w / l) * sc;
- BRy, TLx, TLy, TRy = BLx, 1 - BRx, 1 - BLx, 1 - BLy;
- TRx = TLy;
- end
- -- Set texture coordinates and anchors
- T:ClearAllPoints();
- T:SetTexCoord(TLx, TLy, BLx, BLy, TRx, TRy, BRx, BRy);
- T:SetPoint("BOTTOMLEFT", C, relPoint, cx - Bwid, cy - Bhgt);
- T:SetPoint("TOPRIGHT", C, relPoint, cx + Bwid, cy + Bhgt);
- end
Advertisement
Add Comment
Please, Sign In to add comment