2017-02-26 13:56:36 +01:00
|
|
|
/*
|
|
|
|
* This file is part of Industrial Wires.
|
|
|
|
* Copyright (C) 2016-2017 malte0811
|
|
|
|
*
|
|
|
|
* Industrial Wires is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Industrial Wires is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Industrial Wires. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package malte0811.industrialWires.client.render;
|
|
|
|
|
|
|
|
import malte0811.industrialWires.blocks.TileEntityJacobsLadder;
|
2017-03-03 17:52:22 +01:00
|
|
|
import malte0811.industrialWires.blocks.TileEntityJacobsLadder.LadderSize;
|
2017-02-26 13:56:36 +01:00
|
|
|
import malte0811.industrialWires.util.Beziers;
|
|
|
|
import net.minecraft.client.renderer.GlStateManager;
|
|
|
|
import net.minecraft.client.renderer.OpenGlHelper;
|
|
|
|
import net.minecraft.client.renderer.Tessellator;
|
|
|
|
import net.minecraft.client.renderer.VertexBuffer;
|
|
|
|
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
|
|
|
|
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
|
|
|
import net.minecraft.util.math.Vec3d;
|
|
|
|
import org.lwjgl.opengl.GL11;
|
|
|
|
|
|
|
|
public class TileRenderJacobsLadder extends TileEntitySpecialRenderer<TileEntityJacobsLadder> {
|
|
|
|
@Override
|
|
|
|
public void renderTileEntityAt(TileEntityJacobsLadder tile, double x, double y, double z, float partialTicks, int destroyStage) {
|
|
|
|
super.renderTileEntityAt(tile, x, y, z, partialTicks, destroyStage);
|
2017-05-11 16:39:20 +02:00
|
|
|
if (!tile.isDummy() && tile.timeTillActive == 0 && tile.controls[0] != null) {
|
2017-02-26 13:56:36 +01:00
|
|
|
|
|
|
|
GlStateManager.pushMatrix();
|
2017-02-28 17:32:40 +01:00
|
|
|
GlStateManager.translate(x + .5, y + tile.size.heightOffset, z + .5);
|
|
|
|
GlStateManager.rotate(tile.facing.getHorizontalAngle(), 0, 1, 0);
|
2017-05-11 16:39:20 +02:00
|
|
|
GlStateManager.translate(-tile.size.bottomDistance / 2, 0, 0);
|
2017-02-26 13:56:36 +01:00
|
|
|
|
|
|
|
GlStateManager.disableTexture2D();
|
|
|
|
GlStateManager.disableLighting();
|
2017-03-06 16:36:02 +01:00
|
|
|
GlStateManager.shadeModel(GL11.GL_SMOOTH);
|
2017-02-26 13:56:36 +01:00
|
|
|
|
|
|
|
float oldBX = OpenGlHelper.lastBrightnessX;
|
|
|
|
float oldBY = OpenGlHelper.lastBrightnessY;
|
|
|
|
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 238, 238);
|
|
|
|
GlStateManager.color(1, .85F, 1, 1);
|
|
|
|
Vec3d[] controls = new Vec3d[tile.size.arcPoints];
|
|
|
|
for (int i = 0; i < tile.size.arcPoints; i++) {
|
|
|
|
Vec3d speed = tile.controlMovement[i];
|
|
|
|
controls[i] = tile.controls[i].addVector(speed.xCoord * partialTicks, speed.yCoord * partialTicks, speed.zCoord * partialTicks);
|
|
|
|
}
|
2017-03-03 17:52:22 +01:00
|
|
|
drawBezier(controls, tile.salt, tile.size);
|
2017-02-28 17:32:40 +01:00
|
|
|
//DEBUG CODE
|
2017-02-26 13:56:36 +01:00
|
|
|
/*for (Vec3d[] c:tile.controlControls) {
|
|
|
|
drawBezier(c, .05, steps);
|
2017-02-28 17:32:40 +01:00
|
|
|
}
|
|
|
|
Vec3d topA = tile.controlMovement[0].scale(tile.size.tickToTop);
|
|
|
|
Vec3d topB = tile.controlMovement[tile.controlMovement.length-1].scale(tile.size.tickToTop).add(new Vec3d(tile.size.bottomDistance, 0, 0));
|
|
|
|
|
|
|
|
Tessellator tes = Tessellator.getInstance();
|
|
|
|
VertexBuffer vertBuffer = tes.getBuffer();
|
|
|
|
vertBuffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION);
|
|
|
|
drawQuad(Vec3d.ZERO, topA, new Vec3d(.005, 0, 0), vertBuffer);
|
|
|
|
drawQuad(new Vec3d(tile.size.bottomDistance, 0, 0), topB, new Vec3d(.005, 0, 0), vertBuffer);
|
|
|
|
tes.draw();*/
|
|
|
|
//END OF DEBUG CODE
|
2017-02-26 13:56:36 +01:00
|
|
|
|
|
|
|
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, oldBX, oldBY);
|
|
|
|
|
|
|
|
GlStateManager.enableTexture2D();
|
|
|
|
GlStateManager.enableLighting();
|
2017-03-06 16:36:02 +01:00
|
|
|
GlStateManager.shadeModel(GL11.GL_FLAT);
|
2017-02-26 13:56:36 +01:00
|
|
|
|
|
|
|
GlStateManager.popMatrix();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-03 17:52:22 +01:00
|
|
|
private void drawBezier(Vec3d[] controls, double salt, LadderSize size) {
|
|
|
|
int steps = size.renderPoints;
|
|
|
|
double diameter = size.renderDiameter;
|
2017-02-26 13:56:36 +01:00
|
|
|
Vec3d radY = new Vec3d(0, diameter / 2, 0);
|
|
|
|
Vec3d radZ = new Vec3d(0, 0, diameter / 2);
|
|
|
|
Tessellator tes = Tessellator.getInstance();
|
|
|
|
VertexBuffer vertBuffer = tes.getBuffer();
|
2017-05-11 16:39:20 +02:00
|
|
|
float[][] colors = new float[steps + 1][];
|
2017-03-03 17:52:22 +01:00
|
|
|
vertBuffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR);
|
2017-02-26 13:56:36 +01:00
|
|
|
Vec3d last = Beziers.getPoint(0, controls);
|
2017-03-03 17:52:22 +01:00
|
|
|
colors[0] = getColor(0, salt, size);
|
2017-05-11 16:39:20 +02:00
|
|
|
for (int i = 1; i <= steps; i++) {
|
|
|
|
double d = i / (double) steps;
|
2017-03-03 17:52:22 +01:00
|
|
|
colors[i] = getColor(d, salt, size);
|
2017-02-26 13:56:36 +01:00
|
|
|
Vec3d pos = Beziers.getPoint(d, controls);
|
2017-05-11 16:39:20 +02:00
|
|
|
drawQuad(last, pos, radY, colors[i - 1], colors[i], vertBuffer);
|
|
|
|
drawQuad(last, pos, radZ, colors[i - 1], colors[i], vertBuffer);
|
2017-02-26 13:56:36 +01:00
|
|
|
last = pos;
|
|
|
|
}
|
|
|
|
tes.draw();
|
|
|
|
}
|
2017-05-11 16:39:20 +02:00
|
|
|
|
|
|
|
private final float[] saltColor = {1, 190 / 255F, 50 / 255F};
|
2017-03-03 17:52:22 +01:00
|
|
|
private final float[] airColor = {1, .85F, 1};
|
2017-05-11 16:39:20 +02:00
|
|
|
|
2017-03-03 17:52:22 +01:00
|
|
|
private float[] getColor(double t, double salt, LadderSize size) {
|
|
|
|
salt = Math.min(salt, 1);
|
|
|
|
int factor = 20;
|
|
|
|
double smallMin = Math.exp(-.5);
|
2017-05-11 16:39:20 +02:00
|
|
|
double normalMin = Math.exp(-.25 * factor);
|
|
|
|
double hugeMin = Math.exp(-.75 * factor);
|
2017-03-03 17:52:22 +01:00
|
|
|
double saltyness = 0;
|
2017-05-11 16:39:20 +02:00
|
|
|
double t2 = t - .5;
|
2017-03-03 17:52:22 +01:00
|
|
|
switch (size) {
|
|
|
|
case SMALL:
|
2017-05-11 16:39:20 +02:00
|
|
|
saltyness = salt * (1 - .9 * (Math.exp(-Math.abs(t2)) - smallMin));
|
2017-03-03 17:52:22 +01:00
|
|
|
break;
|
|
|
|
case NORMAL:
|
2017-05-11 16:39:20 +02:00
|
|
|
saltyness = salt * (1 - .9 * (Math.exp(-factor * t2 * t2) - normalMin));
|
2017-03-03 17:52:22 +01:00
|
|
|
break;
|
|
|
|
case HUGE:
|
2017-05-11 16:39:20 +02:00
|
|
|
saltyness = salt * (1 - .9 * (Math.exp(-Math.abs(factor * t2 * t2 * t2)) - hugeMin));
|
2017-03-03 17:52:22 +01:00
|
|
|
break;
|
|
|
|
}
|
2017-05-11 16:39:20 +02:00
|
|
|
return interpolate(saltyness, saltColor, 1 - saltyness, airColor);
|
2017-03-03 17:52:22 +01:00
|
|
|
}
|
2017-05-11 16:39:20 +02:00
|
|
|
|
2017-03-03 17:52:22 +01:00
|
|
|
private float[] interpolate(double a, float[] cA, double b, float[] cB) {
|
|
|
|
float[] ret = new float[cA.length];
|
2017-05-11 16:39:20 +02:00
|
|
|
for (int i = 0; i < ret.length; i++) {
|
|
|
|
ret[i] = (float) (a * cA[i] + b * cB[i]);
|
2017-03-03 17:52:22 +01:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
2017-02-26 13:56:36 +01:00
|
|
|
|
2017-03-03 17:52:22 +01:00
|
|
|
private void drawQuad(Vec3d v0, Vec3d v1, Vec3d rad, float[] color0, float[] color1, VertexBuffer vertexBuffer) {
|
|
|
|
color(color1, vertexBuffer.pos(v1.xCoord - rad.xCoord, v1.yCoord - rad.yCoord, v1.zCoord - rad.zCoord)).endVertex();
|
|
|
|
color(color0, vertexBuffer.pos(v0.xCoord - rad.xCoord, v0.yCoord - rad.yCoord, v0.zCoord - rad.zCoord)).endVertex();
|
|
|
|
color(color0, vertexBuffer.pos(v0.xCoord + rad.xCoord, v0.yCoord + rad.yCoord, v0.zCoord + rad.zCoord)).endVertex();
|
|
|
|
color(color1, vertexBuffer.pos(v1.xCoord + rad.xCoord, v1.yCoord + rad.yCoord, v1.zCoord + rad.zCoord)).endVertex();
|
2017-02-26 13:56:36 +01:00
|
|
|
|
2017-03-03 17:52:22 +01:00
|
|
|
color(color1, vertexBuffer.pos(v1.xCoord + rad.xCoord, v1.yCoord + rad.yCoord, v1.zCoord + rad.zCoord)).endVertex();
|
|
|
|
color(color0, vertexBuffer.pos(v0.xCoord + rad.xCoord, v0.yCoord + rad.yCoord, v0.zCoord + rad.zCoord)).endVertex();
|
|
|
|
color(color0, vertexBuffer.pos(v0.xCoord - rad.xCoord, v0.yCoord - rad.yCoord, v0.zCoord - rad.zCoord)).endVertex();
|
|
|
|
color(color1, vertexBuffer.pos(v1.xCoord - rad.xCoord, v1.yCoord - rad.yCoord, v1.zCoord - rad.zCoord)).endVertex();
|
|
|
|
}
|
2017-05-11 16:39:20 +02:00
|
|
|
|
2017-03-03 17:52:22 +01:00
|
|
|
private VertexBuffer color(float[] color, VertexBuffer vb) {
|
|
|
|
vb.color(color[0], color[1], color[2], 1);
|
|
|
|
return vb;
|
2017-02-26 13:56:36 +01:00
|
|
|
}
|
|
|
|
}
|