コード例 #1
0
public class OpenGLUtils {

  private static IntBuffer viewport = GLAllocation.createDirectIntBuffer(16);

  private static FloatBuffer modelview = GLAllocation.createDirectFloatBuffer(16);

  private static FloatBuffer projection = GLAllocation.createDirectFloatBuffer(16);

  private static FloatBuffer objectCoords = GLAllocation.createDirectFloatBuffer(3);

  public static void updateMatrices() {
    GL11.glGetFloat(GL11.GL_MODELVIEW_MATRIX, modelview);
    GL11.glGetFloat(GL11.GL_PROJECTION_MATRIX, projection);
    GL11.glGetInteger(GL11.GL_VIEWPORT, viewport);
  }

  public static Vec3 unproject(float winX, float winY, float winZ) {
    GLU.gluUnProject(winX, winY, winZ, modelview, projection, viewport, objectCoords);

    float objectX = objectCoords.get(0);
    float objectY = objectCoords.get(1);
    float objectZ = objectCoords.get(2);

    return Vec3.createVectorHelper(objectX, objectY, objectZ);
  }
}
コード例 #2
0
  @SubscribeEvent
  @SideOnly(Side.CLIENT)
  public void renderLast(RenderWorldLastEvent evt) {
    // TODO: while the urbanist is deactivated, this code can be dormant.
    // it happens to be very expensive at run time, so we need some way
    // to operate it only when relevant (e.g. in the cycle following a
    // click request).
    if (NONRELEASED_BLOCKS) {
      return;
    }

    /**
     * Note (SpaceToad): Why on earth this thing eventually worked out is a mystery to me. In
     * particular, all the examples I got computed y in a different way. Anyone with further OpenGL
     * understanding would be welcome to explain.
     *
     * <p>Anyway, the purpose of this code is to store the block position pointed by the mouse at
     * each frame, relative to the entity that has the camera.
     *
     * <p>It got heavily inspire from the two following sources:
     * http://nehe.gamedev.net/article/using_gluunproject/16013/ #ActiveRenderInfo.updateRenderInfo.
     *
     * <p>See EntityUrbanist#rayTraceMouse for a usage example.
     */
    if (modelviewF == null) {
      modelviewF = GLAllocation.createDirectFloatBuffer(16);
      projectionF = GLAllocation.createDirectFloatBuffer(16);
      viewport = GLAllocation.createDirectIntBuffer(16);
    }

    GL11.glGetFloat(GL11.GL_MODELVIEW_MATRIX, modelviewF);
    GL11.glGetFloat(GL11.GL_PROJECTION_MATRIX, projectionF);
    GL11.glGetInteger(GL11.GL_VIEWPORT, viewport);
    float f = (viewport.get(0) + viewport.get(2)) / 2;
    float f1 = (viewport.get(1) + viewport.get(3)) / 2;

    float x = Mouse.getX();
    float y = Mouse.getY();

    // TODO: Minecraft seems to instist to have this winZ re-created at
    // each frame - looks like a memory leak to me but I couldn't use a
    // static variable instead, as for the rest.
    FloatBuffer winZ = GLAllocation.createDirectFloatBuffer(1);
    GL11.glReadPixels((int) x, (int) y, 1, 1, GL11.GL_DEPTH_COMPONENT, GL11.GL_FLOAT, winZ);

    GLU.gluUnProject(x, y, winZ.get(), modelviewF, projectionF, viewport, pos);

    diffX = pos.get(0);
    diffY = pos.get(1);
    diffZ = pos.get(2);
  }
コード例 #3
0
ファイル: RenderDimDoor.java プロジェクト: nallar/DimDoors
@SideOnly(Side.CLIENT)
public class RenderDimDoor extends TileEntitySpecialRenderer {
  FloatBuffer field_76908_a = GLAllocation.createDirectFloatBuffer(16);

  public RenderDimDoor() {
    if (properties == null) properties = DDProperties.instance();
  }

  private static DDProperties properties = null;

  /** Renders the dimdoor. */
  public void renderDimDoorTileEntity(
      TileEntityDimDoor tile, double x, double y, double z, float par8) {
    try {
      dimDoor
          .class
          .cast(Block.blocksList[properties.DimensionalDoorID])
          .updateAttatchedTile(tile.worldObj, tile.xCoord, tile.yCoord, tile.zCoord)
          .getFullMetadata(tile.worldObj, tile.xCoord, tile.yCoord, tile.zCoord);

    } catch (Exception e) {

      e.printStackTrace();
    }

    // float playerX = (float)this.tileEntityRenderer.playerX;
    // float playerY = (float)this.tileEntityRenderer.playerY;
    // float playerZ = (float)this.tileEntityRenderer.playerZ;

    // float distance = (float) tile.getDistanceFrom(playerX, playerY, playerZ);
    GL11.glDisable(GL11.GL_LIGHTING);
    Random rand = new Random(31100L);
    float var13 = 0.75F;

    for (int count = 0; count < 16; ++count) {
      GL11.glPushMatrix();
      float var15 = (float) (16 - count);
      float var16 = 0.2625F;
      float var17 = 1.0F / (var15 + 1.0F);

      if (count == 0) {
        this.bindTextureByName("/RIFT.png");
        var17 = 0.1F;
        var15 = 25.0F;
        var16 = 0.125F;
        GL11.glEnable(GL11.GL_BLEND);
        GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
      }

      if (count == 1) {
        this.bindTextureByName("/WARP.png");
        GL11.glEnable(GL11.GL_BLEND);
        GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE);
        var16 = .5F;
      }

      float startY = (float) (+(y + (double) var13));
      float ratioY = startY + ActiveRenderInfo.objectY;
      float ratioY2 = startY + var15 + ActiveRenderInfo.objectY;
      float yConverted = ratioY / ratioY2;

      float startZ = (float) (+(z + (double) var13));
      float ratioZ = startZ + ActiveRenderInfo.objectZ;
      float ratioZ2 = startZ + var15 + ActiveRenderInfo.objectZ;
      float zConverted = ratioZ / ratioZ2;

      float startX = (float) (+(x + (double) var13));
      float ratioX = startX + ActiveRenderInfo.objectX;
      float ratioX2 = startX + var15 + ActiveRenderInfo.objectX;
      float xConverted = ratioX / ratioX2;

      yConverted += (float) (y + (double) var13);
      xConverted += (float) (x + (double) var13);
      zConverted += (float) (z + (double) var13);

      GL11.glTranslatef((float) (Minecraft.getSystemTime() % 200000L) / 200000.0F, 0, 0.0F);
      GL11.glTranslatef(0, (float) (Minecraft.getSystemTime() % 200000L) / 200000.0F, 0.0F);

      GL11.glTranslatef(0, 0, (float) (Minecraft.getSystemTime() % 200000L) / 200000.0F);

      GL11.glTexGeni(GL11.GL_S, GL11.GL_TEXTURE_GEN_MODE, GL11.GL_OBJECT_LINEAR);
      GL11.glTexGeni(GL11.GL_T, GL11.GL_TEXTURE_GEN_MODE, GL11.GL_OBJECT_LINEAR);
      GL11.glTexGeni(GL11.GL_R, GL11.GL_TEXTURE_GEN_MODE, GL11.GL_OBJECT_LINEAR);
      GL11.glTexGeni(GL11.GL_Q, GL11.GL_TEXTURE_GEN_MODE, GL11.GL_OBJECT_LINEAR);
      switch ((tile.orientation % 4) + 4) {
        case 4:
          GL11.glTexGen(
              GL11.GL_S, GL11.GL_OBJECT_PLANE, this.getFloatBuffer(0.0F, 1.0F, 0.0F, 0.0F));
          GL11.glTexGen(
              GL11.GL_T, GL11.GL_OBJECT_PLANE, this.getFloatBuffer(0.0F, 0.0F, 1.0F, 0.0F));
          GL11.glTexGen(
              GL11.GL_R, GL11.GL_OBJECT_PLANE, this.getFloatBuffer(0.0F, 0.0F, 0.0F, 1.0F));
          GL11.glTexGen(
              GL11.GL_Q, GL11.GL_OBJECT_PLANE, this.getFloatBuffer(1.0F, 0.0F, 0.0F, 0.0F));

          break;
        case 5:
          GL11.glTexGen(
              GL11.GL_S, GL11.GL_OBJECT_PLANE, this.getFloatBuffer(0.0F, 1.0F, 0.0F, 0.0F));
          GL11.glTexGen(
              GL11.GL_T, GL11.GL_OBJECT_PLANE, this.getFloatBuffer(1.0F, 0.0F, 0.0F, 0.0F));
          GL11.glTexGen(
              GL11.GL_R, GL11.GL_OBJECT_PLANE, this.getFloatBuffer(0.0F, 0.0F, 0.0F, 1.0F));
          GL11.glTexGen(
              GL11.GL_Q, GL11.GL_OBJECT_PLANE, this.getFloatBuffer(0.0F, 0.0F, 1.0F, 0.0F));
          break;
        case 6:
          GL11.glTexGen(
              GL11.GL_S, GL11.GL_OBJECT_PLANE, this.getFloatBuffer(0.0F, 1.0F, 0.0F, 0.0F));
          GL11.glTexGen(
              GL11.GL_T, GL11.GL_OBJECT_PLANE, this.getFloatBuffer(0.0F, 0.0F, 1.0F, 0.0F));
          GL11.glTexGen(
              GL11.GL_R, GL11.GL_OBJECT_PLANE, this.getFloatBuffer(0.0F, 0.0F, 0.0F, 1.0F));
          GL11.glTexGen(
              GL11.GL_Q, GL11.GL_OBJECT_PLANE, this.getFloatBuffer(1.0F, 0.0F, 0.0F, 0.0F));

          break;
        case 7:
          GL11.glTexGen(
              GL11.GL_S, GL11.GL_OBJECT_PLANE, this.getFloatBuffer(0.0F, 1.0F, 0.0F, 0.0F));
          GL11.glTexGen(
              GL11.GL_T, GL11.GL_OBJECT_PLANE, this.getFloatBuffer(1.0F, 0.0F, 0.0F, 0.0F));
          GL11.glTexGen(
              GL11.GL_R, GL11.GL_OBJECT_PLANE, this.getFloatBuffer(0.0F, 0.0F, 0.0F, 1.0F));
          GL11.glTexGen(
              GL11.GL_Q, GL11.GL_OBJECT_PLANE, this.getFloatBuffer(0.0F, 0.0F, 1.0F, 0.0F));
          break;
      }

      GL11.glEnable(GL11.GL_TEXTURE_GEN_S);
      GL11.glEnable(GL11.GL_TEXTURE_GEN_T);
      GL11.glEnable(GL11.GL_TEXTURE_GEN_R);
      GL11.glEnable(GL11.GL_TEXTURE_GEN_Q);
      GL11.glPopMatrix();
      GL11.glMatrixMode(GL11.GL_TEXTURE);
      GL11.glPushMatrix();
      GL11.glLoadIdentity();
      GL11.glTranslatef(
          0.0F, (float) (Minecraft.getSystemTime() % 200000L) / 200000.0F * var15, 0.0F);
      GL11.glScalef(var16, var16, var16);
      GL11.glTranslatef(0.5F, 0.5F, 0.5F);
      GL11.glRotatef((float) (count * count * 4321 + count * 9) * 2.0F, 0.0F, 0.0F, 1.0F);
      GL11.glTranslatef(0.5F, 0.5F, 0.5F);

      Tessellator var24 = Tessellator.instance;
      var24.startDrawingQuads();

      float var21 = rand.nextFloat() * 0.5F + 0.1F;
      float var22 = rand.nextFloat() * 0.4F + 0.4F;
      float var23 = rand.nextFloat() * 0.6F + 0.5F;

      if (count == 0) {
        var23 = 1.0F;
        var22 = 1.0F;
        yConverted = 1.0F;
      }
      var24.setColorRGBA_F(var21 * var17, var22 * var17, var23 * var17, 1.0F);
      if (tile.openOrClosed) {

        switch (tile.orientation) {
          case 0:
            var24.addVertex(x + .01F, y - 1, z);
            var24.addVertex(x + .01, y - 1, z + 1.0D);
            var24.addVertex(x + .01, y + 1, z + 1.0D);
            var24.addVertex(x + .01, y + 1, z);
            break;
          case 1:
            var24.addVertex(x, y + 1, z + .01);
            var24.addVertex(x + 1, y + 1, z + .01);
            var24.addVertex(x + 1, y - 1, z + .01);
            var24.addVertex(x, y - 1, z + .01);

            break;
          case 2: //
            var24.addVertex(x + .99, y + 1, z);
            var24.addVertex(x + .99, y + 1, z + 1.0D);
            var24.addVertex(x + .99, y - 1, z + 1.0D);
            var24.addVertex(x + .99, y - 1, z);
            break;
          case 3:
            var24.addVertex(x, y - 1, z + .99);
            var24.addVertex(x + 1, y - 1, z + .99);
            var24.addVertex(x + 1, y + 1, z + .99);
            var24.addVertex(x, y + 1, z + .99);
            break;
          case 4: //
            //   GL11.glTranslatef();

            var24.addVertex(x + .15F, y - 1, z);
            var24.addVertex(x + .15, y - 1, z + 1.0D);
            var24.addVertex(x + .15, y + 1, z + 1.0D);
            var24.addVertex(x + .15, y + 1, z);
            break;
          case 5:
            var24.addVertex(x, y + 1, z + .15);
            var24.addVertex(x + 1, y + 1, z + .15);
            var24.addVertex(x + 1, y - 1, z + .15);
            var24.addVertex(x, y - 1, z + .15);

            break;
          case 6: //
            var24.addVertex(x + .85, y + 1, z);
            var24.addVertex(x + .85, y + 1, z + 1.0D);
            var24.addVertex(x + .85, y - 1, z + 1.0D);
            var24.addVertex(x + .85, y - 1, z);
            break;
          case 7:
            var24.addVertex(x, y - 1, z + .85);
            var24.addVertex(x + 1, y - 1, z + .85);
            var24.addVertex(x + 1, y + 1, z + .85);
            var24.addVertex(x, y + 1, z + .85);
            break;
          default:
            break;
        }
      }

      var24.draw();

      GL11.glPopMatrix();
      GL11.glMatrixMode(GL11.GL_MODELVIEW);
    }

    GL11.glDisable(GL11.GL_BLEND);
    GL11.glDisable(GL11.GL_TEXTURE_GEN_S);
    GL11.glDisable(GL11.GL_TEXTURE_GEN_T);
    GL11.glDisable(GL11.GL_TEXTURE_GEN_R);
    GL11.glDisable(GL11.GL_TEXTURE_GEN_Q);
    GL11.glEnable(GL11.GL_LIGHTING);
  }

  private FloatBuffer getFloatBuffer(float par1, float par2, float par3, float par4) {
    this.field_76908_a.clear();
    this.field_76908_a.put(par1).put(par2).put(par3).put(par4);
    this.field_76908_a.flip();
    return this.field_76908_a;
  }

  public void renderTileEntityAt(
      TileEntity par1TileEntity, double par2, double par4, double par6, float par8) {
    if (properties.DoorRenderingEnabled) {
      this.renderDimDoorTileEntity((TileEntityDimDoor) par1TileEntity, par2, par4, par6, par8);
    }
  }
}
コード例 #4
0
public class ClippingHelperImpl extends ClippingHelper {
  private static ClippingHelperImpl instance = new ClippingHelperImpl();
  private FloatBuffer projectionMatrixBuffer = GLAllocation.createDirectFloatBuffer(16);
  private FloatBuffer modelviewMatrixBuffer = GLAllocation.createDirectFloatBuffer(16);
  private FloatBuffer field_78564_h = GLAllocation.createDirectFloatBuffer(16);
  private static final String __OBFID = "CL_00000975";

  /** Initialises the ClippingHelper object then returns an instance of it. */
  public static ClippingHelper getInstance() {
    instance.init();
    return instance;
  }

  /** Normalize the frustum. */
  private void normalize(float[][] p_78559_1_, int p_78559_2_) {
    float var3 =
        MathHelper.sqrt_float(
            p_78559_1_[p_78559_2_][0] * p_78559_1_[p_78559_2_][0]
                + p_78559_1_[p_78559_2_][1] * p_78559_1_[p_78559_2_][1]
                + p_78559_1_[p_78559_2_][2] * p_78559_1_[p_78559_2_][2]);
    p_78559_1_[p_78559_2_][0] /= var3;
    p_78559_1_[p_78559_2_][1] /= var3;
    p_78559_1_[p_78559_2_][2] /= var3;
    p_78559_1_[p_78559_2_][3] /= var3;
  }

  private void init() {
    this.projectionMatrixBuffer.clear();
    this.modelviewMatrixBuffer.clear();
    this.field_78564_h.clear();
    GL11.glGetFloat(GL11.GL_PROJECTION_MATRIX, this.projectionMatrixBuffer);
    GL11.glGetFloat(GL11.GL_MODELVIEW_MATRIX, this.modelviewMatrixBuffer);
    this.projectionMatrixBuffer.flip().limit(16);
    this.projectionMatrixBuffer.get(this.projectionMatrix);
    this.modelviewMatrixBuffer.flip().limit(16);
    this.modelviewMatrixBuffer.get(this.modelviewMatrix);
    this.clippingMatrix[0] =
        this.modelviewMatrix[0] * this.projectionMatrix[0]
            + this.modelviewMatrix[1] * this.projectionMatrix[4]
            + this.modelviewMatrix[2] * this.projectionMatrix[8]
            + this.modelviewMatrix[3] * this.projectionMatrix[12];
    this.clippingMatrix[1] =
        this.modelviewMatrix[0] * this.projectionMatrix[1]
            + this.modelviewMatrix[1] * this.projectionMatrix[5]
            + this.modelviewMatrix[2] * this.projectionMatrix[9]
            + this.modelviewMatrix[3] * this.projectionMatrix[13];
    this.clippingMatrix[2] =
        this.modelviewMatrix[0] * this.projectionMatrix[2]
            + this.modelviewMatrix[1] * this.projectionMatrix[6]
            + this.modelviewMatrix[2] * this.projectionMatrix[10]
            + this.modelviewMatrix[3] * this.projectionMatrix[14];
    this.clippingMatrix[3] =
        this.modelviewMatrix[0] * this.projectionMatrix[3]
            + this.modelviewMatrix[1] * this.projectionMatrix[7]
            + this.modelviewMatrix[2] * this.projectionMatrix[11]
            + this.modelviewMatrix[3] * this.projectionMatrix[15];
    this.clippingMatrix[4] =
        this.modelviewMatrix[4] * this.projectionMatrix[0]
            + this.modelviewMatrix[5] * this.projectionMatrix[4]
            + this.modelviewMatrix[6] * this.projectionMatrix[8]
            + this.modelviewMatrix[7] * this.projectionMatrix[12];
    this.clippingMatrix[5] =
        this.modelviewMatrix[4] * this.projectionMatrix[1]
            + this.modelviewMatrix[5] * this.projectionMatrix[5]
            + this.modelviewMatrix[6] * this.projectionMatrix[9]
            + this.modelviewMatrix[7] * this.projectionMatrix[13];
    this.clippingMatrix[6] =
        this.modelviewMatrix[4] * this.projectionMatrix[2]
            + this.modelviewMatrix[5] * this.projectionMatrix[6]
            + this.modelviewMatrix[6] * this.projectionMatrix[10]
            + this.modelviewMatrix[7] * this.projectionMatrix[14];
    this.clippingMatrix[7] =
        this.modelviewMatrix[4] * this.projectionMatrix[3]
            + this.modelviewMatrix[5] * this.projectionMatrix[7]
            + this.modelviewMatrix[6] * this.projectionMatrix[11]
            + this.modelviewMatrix[7] * this.projectionMatrix[15];
    this.clippingMatrix[8] =
        this.modelviewMatrix[8] * this.projectionMatrix[0]
            + this.modelviewMatrix[9] * this.projectionMatrix[4]
            + this.modelviewMatrix[10] * this.projectionMatrix[8]
            + this.modelviewMatrix[11] * this.projectionMatrix[12];
    this.clippingMatrix[9] =
        this.modelviewMatrix[8] * this.projectionMatrix[1]
            + this.modelviewMatrix[9] * this.projectionMatrix[5]
            + this.modelviewMatrix[10] * this.projectionMatrix[9]
            + this.modelviewMatrix[11] * this.projectionMatrix[13];
    this.clippingMatrix[10] =
        this.modelviewMatrix[8] * this.projectionMatrix[2]
            + this.modelviewMatrix[9] * this.projectionMatrix[6]
            + this.modelviewMatrix[10] * this.projectionMatrix[10]
            + this.modelviewMatrix[11] * this.projectionMatrix[14];
    this.clippingMatrix[11] =
        this.modelviewMatrix[8] * this.projectionMatrix[3]
            + this.modelviewMatrix[9] * this.projectionMatrix[7]
            + this.modelviewMatrix[10] * this.projectionMatrix[11]
            + this.modelviewMatrix[11] * this.projectionMatrix[15];
    this.clippingMatrix[12] =
        this.modelviewMatrix[12] * this.projectionMatrix[0]
            + this.modelviewMatrix[13] * this.projectionMatrix[4]
            + this.modelviewMatrix[14] * this.projectionMatrix[8]
            + this.modelviewMatrix[15] * this.projectionMatrix[12];
    this.clippingMatrix[13] =
        this.modelviewMatrix[12] * this.projectionMatrix[1]
            + this.modelviewMatrix[13] * this.projectionMatrix[5]
            + this.modelviewMatrix[14] * this.projectionMatrix[9]
            + this.modelviewMatrix[15] * this.projectionMatrix[13];
    this.clippingMatrix[14] =
        this.modelviewMatrix[12] * this.projectionMatrix[2]
            + this.modelviewMatrix[13] * this.projectionMatrix[6]
            + this.modelviewMatrix[14] * this.projectionMatrix[10]
            + this.modelviewMatrix[15] * this.projectionMatrix[14];
    this.clippingMatrix[15] =
        this.modelviewMatrix[12] * this.projectionMatrix[3]
            + this.modelviewMatrix[13] * this.projectionMatrix[7]
            + this.modelviewMatrix[14] * this.projectionMatrix[11]
            + this.modelviewMatrix[15] * this.projectionMatrix[15];
    this.frustum[0][0] = this.clippingMatrix[3] - this.clippingMatrix[0];
    this.frustum[0][1] = this.clippingMatrix[7] - this.clippingMatrix[4];
    this.frustum[0][2] = this.clippingMatrix[11] - this.clippingMatrix[8];
    this.frustum[0][3] = this.clippingMatrix[15] - this.clippingMatrix[12];
    this.normalize(this.frustum, 0);
    this.frustum[1][0] = this.clippingMatrix[3] + this.clippingMatrix[0];
    this.frustum[1][1] = this.clippingMatrix[7] + this.clippingMatrix[4];
    this.frustum[1][2] = this.clippingMatrix[11] + this.clippingMatrix[8];
    this.frustum[1][3] = this.clippingMatrix[15] + this.clippingMatrix[12];
    this.normalize(this.frustum, 1);
    this.frustum[2][0] = this.clippingMatrix[3] + this.clippingMatrix[1];
    this.frustum[2][1] = this.clippingMatrix[7] + this.clippingMatrix[5];
    this.frustum[2][2] = this.clippingMatrix[11] + this.clippingMatrix[9];
    this.frustum[2][3] = this.clippingMatrix[15] + this.clippingMatrix[13];
    this.normalize(this.frustum, 2);
    this.frustum[3][0] = this.clippingMatrix[3] - this.clippingMatrix[1];
    this.frustum[3][1] = this.clippingMatrix[7] - this.clippingMatrix[5];
    this.frustum[3][2] = this.clippingMatrix[11] - this.clippingMatrix[9];
    this.frustum[3][3] = this.clippingMatrix[15] - this.clippingMatrix[13];
    this.normalize(this.frustum, 3);
    this.frustum[4][0] = this.clippingMatrix[3] - this.clippingMatrix[2];
    this.frustum[4][1] = this.clippingMatrix[7] - this.clippingMatrix[6];
    this.frustum[4][2] = this.clippingMatrix[11] - this.clippingMatrix[10];
    this.frustum[4][3] = this.clippingMatrix[15] - this.clippingMatrix[14];
    this.normalize(this.frustum, 4);
    this.frustum[5][0] = this.clippingMatrix[3] + this.clippingMatrix[2];
    this.frustum[5][1] = this.clippingMatrix[7] + this.clippingMatrix[6];
    this.frustum[5][2] = this.clippingMatrix[11] + this.clippingMatrix[10];
    this.frustum[5][3] = this.clippingMatrix[15] + this.clippingMatrix[14];
    this.normalize(this.frustum, 5);
  }
}
コード例 #5
0
public class ClippingHelperImpl extends ClippingHelper {
  private static ClippingHelperImpl instance = new ClippingHelperImpl();
  private FloatBuffer projectionMatrixBuffer = GLAllocation.createDirectFloatBuffer(16);
  private FloatBuffer modelviewMatrixBuffer = GLAllocation.createDirectFloatBuffer(16);
  private FloatBuffer field_78564_h = GLAllocation.createDirectFloatBuffer(16);
  private static final String __OBFID = "CL_00000975";

  /** Initialises the ClippingHelper object then returns an instance of it. */
  public static ClippingHelper getInstance() {
    instance.init();
    return instance;
  }

  private void func_180547_a(float[] p_180547_1_) {
    float var2 =
        MathHelper.sqrt_float(
            p_180547_1_[0] * p_180547_1_[0]
                + p_180547_1_[1] * p_180547_1_[1]
                + p_180547_1_[2] * p_180547_1_[2]);
    p_180547_1_[0] /= var2;
    p_180547_1_[1] /= var2;
    p_180547_1_[2] /= var2;
    p_180547_1_[3] /= var2;
  }

  public void init() {
    this.projectionMatrixBuffer.clear();
    this.modelviewMatrixBuffer.clear();
    this.field_78564_h.clear();
    GlStateManager.getFloat(2983, this.projectionMatrixBuffer);
    GlStateManager.getFloat(2982, this.modelviewMatrixBuffer);
    float[] var1 = this.field_178625_b;
    float[] var2 = this.field_178626_c;
    this.projectionMatrixBuffer.flip().limit(16);
    this.projectionMatrixBuffer.get(var1);
    this.modelviewMatrixBuffer.flip().limit(16);
    this.modelviewMatrixBuffer.get(var2);
    this.clippingMatrix[0] =
        var2[0] * var1[0] + var2[1] * var1[4] + var2[2] * var1[8] + var2[3] * var1[12];
    this.clippingMatrix[1] =
        var2[0] * var1[1] + var2[1] * var1[5] + var2[2] * var1[9] + var2[3] * var1[13];
    this.clippingMatrix[2] =
        var2[0] * var1[2] + var2[1] * var1[6] + var2[2] * var1[10] + var2[3] * var1[14];
    this.clippingMatrix[3] =
        var2[0] * var1[3] + var2[1] * var1[7] + var2[2] * var1[11] + var2[3] * var1[15];
    this.clippingMatrix[4] =
        var2[4] * var1[0] + var2[5] * var1[4] + var2[6] * var1[8] + var2[7] * var1[12];
    this.clippingMatrix[5] =
        var2[4] * var1[1] + var2[5] * var1[5] + var2[6] * var1[9] + var2[7] * var1[13];
    this.clippingMatrix[6] =
        var2[4] * var1[2] + var2[5] * var1[6] + var2[6] * var1[10] + var2[7] * var1[14];
    this.clippingMatrix[7] =
        var2[4] * var1[3] + var2[5] * var1[7] + var2[6] * var1[11] + var2[7] * var1[15];
    this.clippingMatrix[8] =
        var2[8] * var1[0] + var2[9] * var1[4] + var2[10] * var1[8] + var2[11] * var1[12];
    this.clippingMatrix[9] =
        var2[8] * var1[1] + var2[9] * var1[5] + var2[10] * var1[9] + var2[11] * var1[13];
    this.clippingMatrix[10] =
        var2[8] * var1[2] + var2[9] * var1[6] + var2[10] * var1[10] + var2[11] * var1[14];
    this.clippingMatrix[11] =
        var2[8] * var1[3] + var2[9] * var1[7] + var2[10] * var1[11] + var2[11] * var1[15];
    this.clippingMatrix[12] =
        var2[12] * var1[0] + var2[13] * var1[4] + var2[14] * var1[8] + var2[15] * var1[12];
    this.clippingMatrix[13] =
        var2[12] * var1[1] + var2[13] * var1[5] + var2[14] * var1[9] + var2[15] * var1[13];
    this.clippingMatrix[14] =
        var2[12] * var1[2] + var2[13] * var1[6] + var2[14] * var1[10] + var2[15] * var1[14];
    this.clippingMatrix[15] =
        var2[12] * var1[3] + var2[13] * var1[7] + var2[14] * var1[11] + var2[15] * var1[15];
    float[] var3 = this.frustum[0];
    var3[0] = this.clippingMatrix[3] - this.clippingMatrix[0];
    var3[1] = this.clippingMatrix[7] - this.clippingMatrix[4];
    var3[2] = this.clippingMatrix[11] - this.clippingMatrix[8];
    var3[3] = this.clippingMatrix[15] - this.clippingMatrix[12];
    this.func_180547_a(var3);
    float[] var4 = this.frustum[1];
    var4[0] = this.clippingMatrix[3] + this.clippingMatrix[0];
    var4[1] = this.clippingMatrix[7] + this.clippingMatrix[4];
    var4[2] = this.clippingMatrix[11] + this.clippingMatrix[8];
    var4[3] = this.clippingMatrix[15] + this.clippingMatrix[12];
    this.func_180547_a(var4);
    float[] var5 = this.frustum[2];
    var5[0] = this.clippingMatrix[3] + this.clippingMatrix[1];
    var5[1] = this.clippingMatrix[7] + this.clippingMatrix[5];
    var5[2] = this.clippingMatrix[11] + this.clippingMatrix[9];
    var5[3] = this.clippingMatrix[15] + this.clippingMatrix[13];
    this.func_180547_a(var5);
    float[] var6 = this.frustum[3];
    var6[0] = this.clippingMatrix[3] - this.clippingMatrix[1];
    var6[1] = this.clippingMatrix[7] - this.clippingMatrix[5];
    var6[2] = this.clippingMatrix[11] - this.clippingMatrix[9];
    var6[3] = this.clippingMatrix[15] - this.clippingMatrix[13];
    this.func_180547_a(var6);
    float[] var7 = this.frustum[4];
    var7[0] = this.clippingMatrix[3] - this.clippingMatrix[2];
    var7[1] = this.clippingMatrix[7] - this.clippingMatrix[6];
    var7[2] = this.clippingMatrix[11] - this.clippingMatrix[10];
    var7[3] = this.clippingMatrix[15] - this.clippingMatrix[14];
    this.func_180547_a(var7);
    float[] var8 = this.frustum[5];
    var8[0] = this.clippingMatrix[3] + this.clippingMatrix[2];
    var8[1] = this.clippingMatrix[7] + this.clippingMatrix[6];
    var8[2] = this.clippingMatrix[11] + this.clippingMatrix[10];
    var8[3] = this.clippingMatrix[15] + this.clippingMatrix[14];
    this.func_180547_a(var8);
  }
}
コード例 #6
0
public abstract class RenderLocusPoint extends ChromaRenderBase {

  @Override
  public final void renderTileEntityAt(
      TileEntity tile, double par2, double par4, double par6, float par8) {
    GL11.glPushMatrix();
    GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
    GL11.glDisable(GL11.GL_ALPHA_TEST);
    GL11.glDisable(GL11.GL_LIGHTING);
    GL11.glDisable(GL11.GL_CULL_FACE);
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glDepthMask(false);
    GL11.glColor4f(1, 1, 1, 1);
    GL11.glTranslated(par2, par4, par6);
    if (MinecraftForgeClient.getRenderPass() == 1 || !tile.hasWorldObj())
      this.renderCore((TileEntityLocusPoint) tile, par2, par4, par6, par8);
    this.doOtherRendering((TileEntityLocusPoint) tile, par8);
    GL11.glPopAttrib();
    GL11.glPopMatrix();
  }

  protected abstract void doOtherRendering(TileEntityLocusPoint tile, float par8);

  private void renderCore(
      TileEntityLocusPoint tile, double par2, double par4, double par6, float par8) {
    Tessellator v5 = Tessellator.instance;
    // this.renderStaticTexture(par2, par4, par6, par8);
    // BlendMode.ADDITIVEDARK.apply();
    BlendMode.ADDITIVE2.apply();
    GL11.glPushMatrix();
    GL11.glTranslated(0.5, 0.5, 0.5);
    RenderManager rm = RenderManager.instance;
    if (tile.hasWorldObj()) {
      GL11.glRotatef(-rm.playerViewY, 0.0F, 1.0F, 0.0F);
      GL11.glRotatef(rm.playerViewX, 1.0F, 0.0F, 0.0F);
    } else {
      GL11.glTranslated(0.55, 0.5, 0.5);
      GL11.glRotatef(45, 0, 1, 0);
      GL11.glRotatef(-30, 1, 0, 0);
    }

    // ReikaJavaLibrary.pConsole(te.getEnergy());

    ReikaTextureHelper.bindTexture(ChromatiCraft.class, "Textures/aurapoint2-grid.png");

    for (int i = 0; i < 3; i++) {

      int alpha = 255 - i * 64; // 255;
      int tick =
          (int)
              ((System.currentTimeMillis() / 250)
                  % 80); // (tile.getTicksExisted()*(i*3+1))%80;//+par8;
      double u = (tick % 8) / 8D; // tick/80D;//0;//0.125;
      double v = (tick / 8) / 10D; // 0;//(int)(tick/20)/4D;//0.125;
      double du = u + 1 / 8D; // u+1/80D;//u+1;//0.9375;
      double dv = v + 1 / 10D; // v+1;//0.9375;

      double s = 1 - i * 0.25;
      // for (double s = 0.5; s >= 0.25; s -= 0.0625) {

      GL11.glPushMatrix();

      double s1 = tile.isInWorld() ? s : s;

      GL11.glScaled(s1, s1, s1);
      /*
      	GL11.glMatrixMode(GL11.GL_TEXTURE);
      	GL11.glPushMatrix();

      	/*
      double d = 0.5;
      GL11.glTranslated(d, d, d);
      GL11.glRotated(rm.playerViewY, 0, 0, 1);
      GL11.glTranslated(-d, -d, -d);
      	 */
      if (tile.isInWorld()) {
        double d = 0.5;
        GL11.glTranslated(d, d, d);

        double dx = tile.xCoord + 0.5 - RenderManager.renderPosX;
        double dy = tile.yCoord + 0.5 - RenderManager.renderPosY;
        double dz = tile.zCoord + 0.5 - RenderManager.renderPosZ;
        double[] angs = ReikaPhysicsHelper.cartesianToPolar(dx, dy, dz);
        GL11.glTranslated(-d, -d, -d);
        GL11.glRotated(angs[2], 0, 0, 1);
      }

      // GL11.glMatrixMode(GL11.GL_MODELVIEW);

      v5.startDrawingQuads();
      v5.setBrightness(240);
      int color =
          ReikaColorAPI.getColorWithBrightnessMultiplier(tile.getRenderColor(), alpha / 255F);
      v5.setColorRGBA_I(color, alpha);
      v5.addVertexWithUV(-1, -1, 0, u, v);
      v5.addVertexWithUV(1, -1, 0, du, v);
      v5.addVertexWithUV(1, 1, 0, du, dv);
      v5.addVertexWithUV(-1, 1, 0, u, dv);
      v5.draw();

      // GL11.glMatrixMode(GL11.GL_TEXTURE);
      // GL11.glPopMatrix();
      // GL11.glMatrixMode(GL11.GL_MODELVIEW);

      GL11.glPopMatrix();

      // }
    }

    double s = 0.5;
    GL11.glScaled(s, s, s);

    /*
    ReikaTextureHelper.bindTexture(ChromatiCraft.class, "Textures/Dimension Bump Maps/gray.png");

    u = 0;
    v = 0;
    du = 1;
    dv = 1;

    GL11.glMatrixMode(GL11.GL_TEXTURE);
    GL11.glPushMatrix();

    GL11.glRotated(angs[2], 0, 1, 0);
    GL11.glRotated(90-angs[1], 1, 0, 0);

    GL11.glMatrixMode(GL11.GL_MODELVIEW);

    v5.startDrawingQuads();
    v5.setColorRGBA_I(this.getColor(), alpha);
    v5.addVertexWithUV(-1, -1, 0, u, v);
    v5.addVertexWithUV(1, -1, 0, du, v);
    v5.addVertexWithUV(1, 1, 0, du, dv);
    v5.addVertexWithUV(-1, 1, 0, u, dv);
    v5.draw();


    GL11.glMatrixMode(GL11.GL_TEXTURE);
    GL11.glPopMatrix();
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
     */

    GL11.glPopMatrix();
  }

  private static final Random staticRand = new Random(31100L);
  FloatBuffer fBuffer = GLAllocation.createDirectFloatBuffer(16);

  private void renderStaticTexture(double par2, double par4, double par6, float ptick) {
    float f1 = (float) field_147501_a.field_147560_j;
    float f2 = (float) field_147501_a.field_147561_k;
    float f3 = (float) field_147501_a.field_147558_l;
    staticRand.setSeed(31100L);

    float f4 = 1.001F; // 0.75F;//+i*0.125F;
    GL11.glPushMatrix();
    float f5 = 16;
    float f6 = 0.0625F;
    float f7 = 1.0F / (f5 + 1.0F);

    float f8 = (float) (-(par4 + f4));
    float f9 = f8 + ActiveRenderInfo.objectY;
    float f10 = f8 + f5 + ActiveRenderInfo.objectY;
    float f11 = f9 / f10;
    f11 += (float) (par4 + f4);
    // GL11.glTranslatef(f1, f11, f3);
    GL11.glTexGeni(GL11.GL_S, GL11.GL_TEXTURE_GEN_MODE, GL11.GL_OBJECT_LINEAR);
    GL11.glTexGeni(GL11.GL_T, GL11.GL_TEXTURE_GEN_MODE, GL11.GL_OBJECT_LINEAR);
    GL11.glTexGeni(GL11.GL_R, GL11.GL_TEXTURE_GEN_MODE, GL11.GL_OBJECT_LINEAR);
    GL11.glTexGeni(GL11.GL_Q, GL11.GL_TEXTURE_GEN_MODE, GL11.GL_EYE_LINEAR);
    GL11.glTexGen(GL11.GL_S, GL11.GL_OBJECT_PLANE, this.genBuffer(1.0F, 0.0F, 0.0F, 0.0F));
    GL11.glTexGen(GL11.GL_T, GL11.GL_OBJECT_PLANE, this.genBuffer(0.0F, 0.0F, 1.0F, 0.0F));
    GL11.glTexGen(GL11.GL_R, GL11.GL_OBJECT_PLANE, this.genBuffer(0.0F, 0.0F, 0.0F, 1.0F));
    GL11.glTexGen(GL11.GL_Q, GL11.GL_EYE_PLANE, this.genBuffer(0.0F, 1.0F, 0.0F, 0.0F));
    GL11.glEnable(GL11.GL_TEXTURE_GEN_S);
    GL11.glEnable(GL11.GL_TEXTURE_GEN_T);
    GL11.glEnable(GL11.GL_TEXTURE_GEN_R);
    GL11.glEnable(GL11.GL_TEXTURE_GEN_Q);
    GL11.glPopMatrix();
    GL11.glMatrixMode(GL11.GL_TEXTURE);
    GL11.glPushMatrix();
    GL11.glLoadIdentity();
    GL11.glTranslatef(0.0F, Minecraft.getSystemTime() % 700000L / 700000.0F, 0.0F);
    GL11.glScalef(f6, f6, f6);
    GL11.glTranslatef(0.5F, 0.5F, 0.0F);
    GL11.glTranslatef(-0.5F, -0.5F, 0.0F);
    // GL11.glTranslatef(-f1, -f3, -f2);
    f9 = f8 + ActiveRenderInfo.objectY;
    GL11.glTranslatef(ActiveRenderInfo.objectX * f5 / f9, ActiveRenderInfo.objectZ * f5 / f9, -f2);
    Tessellator v5 = Tessellator.instance;
    v5.startDrawingQuads();
    f11 = staticRand.nextFloat() * 0.5F + 0.1F;
    float f12 = staticRand.nextFloat() * 0.5F + 0.4F;
    float f13 = staticRand.nextFloat() * 0.5F + 0.5F;

    f7 = 1;
    f13 = 1.0F;
    f12 = 1.0F;
    f11 = 1.0F;

    // v5.setColorRGBA_F(e.getRed()*f7/255F, e.getGreen()*f7/255F, e.getBlue()*f7/255F, 1);
    v5.setColorRGBA_F(f11 * f7, f12 * f7, f13 * f7, 1.0F);
    v5.addVertex(par2, par4 + f4, par6);
    v5.addVertex(par2, par4 + f4, par6 + 1.0D);
    v5.addVertex(par2 + 1.0D, par4 + f4, par6 + 1.0D);
    v5.addVertex(par2 + 1.0D, par4 + f4, par6);
    v5.draw();
    GL11.glPopMatrix();
    GL11.glMatrixMode(GL11.GL_MODELVIEW);

    GL11.glDisable(GL11.GL_TEXTURE_GEN_S);
    GL11.glDisable(GL11.GL_TEXTURE_GEN_T);
    GL11.glDisable(GL11.GL_TEXTURE_GEN_R);
    GL11.glDisable(GL11.GL_TEXTURE_GEN_Q);
  }

  private FloatBuffer genBuffer(float v1, float v2, float v3, float v4) {
    fBuffer.clear();
    fBuffer.put(v1).put(v2).put(v3).put(v4);
    fBuffer.flip();
    return fBuffer;
  }
}