Advertisement
Guest User

Untitled

a guest
Sep 7th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. static final function DrawMapGridBorder(Canvas C)
  2. {
  3.     local float D, X;
  4.     local int i;
  5.     local float Step;
  6.     local float HalfStepViewSpace;
  7.     local string Symbol;
  8.     local float XL, YL;
  9.  
  10.     const GRID_LINES = 9;
  11.  
  12.     // TODO: we have to draw this in two places, ideally we don't need to loop through
  13.     // all of this twice and can do it in once pass
  14.  
  15.     // Draw horizontal grid lines!
  16.     Step = 1.0 / GRID_LINES;
  17.     D = Viewport.Max.X - Viewport.Min.X;
  18.     i = Floor(Viewport.Min.X / Step);
  19.     j = Ceil(Viewport.Max.X / Step);
  20.     HalfStepViewSpace = (Step / D) / 2;
  21.  
  22.     // TODO: pick a font to use (something that isn't crap, preferably)
  23.     C.Font = none;
  24.  
  25.     while (; i < j; ++i)
  26.     {
  27.         // Convert from viewport-space to view-space.
  28.         X = ((i * Step) - Viewport.Min.X) / D;
  29.  
  30.         if (i > 0 && X < 0)
  31.         {
  32.             // TODO: draw grid line
  33.             DrawLine(X);
  34.         }
  35.        
  36.         X += HalfStepViewSpace;
  37.  
  38.         if (X < 1)
  39.         {
  40.             Symbol = Asc(Char("A") + i);
  41.  
  42.             C.TextSize(Symbol, XL, YL);
  43.  
  44.             DrawText(Symbol);
  45.         }
  46.     }
  47. }
  48.  
  49. /**
  50. minx = 0.4
  51. 0.111111111111111
  52. */
  53.  
  54. static final function bool ClipLineToViewport(out float X0, out float Y0, out float X1, out float Y1, Box Viewport)
  55. {
  56.     local float T0, T1, DX, DY, P, Q, U;
  57.     local int i;
  58.  
  59.     T0 = 0;
  60.     T1 = 1;
  61.     DX = X1 - X0;
  62.     DY = Y1 - Y0;
  63.  
  64.     for (i = 0; i < 4; ++i)
  65.     {
  66.         if (i == 0)
  67.         {
  68.             P = -DX;
  69.             Q = -(Viewport.Min.X - X0);
  70.         }
  71.         else if (i == 1)
  72.         {
  73.             P = DX;
  74.             Q = Viewport.Max.X - X0;
  75.         }
  76.         else if (i == 2)
  77.         {
  78.             P = -DY;
  79.             Q = -(Viewport.Min.Y - Y0);
  80.         }
  81.         else
  82.         {
  83.             P = DY;
  84.             Q = Viewport.Max.Y - Y0;
  85.         }
  86.  
  87.         U = Q / P;
  88.  
  89.         if (P == 0)
  90.         {
  91.             if (Q < 0)
  92.             {
  93.                 return false;
  94.             }
  95.         }
  96.         else if (P < 0)
  97.         {
  98.             if (U > T1)
  99.             {
  100.                 return false;
  101.             }
  102.             if (U > T0)
  103.             {
  104.                 T0 = u;
  105.             }
  106.         }
  107.         else
  108.         {
  109.             if (U < T0)
  110.             {
  111.                 return false;
  112.             }
  113.  
  114.             if (U < T1)
  115.             {
  116.                 T1 = u;
  117.             }
  118.     }
  119.  
  120.     X0 = X0 + T0 * DX;
  121.     Y0 = Y0 + T0 * DY;
  122.     X1 = X0 + T1 * DX;
  123.     Y1 = Y0 + T1 * DY;
  124.  
  125.     return true;
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement