Advertisement
Southclaw

ConstrainPositionToBox

Sep 29th, 2013
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 0.64 KB | None | 0 0
  1. /*
  2.     Used to manipulate pathfinding coordinates to constrain a position to within a rectangle.
  3.     Positions are altered by shifting them back towards the inside edge of the rectangle.
  4.  
  5.     Returns the number of modifications done to the coordinates (0, 1 or 2)
  6. */
  7.  
  8. ConstrainPositionToBox(&Float:x, &Float:y, Float:minx, Float:miny, Float:maxx, Float:maxy)
  9. {
  10.     new modified;
  11.  
  12.     if(x < minx)
  13.     {
  14.         x = (minx + 1.0);
  15.         modified++;
  16.     }
  17.  
  18.     else if(x > maxx)
  19.     {
  20.         x = (maxx - 1.0);
  21.         modified++;
  22.     }
  23.  
  24.     if(y < miny)
  25.     {
  26.         y = (miny + 1.0);
  27.         modified++;
  28.     }
  29.  
  30.     else if(y > maxy)
  31.     {
  32.         y = (maxy - 1.0);
  33.         modified++;
  34.     }
  35.  
  36.     return modified;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement