Advertisement
Barteks2x

Untitled

Dec 2nd, 2016
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.06 KB | None | 0 0
  1.  
  2.     // this isn't supposed to be fast... yet
  3.     default void forEachScaled(Vec3i startUnscaled, Vec3i endUnscaled, Vec3i scale, NoiseConsumer consumer) {
  4.  
  5.         int xScale = scale.getX();
  6.         int yScale = scale.getY();
  7.         int zScale = scale.getZ();
  8.  
  9.         double stepX = 1.0/xScale;
  10.         double stepY = 1.0/yScale;
  11.         double stepZ = 1.0/zScale;
  12.  
  13.         int minX = startUnscaled.getX();
  14.         int minY = startUnscaled.getY();
  15.         int minZ = startUnscaled.getZ();
  16.         int maxX = endUnscaled.getX();
  17.         int maxY = endUnscaled.getY();
  18.         int maxZ = endUnscaled.getZ();
  19.         for (int sectionX = minX; sectionX < maxX; ++sectionX) {
  20.             int x = sectionX*xScale;
  21.             for (int sectionZ = minZ; sectionZ < maxZ; ++sectionZ) {
  22.                 int z = sectionZ*zScale;
  23.                 for (int sectionY = minY; sectionY < maxY; ++sectionY) {
  24.                     int y = sectionY*yScale;
  25.                     NoiseValue v0y0 = this.get(x, y, z);
  26.                     NoiseValue v0y1 = this.get(x, y, z + zScale);
  27.                     NoiseValue v1y0 = this.get(x + xScale, y, z);
  28.                     NoiseValue v1y1 = this.get(x + xScale, y, z + zScale);
  29.                     NoiseValue d0y0 = this.get(x, y + yScale, z).sub(v0y0).mul(stepY);
  30.                     NoiseValue d0y1 = this.get(x, y + yScale, z + zScale).sub(v0y1).mul(stepY);
  31.                     NoiseValue d1y0 = this.get(x + xScale, y + yScale, z).sub(v1y0).mul(stepY);
  32.                     NoiseValue d1y1 = this.get(x + xScale, y + yScale, z + zScale).sub(v1y1).mul(stepY);
  33.  
  34.                     for (int yRel = 0; yRel < yScale; ++yRel) {
  35.                         NoiseValue vxy0 = v0y0;
  36.                         NoiseValue vxy1 = v0y1;
  37.                         NoiseValue dxy0 = v1y0.sub(v0y0).mul(stepZ);
  38.                         NoiseValue dxy1 = v1y1.sub(v0y1).mul(stepZ);
  39.  
  40.                         for (int xRel = 0; xRel < xScale; ++xRel) {
  41.                             NoiseValue dxyz = vxy1.sub(vxy0).mul(stepX);
  42.                             NoiseValue vxyz = vxy0.sub(dxyz);
  43.  
  44.                             for (int zRel = 0; zRel < zScale; ++zRel) {
  45.                                 vxyz = vxyz.add(dxyz);
  46.                                 consumer.consume(x + xRel, y + yRel, z + zRel, vxyz);
  47.                             }
  48.  
  49.                             vxy0 = vxy0.add(dxy0);
  50.                             vxy1 = vxy1.add(dxy1);
  51.                         }
  52.  
  53.                         v0y0 = v0y0.add(d0y0);
  54.                         v0y1 = v0y1.add(d0y1);
  55.                         v1y0 = v1y0.add(d1y0);
  56.                         v1y1 = v1y1.add(d1y1);
  57.                     }
  58.                 }
  59.             }
  60.         }
  61.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement