Exemplo n.º 1
0
  /**
   * Rotate the clipboard in 2D. It can only rotate by angles divisible by 90.
   *
   * @param angle in degrees
   */
  public void rotate2D(int angle) {
    angle = angle % 360;
    if (angle % 90 != 0) { // Can only rotate 90 degrees at the moment
      return;
    }
    boolean reverse = angle < 0;
    int numRotations = Math.abs((int) Math.floor(angle / 90.0));

    int width = getWidth();
    int length = getLength();
    int height = getHeight();
    Vector sizeRotated = size.transform2D(angle, 0, 0, 0, 0);
    int shiftX = sizeRotated.getX() < 0 ? -sizeRotated.getBlockX() - 1 : 0;
    int shiftZ = sizeRotated.getZ() < 0 ? -sizeRotated.getBlockZ() - 1 : 0;

    BaseBlock newData[][][] =
        new BaseBlock[Math.abs(sizeRotated.getBlockX())][Math.abs(sizeRotated.getBlockY())]
            [Math.abs(sizeRotated.getBlockZ())];

    for (int x = 0; x < width; ++x) {
      for (int z = 0; z < length; ++z) {
        Vector v = (new Vector(x, 0, z)).transform2D(angle, 0, 0, 0, 0);
        int newX = v.getBlockX();
        int newZ = v.getBlockZ();
        for (int y = 0; y < height; ++y) {
          BaseBlock block = data[x][y][z];
          newData[shiftX + newX][y][shiftZ + newZ] = block;

          if (reverse) {
            for (int i = 0; i < numRotations; ++i) {
              block.rotate90Reverse();
            }
          } else {
            for (int i = 0; i < numRotations; ++i) {
              block.rotate90();
            }
          }
        }
      }
    }

    data = newData;
    size =
        new Vector(
            Math.abs(sizeRotated.getBlockX()),
            Math.abs(sizeRotated.getBlockY()),
            Math.abs(sizeRotated.getBlockZ()));
    offset = offset.transform2D(angle, 0, 0, 0, 0).subtract(shiftX, 0, shiftZ);
  }
Exemplo n.º 2
0
 public void print() {
   super.print();
   String s = "DataSize: " + getDataSize() + " packSize: " + getPackSize();
 }