Advertisement
PaleoCrafter

Untitled

May 16th, 2014
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.76 KB | None | 0 0
  1. public static void drawRectangleRepeated(int x, int y, float u, float v, float uMax, float vMax, int width, int height, int tileWidth, int tileHeight, int zLevel)
  2. {
  3.     float uvHeight = v - vMax;
  4.     int numX = (int) Math.ceil((float) width / tileWidth);
  5.     int numY = (int) Math.ceil((float) height / tileHeight);
  6.  
  7.     for (int y2 = 0; y2 < numY; ++y2)
  8.         for (int x2 = 0; x2 < numX; ++x2)
  9.         {
  10.             int w = tileWidth;
  11.             int h = tileHeight;
  12.  
  13.             float tileMaxU = uMax;
  14.             float tileMaxV = vMax;
  15.  
  16.             float tileV = v;
  17.  
  18.             int tileX = w * x2;
  19.             int tileY = h * y2 + h;
  20.  
  21.             if (tileWidth > width)
  22.             {
  23.                 w = width;
  24.                 tileMaxU -= 0.00390625F * (float) w / tileWidth;
  25.                 tileX = w * x2;
  26.             }
  27.             else if (x2 == numX - 1)
  28.             {
  29.                 if (tileWidth > width - x2 * tileWidth)
  30.                 {
  31.                     w = width - x2 * tileWidth;
  32.                     tileMaxU -= 0.00390625F * (float) w / tileWidth;
  33.                     tileX = tileWidth * x2;
  34.                 }
  35.             }
  36.  
  37.             if (tileHeight > height)
  38.             {
  39.                 h = height;
  40.                 tileMaxV -= 0.00390625F * (float) h / tileHeight;
  41.                 tileY = h * y2 + h;
  42.             }
  43.             else if (y2 == numY - 1)
  44.             {
  45.                 if (tileHeight > height - (y2 - 1) * tileHeight)
  46.                 {
  47.                     h = height - (y2 - 1) * tileHeight;
  48.                     tileV += uvHeight - 0.00390625F * (float) h / tileHeight;
  49.                     tileY = tileHeight * y2 + h;
  50.                 }
  51.             }
  52.  
  53.             drawRectangleStretched(x + tileX, y + height - tileY, u, tileV, w, h, tileMaxU, tileMaxV, zLevel);
  54.         }
  55. }
  56.  
  57. public static void drawRectangleXRepeated(int x, int y, float u, float v, float uMax, float vMax, int width, int height, int tileWidth, int zLevel)
  58. {
  59.     float uvHeight = v - vMax;
  60.     int numX = (int) Math.ceil((float) width / tileWidth);
  61.  
  62.     for (int x2 = 0; x2 < numX; ++x2)
  63.     {
  64.         int w = tileWidth;
  65.  
  66.         float tileMaxU = uMax;
  67.  
  68.         int tileX = w * x2;
  69.  
  70.         if (tileWidth > width)
  71.         {
  72.             w = width;
  73.             tileMaxU -= 0.00390625F * (float) w / tileWidth;
  74.             tileX = w * x2;
  75.         }
  76.         else if (x2 == numX - 1)
  77.         {
  78.             if (tileWidth > width - x2 * tileWidth)
  79.             {
  80.                 w = width - x2 * tileWidth;
  81.                 tileMaxU -= 0.00390625F * (float) w / tileWidth;
  82.                 tileX = tileWidth * x2;
  83.             }
  84.         }
  85.  
  86.         drawRectangleStretched(x + tileX, y, u, v, w, height, tileMaxU, vMax, zLevel);
  87.     }
  88. }
  89.  
  90. public static void drawRectangleYRepeated(int x, int y, float u, float v, float uMax, float vMax, int width, int height, int tileHeight, int zLevel)
  91. {
  92.     float uvHeight = v - vMax;
  93.     int numY = (int) Math.ceil((float) height / tileHeight);
  94.  
  95.     for (int y2 = 0; y2 < numY; ++y2)
  96.     {
  97.         int h = tileHeight;
  98.  
  99.         float tileMaxV = vMax;
  100.  
  101.         float tileV = v;
  102.  
  103.         int tileY = h * y2 + h;
  104.  
  105.         if (tileHeight > height)
  106.         {
  107.             h = height;
  108.             tileMaxV -= 0.00390625F * (float) h / tileHeight;
  109.             tileY = h * y2 + h;
  110.         }
  111.         else if (y2 == numY - 1)
  112.         {
  113.             if (tileHeight > height - (y2 - 1) * tileHeight)
  114.             {
  115.                 h = height - (y2 - 1) * tileHeight;
  116.                 tileV += uvHeight - 0.00390625F * (float) h / tileHeight;
  117.                 tileY = tileHeight * y2 + h;
  118.             }
  119.         }
  120.  
  121.         drawRectangleStretched(x, y + height - tileY, u, tileV, width, h, uMax, tileMaxV, zLevel);
  122.     }
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement