RenderTileFusionPedistal.java 文件源码

java
阅读 15 收藏 0 点赞 0 评论 0

项目:CrystalMod 作者:
public static void renderBeam(double x1, double y1, double z1, double x2, double y2, double z2, int tick, float partialTicks, double beamWidth, int r, int g, int b, float alpha)
  {
Tessellator tessy = Tessellator.getInstance();
      VertexBuffer render = tessy.getBuffer();

      Vec3d vec1 = new Vec3d(x1, y1, z1);
      Vec3d vec2 = new Vec3d(x2, y2, z2);
      Vec3d combinedVec = vec2.subtract(vec1);

      double rot = tick > 0 ? ((ClientEventHandler.elapsedTicks + partialTicks) * (tick)) % 360 : 0;
      double pitch = Math.atan2(combinedVec.yCoord, Math.sqrt(combinedVec.xCoord*combinedVec.xCoord+combinedVec.zCoord*combinedVec.zCoord));
      double yaw = Math.atan2(-combinedVec.zCoord, combinedVec.xCoord);

      double length = combinedVec.lengthVector();

      GlStateManager.pushMatrix();

      GlStateManager.disableLighting();
      GlStateManager.enableBlend();
      GlStateManager.blendFunc(SourceFactor.SRC_ALPHA, DestFactor.ONE);
      int func = GL11.glGetInteger(GL11.GL_ALPHA_TEST_FUNC);
      float ref = GL11.glGetFloat(GL11.GL_ALPHA_TEST_REF);
      GlStateManager.alphaFunc(GL11.GL_ALWAYS, 0);
      GlStateManager.translate(x1-TileEntityRendererDispatcher.staticPlayerX, y1-TileEntityRendererDispatcher.staticPlayerY, z1-TileEntityRendererDispatcher.staticPlayerZ);
      GlStateManager.rotate((float)(180*yaw/Math.PI), 0, 1, 0);
      GlStateManager.rotate((float)(180*pitch/Math.PI), 0, 0, 1);
      GlStateManager.rotate((float)rot, 1, 0, 0);
      GlStateManager.disableTexture2D();
      render.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_LMAP_COLOR);
      final int MAX_LIGHT_X = 0xF000F0;
      final int MAX_LIGHT_Y = 0xF000F0;

      float red = r/255F, green = g/255F, blue = b/255F;

      for(double i = 0; i < 4; i++){
          double width = beamWidth*(i/4.0);
          render.pos(length, width, width).tex(0, 0).lightmap(MAX_LIGHT_X, MAX_LIGHT_Y).color(red, green, blue, alpha).endVertex();
          render.pos(0, width, width).tex(0, 0).lightmap(MAX_LIGHT_X, MAX_LIGHT_Y).color(red, green, blue, alpha).endVertex();
          render.pos(0, -width, width).tex(0, 0).lightmap(MAX_LIGHT_X, MAX_LIGHT_Y).color(red, green, blue, alpha).endVertex();
          render.pos(length, -width, width).tex(0, 0).lightmap(MAX_LIGHT_X, MAX_LIGHT_Y).color(red, green, blue, alpha).endVertex();

          render.pos(length, -width, -width).tex(0, 0).lightmap(MAX_LIGHT_X, MAX_LIGHT_Y).color(red, green, blue, alpha).endVertex();
          render.pos(0, -width, -width).tex(0, 0).lightmap(MAX_LIGHT_X, MAX_LIGHT_Y).color(red, green, blue, alpha).endVertex();
          render.pos(0, width, -width).tex(0, 0).lightmap(MAX_LIGHT_X, MAX_LIGHT_Y).color(red, green, blue, alpha).endVertex();
          render.pos(length, width, -width).tex(0, 0).lightmap(MAX_LIGHT_X, MAX_LIGHT_Y).color(red, green, blue, alpha).endVertex();

          render.pos(length, width, -width).tex(0, 0).lightmap(MAX_LIGHT_X, MAX_LIGHT_Y).color(red, green, blue, alpha).endVertex();
          render.pos(0, width, -width).tex(0, 0).lightmap(MAX_LIGHT_X, MAX_LIGHT_Y).color(red, green, blue, alpha).endVertex();
          render.pos(0, width, width).tex(0, 0).lightmap(MAX_LIGHT_X, MAX_LIGHT_Y).color(red, green, blue, alpha).endVertex();
          render.pos(length, width, width).tex(0, 0).lightmap(MAX_LIGHT_X, MAX_LIGHT_Y).color(red, green, blue, alpha).endVertex();

          render.pos(length, -width, width).tex(0, 0).lightmap(MAX_LIGHT_X, MAX_LIGHT_Y).color(red, green, blue, alpha).endVertex();
          render.pos(0, -width, width).tex(0, 0).lightmap(MAX_LIGHT_X, MAX_LIGHT_Y).color(red, green, blue, alpha).endVertex();
          render.pos(0, -width, -width).tex(0, 0).lightmap(MAX_LIGHT_X, MAX_LIGHT_Y).color(red, green, blue, alpha).endVertex();
          render.pos(length, -width, -width).tex(0, 0).lightmap(MAX_LIGHT_X, MAX_LIGHT_Y).color(red, green, blue, alpha).endVertex();
      }
      tessy.draw();

      GlStateManager.enableTexture2D();

      GlStateManager.alphaFunc(func, ref);
      GlStateManager.blendFunc(SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA);
      GlStateManager.disableBlend();
      GlStateManager.enableLighting();
      GlStateManager.popMatrix();
  }
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号