Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static final function DrawMapGridBorder(Canvas C)
- {
- local float D, X;
- local int i;
- local float Step;
- local float HalfStepViewSpace;
- local string Symbol;
- local float XL, YL;
- const GRID_LINES = 9;
- // TODO: we have to draw this in two places, ideally we don't need to loop through
- // all of this twice and can do it in once pass
- // Draw horizontal grid lines!
- Step = 1.0 / GRID_LINES;
- D = Viewport.Max.X - Viewport.Min.X;
- i = Floor(Viewport.Min.X / Step);
- j = Ceil(Viewport.Max.X / Step);
- HalfStepViewSpace = (Step / D) / 2;
- // TODO: pick a font to use (something that isn't crap, preferably)
- C.Font = none;
- while (; i < j; ++i)
- {
- // Convert from viewport-space to view-space.
- X = ((i * Step) - Viewport.Min.X) / D;
- if (i > 0 && X < 0)
- {
- // TODO: draw grid line
- DrawLine(X);
- }
- X += HalfStepViewSpace;
- if (X < 1)
- {
- Symbol = Asc(Char("A") + i);
- C.TextSize(Symbol, XL, YL);
- DrawText(Symbol);
- }
- }
- }
- /**
- minx = 0.4
- 0.111111111111111
- */
- static final function bool ClipLineToViewport(out float X0, out float Y0, out float X1, out float Y1, Box Viewport)
- {
- local float T0, T1, DX, DY, P, Q, U;
- local int i;
- T0 = 0;
- T1 = 1;
- DX = X1 - X0;
- DY = Y1 - Y0;
- for (i = 0; i < 4; ++i)
- {
- if (i == 0)
- {
- P = -DX;
- Q = -(Viewport.Min.X - X0);
- }
- else if (i == 1)
- {
- P = DX;
- Q = Viewport.Max.X - X0;
- }
- else if (i == 2)
- {
- P = -DY;
- Q = -(Viewport.Min.Y - Y0);
- }
- else
- {
- P = DY;
- Q = Viewport.Max.Y - Y0;
- }
- U = Q / P;
- if (P == 0)
- {
- if (Q < 0)
- {
- return false;
- }
- }
- else if (P < 0)
- {
- if (U > T1)
- {
- return false;
- }
- if (U > T0)
- {
- T0 = u;
- }
- }
- else
- {
- if (U < T0)
- {
- return false;
- }
- if (U < T1)
- {
- T1 = u;
- }
- }
- X0 = X0 + T0 * DX;
- Y0 = Y0 + T0 * DY;
- X1 = X0 + T1 * DX;
- Y1 = Y0 + T1 * DY;
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement