@Override
  public BlockDesign rotate(int degrees) {
    double angle = Math.toRadians(degrees);
    float[][] rotmatrix = {
      {(float) Math.cos(angle), 0f, (float) Math.sin(angle)},
      {0f, 1f, 0f},
      {(float) -Math.sin(angle), 0f, (float) Math.cos(angle)}
    };

    float[][] xx = new float[xPos.length][xPos[0].length];
    float[][] yy = new float[yPos.length][yPos[0].length];
    float[][] zz = new float[zPos.length][zPos[0].length];
    int[] lightx = new int[lightSourceXOffset.length];
    int[] lighty = new int[lightSourceYOffset.length];
    int[] lightz = new int[lightSourceZOffset.length];
    for (int i = 0; i < xx.length; i++) {
      for (int j = 0; j < 4; j++) {
        float x1 = xPos[i][j] - 0.5f; // shift 0.5 to center around origin.
        float y1 = yPos[i][j] - 0.5f;
        float z1 = zPos[i][j] - 0.5f;
        float x2 = (x1 * rotmatrix[0][0]) + (y1 * rotmatrix[0][1]) + (z1 * rotmatrix[0][2]);
        float y2 = (x1 * rotmatrix[1][0]) + (y1 * rotmatrix[1][1]) + (z1 * rotmatrix[1][2]);
        float z2 = (x1 * rotmatrix[2][0]) + (y1 * rotmatrix[2][1]) + (z1 * rotmatrix[2][2]);
        xx[i][j] = x2 + 0.5f;
        yy[i][j] = y2 + 0.5f;
        zz[i][j] = z2 + 0.5f;
        int side = i;
        if (side > 0 && side < 5 && angle != 0) {
          side--;
          side += (4 - (degrees / 90));
          side = (side % 4) + 1;
        }
        lightx[side] = lightSourceXOffset[i];
        lighty[side] = lightSourceYOffset[i];
        lightz[side] = lightSourceZOffset[i];
      }
    }

    GenericBlockDesign des =
        new GenericBlockDesign(
            lowXBound,
            lowYBound,
            lowZBound,
            highXBound,
            highYBound,
            highZBound,
            textureURL,
            Bukkit.getPluginManager().getPlugin(texturePlugin),
            xx,
            yy,
            zz,
            textXPos,
            textYPos,
            renderPass);
    des.lightSourceXOffset = lightx;
    des.lightSourceYOffset = lighty;
    des.lightSourceZOffset = lightz;
    return des;
  }
Esempio n. 2
0
  private void createDesign() {
    GenericBlockDesign design = new GenericBlockDesign();

    // Create Textures
    Texture texture = new Texture(_SimpleMaterials, _textureURL, 128, 32, 32);
    SubTexture subTextures[] = new SubTexture[3];
    subTextures[0] = new SubTexture(texture, 0, 0, 32, 32);
    subTextures[1] = new SubTexture(texture, 32, 0, 32, 32);
    subTextures[2] = new SubTexture(texture, 64, 0, 32, 32);

    // Load Shape and Texture
    ShapeManager shape = new ShapeManager(_SimpleMaterials, _shapeFileName, subTextures);
    if (!shape.loadShapeAndTexture()) {
      return;
    }

    // Set Texture and Look
    design.setTexture(_SimpleMaterials, texture);

    // Set Bounding Box (Does not work)
    design.setBoundingBox(
        shape._bb[0], shape._bb[1], shape._bb[2], shape._bb[3], shape._bb[4], shape._bb[5]);
    design.setBoundingBox(0, 0, 0, 0, 0, 0);

    // Set Quads
    int i = 0;
    design.setQuadNumber(shape._quadCount);
    for (Quad quad : shape._quads) {
      design.setQuad(quad);
      // design.setLightSource(i, 0, 1, 0);
      i++;
    }
    // Top
    design.setLightSource(0, 0, 1, 0);
    // Bottom
    design.setLightSource(1, 0, 0, 0);
    // Sides
    design.setLightSource(3, 0, 0, 1);
    design.setLightSource(4, 1, 0, 0);
    design.setLightSource(2, 0, 0, -1);
    design.setLightSource(5, -1, 0, 0);

    design.setMinBrightness(0.0f);
    design.setMaxBrightness(1.0f);
    this.setBlockDesign(design);
  }