Added framework to the tesseract model along with changing the animation into a double rotation along the XY and YW rotation planes.

This commit is contained in:
Waterpicker 2018-02-05 13:31:58 -06:00
parent 926dfbe2a9
commit 773773f76d
4 changed files with 309 additions and 154 deletions

View file

@ -5,6 +5,7 @@ import com.flowpowered.math.vector.Vector3f;
import com.flowpowered.math.vector.Vector4f;
import org.dimdev.ddutils.RGBA;
import org.dimdev.dimdoors.DimDoors;
import org.dimdev.dimdoors.client.tesseract.Tesseract;
import org.dimdev.dimdoors.shared.tileentities.TileEntityFloatingRift;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.GlStateManager;
@ -20,127 +21,7 @@ import org.lwjgl.opengl.GL11;
public class TileEntityFloatingRiftRenderer extends TileEntitySpecialRenderer<TileEntityFloatingRift> {
private static final ResourceLocation tesseract_path = new ResourceLocation(DimDoors.MODID + ":textures/other/tesseract.png");
private static final Vector4f[] tesseract = {
new Vector4f(-0.5f,-0.5f,-0.5f,-0.5f),
new Vector4f(0.5f,-0.5f,-0.5f,-0.5f),
new Vector4f(0.5f,-0.5f,0.5f,-0.5f),
new Vector4f(-0.5f,-0.5f,0.5f,-0.5f),
new Vector4f(-0.5f,0.5f,-0.5f,-0.5f),
new Vector4f(0.5f,0.5f,-0.5f,-0.5f),
new Vector4f(0.5f,0.5f,0.5f,-0.5f),
new Vector4f(-0.5f,0.5f,0.5f,-0.5f),
new Vector4f(-0.5f,-0.5f,-0.5f,-0.5f),
new Vector4f(0.5f,-0.5f,-0.5f,-0.5f),
new Vector4f(0.5f,0.5f,-0.5f,-0.5f),
new Vector4f(-0.5f,0.5f,-0.5f,-0.5f),
new Vector4f(-0.5f,-0.5f,0.5f,-0.5f),
new Vector4f(0.5f,-0.5f,0.5f,-0.5f),
new Vector4f(0.5f,0.5f,0.5f,-0.5f),
new Vector4f(-0.5f,0.5f,0.5f,-0.5f),
new Vector4f(-0.5f,-0.5f,-0.5f,-0.5f),
new Vector4f(-0.5f,0.5f,-0.5f,-0.5f),
new Vector4f(-0.5f,0.5f,0.5f,-0.5f),
new Vector4f(-0.5f,-0.5f,0.5f,-0.5f),
new Vector4f(0.5f,-0.5f,-0.5f,-0.5f),
new Vector4f(0.5f,0.5f,-0.5f,-0.5f),
new Vector4f(0.5f,0.5f,0.5f,-0.5f),
new Vector4f(0.5f,-0.5f,0.5f,-0.5f),
new Vector4f(-0.5f,-0.5f,-0.5f,0.5f),
new Vector4f(0.5f,-0.5f,-0.5f,0.5f),
new Vector4f(0.5f,-0.5f,0.5f,0.5f),
new Vector4f(-0.5f,-0.5f,0.5f,0.5f),
new Vector4f(-0.5f,0.5f,-0.5f,0.5f),
new Vector4f(0.5f,0.5f,-0.5f,0.5f),
new Vector4f(0.5f,0.5f,0.5f,0.5f),
new Vector4f(-0.5f,0.5f,0.5f,0.5f),
new Vector4f(-0.5f,-0.5f,-0.5f,0.5f),
new Vector4f(0.5f,-0.5f,-0.5f,0.5f),
new Vector4f(0.5f,0.5f,-0.5f,0.5f),
new Vector4f(-0.5f,0.5f,-0.5f,0.5f),
new Vector4f(-0.5f,-0.5f,0.5f,0.5f),
new Vector4f(0.5f,-0.5f,0.5f,0.5f),
new Vector4f(0.5f,0.5f,0.5f,0.5f),
new Vector4f(-0.5f,0.5f,0.5f,0.5f),
new Vector4f(-0.5f,-0.5f,-0.5f,0.5f),
new Vector4f(-0.5f,0.5f,-0.5f,0.5f),
new Vector4f(-0.5f,0.5f,0.5f,0.5f),
new Vector4f(-0.5f,-0.5f,0.5f,0.5f),
new Vector4f(0.5f,-0.5f,-0.5f,0.5f),
new Vector4f(0.5f,0.5f,-0.5f,0.5f),
new Vector4f(0.5f,0.5f,0.5f,0.5f),
new Vector4f(0.5f,-0.5f,0.5f,0.5f),
new Vector4f(-0.5f,-0.5f,-0.5f,-0.5f),
new Vector4f(-0.5f,0.5f,-0.5f,-0.5f),
new Vector4f(-0.5f,0.5f,-0.5f,0.5f),
new Vector4f(-0.5f,-0.5f,-0.5f,0.5f),
new Vector4f(-0.5f,-0.5f,0.5f,-0.5f),
new Vector4f(-0.5f,0.5f,0.5f,-0.5f),
new Vector4f(-0.5f,0.5f,0.5f,0.5f),
new Vector4f(-0.5f,-0.5f,0.5f,0.5f),
new Vector4f(-0.5f,-0.5f,-0.5f,-0.5f),
new Vector4f(-0.5f,0.5f,-0.5f,-0.5f),
new Vector4f(-0.5f,0.5f,0.5f,-0.5f),
new Vector4f(-0.5f,-0.5f,0.5f,-0.5f),
new Vector4f(-0.5f,-0.5f,-0.5f,0.5f),
new Vector4f(-0.5f,0.5f,-0.5f,0.5f),
new Vector4f(-0.5f,0.5f,0.5f,0.5f),
new Vector4f(-0.5f,-0.5f,0.5f,0.5f),
new Vector4f(-0.5f,-0.5f,-0.5f,-0.5f),
new Vector4f(-0.5f,-0.5f,0.5f,-0.5f),
new Vector4f(-0.5f,-0.5f,0.5f,0.5f),
new Vector4f(-0.5f,-0.5f,-0.5f,0.5f),
new Vector4f(-0.5f,0.5f,-0.5f,-0.5f),
new Vector4f(-0.5f,0.5f,0.5f,-0.5f),
new Vector4f(-0.5f,0.5f,0.5f,0.5f),
new Vector4f(-0.5f,0.5f,-0.5f,0.5f),
new Vector4f(0.5f,-0.5f,-0.5f,-0.5f),
new Vector4f(0.5f,0.5f,-0.5f,-0.5f),
new Vector4f(0.5f,0.5f,-0.5f,0.5f),
new Vector4f(0.5f,-0.5f,-0.5f,0.5f),
new Vector4f(0.5f,-0.5f,0.5f,-0.5f),
new Vector4f(0.5f,0.5f,0.5f,-0.5f),
new Vector4f(0.5f,0.5f,0.5f,0.5f),
new Vector4f(0.5f,-0.5f,0.5f,0.5f),
new Vector4f(0.5f,-0.5f,-0.5f,-0.5f),
new Vector4f(0.5f,0.5f,-0.5f,-0.5f),
new Vector4f(0.5f,0.5f,0.5f,-0.5f),
new Vector4f(0.5f,-0.5f,0.5f,-0.5f),
new Vector4f(0.5f,-0.5f,-0.5f,0.5f),
new Vector4f(0.5f,0.5f,-0.5f,0.5f),
new Vector4f(0.5f,0.5f,0.5f,0.5f),
new Vector4f(0.5f,-0.5f,0.5f,0.5f),
new Vector4f(0.5f,-0.5f,-0.5f,-0.5f),
new Vector4f(0.5f,-0.5f,0.5f,-0.5f),
new Vector4f(0.5f,-0.5f,0.5f,0.5f),
new Vector4f(0.5f,-0.5f,-0.5f,0.5f),
new Vector4f(0.5f,0.5f,-0.5f,-0.5f),
new Vector4f(0.5f,0.5f,0.5f,-0.5f),
new Vector4f(0.5f,0.5f,0.5f,0.5f),
new Vector4f(0.5f,0.5f,-0.5f,0.5f)
};
private static final Tesseract tesseract = new Tesseract();
/**
* Renders the rift.
@ -161,18 +42,7 @@ public class TileEntityFloatingRiftRenderer extends TileEntitySpecialRenderer<Ti
GlStateManager.translate(x+0.5,y+0.5,z+0.5);
GlStateManager.scale(0.25,0.25,0.25);
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder worldRenderer = tessellator.getBuffer();
for (int i = 0; i < tesseract.length; i+=4) {
worldRenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR);
GlStateManager.color(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha());
project(worldRenderer, rotation(tesseract[i], radian),0,0, color);
project(worldRenderer, rotation(tesseract[i+1], radian),0,1, color);
project(worldRenderer, rotation(tesseract[i+2], radian),1,1, color);
project(worldRenderer, rotation(tesseract[i+3], radian),1,0, color);
tessellator.draw();
}
tesseract.draw(color, radian);
GlStateManager.disableBlend();
GlStateManager.enableCull();
@ -181,27 +51,7 @@ public class TileEntityFloatingRiftRenderer extends TileEntitySpecialRenderer<Ti
}
private double update(TileEntityFloatingRift te, float partialTicks) {
te.renderAngle = (te.renderAngle + 1 * partialTicks) % 360;
te.renderAngle = (te.renderAngle + 5 * partialTicks) % 360;
return te.renderAngle;
}
private Vector4f rotation(Vector4f v, double angle) {
double x = v.getX();
double y = v.getY();
double z = v.getZ();
double w = v.getW();
return new Vector4f(
x * TrigMath.cos(angle) - y * TrigMath.sin(angle),
x * TrigMath.sin(angle) + y * TrigMath.cos(angle),
z * TrigMath.cos(angle) - w * TrigMath.sin(angle),
z * TrigMath.sin(angle) + w * TrigMath.cos(angle));
}
private void project(BufferBuilder buffer, Vector4f vector, int u, int v, RGBA color) {
double scalar = 1d/(vector.getW()+1d);
Vector3f vector1 = vector.toVector3().mul(scalar);
buffer.pos(vector1.getX(), vector1.getY(), vector1.getZ()).tex(u,v).color(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha()).endVertex();
}
}

View file

@ -0,0 +1,26 @@
package org.dimdev.dimdoors.client.tesseract;
import com.flowpowered.math.vector.Vector4f;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.dimdev.ddutils.RGBA;
public class Cube {
Plane[] planes = new Plane[6];
public Cube(Vector4f first, Vector4f second, Vector4f third, Vector4f fourth, Vector4f fifth, Vector4f sixth, Vector4f seventh, Vector4f eighth) {
planes[0] = new Plane(first, second, third, fourth);
planes[1] = new Plane(fifth, sixth, seventh, eighth);
planes[2] = new Plane(first, third, fifth, seventh);
planes[3] = new Plane(third, fourth, seventh, eighth);
planes[4] = new Plane(second, fourth, sixth, eighth);
planes[5] = new Plane(first, second, fifth, sixth);
}
@SideOnly(Side.CLIENT)
public void draw(RGBA color, double radian) {
for(Plane plane : planes) {
plane.draw(color, radian);
}
}
}

View file

@ -0,0 +1,90 @@
package org.dimdev.dimdoors.client.tesseract;
import com.flowpowered.math.TrigMath;
import com.flowpowered.math.matrix.Matrix4d;
import com.flowpowered.math.matrix.Matrix4f;
import com.flowpowered.math.vector.Vector3d;
import com.flowpowered.math.vector.Vector3f;
import com.flowpowered.math.vector.Vector4d;
import com.flowpowered.math.vector.Vector4f;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.dimdev.ddutils.RGBA;
import org.lwjgl.opengl.GL11;
import static com.flowpowered.math.TrigMath.cos;
import static com.flowpowered.math.TrigMath.sin;
public class Plane {
Vector4f[] vectors;
public Plane(Vector4f first, Vector4f second, Vector4f third, Vector4f foruth) {
vectors = new Vector4f[] {first, second, third, foruth};
}
@SideOnly(Side.CLIENT)
public void draw(RGBA color, double radian) {
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder worldRenderer = tessellator.getBuffer();
worldRenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR);
GlStateManager.color(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha());
project(worldRenderer, rotYW(vectors[0], radian),0,0, color);
project(worldRenderer, rotYW(vectors[1], radian),0,1, color);
project(worldRenderer, rotYW(vectors[2], radian),1,1, color);
project(worldRenderer, rotYW(vectors[3], radian),1,0, color);
tessellator.draw();
}
private static Vector4f rotXW(Vector4f v, double angle) {
return Matrix4f.from(
cos(angle),0,0,sin(angle),
0,1,0,0,
0,0, 1, 0,
-sin(angle),0, 0,cos(angle))
.transform(v);
}
private static Vector4f rotZW(Vector4f v, double angle) {
return Matrix4f.from(
1,0,0,0,
0,1,0,0,
0,0,cos(angle),-sin(angle),
0,0,sin(angle),cos(angle))
.transform(v);
}
private static Vector4f rotYW(Vector4f v, double angle) {
return Matrix4f.from(
1,0,0,0,
0,cos(angle),0,sin(angle),
0,0,1,0,
0,-sin(angle),0,cos(angle))
.transform(v);
}
private static Vector4f rotXY(Vector4f v, double angle) {
return Matrix4f.from(
cos(angle),-sin(angle),0,0,
sin(angle),cos(angle),0,0,
0,0,1,0,
0,0,0,1)
.transform(v);
}
@SideOnly(Side.CLIENT)
private static void project(BufferBuilder buffer, Vector4f vector, int u, int v, RGBA color) {
double scalar = 1d/(vector.getW()+1);
Vector3f vector1 = vector.toVector3().mul(scalar);
buffer.pos(vector1.getX(), vector1.getY(), vector1.getZ()).tex(u,v).color(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha()).endVertex();
}
}

View file

@ -0,0 +1,189 @@
package org.dimdev.dimdoors.client.tesseract;
import com.flowpowered.math.vector.Vector4f;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.dimdev.ddutils.RGBA;
public class Tesseract {
private Plane[] planes;
public Tesseract() {
planes = new Plane[24];
planes[0] = new Plane(
new Vector4f(-0.5f,-0.5f,-0.5f,-0.5f),
new Vector4f(0.5f,-0.5f,-0.5f,-0.5f),
new Vector4f(0.5f,-0.5f,0.5f,-0.5f),
new Vector4f(-0.5f,-0.5f,0.5f,-0.5f)
);
planes[1] = new Plane(
new Vector4f(-0.5f,0.5f,-0.5f,-0.5f),
new Vector4f(0.5f,0.5f,-0.5f,-0.5f),
new Vector4f(0.5f,0.5f,0.5f,-0.5f),
new Vector4f(-0.5f,0.5f,0.5f,-0.5f)
);
planes[2] = new Plane(
new Vector4f(-0.5f,-0.5f,-0.5f,-0.5f),
new Vector4f(0.5f,-0.5f,-0.5f,-0.5f),
new Vector4f(0.5f,0.5f,-0.5f,-0.5f),
new Vector4f(-0.5f,0.5f,-0.5f,-0.5f)
);
planes[3] = new Plane(
new Vector4f(-0.5f,-0.5f,0.5f,-0.5f),
new Vector4f(0.5f,-0.5f,0.5f,-0.5f),
new Vector4f(0.5f,0.5f,0.5f,-0.5f),
new Vector4f(-0.5f,0.5f,0.5f,-0.5f)
);
planes[4] = new Plane(
new Vector4f(-0.5f,-0.5f,-0.5f,-0.5f),
new Vector4f(-0.5f,0.5f,-0.5f,-0.5f),
new Vector4f(-0.5f,0.5f,0.5f,-0.5f),
new Vector4f(-0.5f,-0.5f,0.5f,-0.5f)
);
planes[5] = new Plane(
new Vector4f(0.5f,-0.5f,-0.5f,-0.5f),
new Vector4f(0.5f,0.5f,-0.5f,-0.5f),
new Vector4f(0.5f,0.5f,0.5f,-0.5f),
new Vector4f(0.5f,-0.5f,0.5f,-0.5f)
);
planes[6] = new Plane(
new Vector4f(-0.5f,-0.5f,-0.5f,0.5f),
new Vector4f(0.5f,-0.5f,-0.5f,0.5f),
new Vector4f(0.5f,-0.5f,0.5f,0.5f),
new Vector4f(-0.5f,-0.5f,0.5f,0.5f)
);
planes[7] = new Plane(
new Vector4f(-0.5f,0.5f,-0.5f,0.5f),
new Vector4f(0.5f,0.5f,-0.5f,0.5f),
new Vector4f(0.5f,0.5f,0.5f,0.5f),
new Vector4f(-0.5f,0.5f,0.5f,0.5f)
);
planes[8] = new Plane(
new Vector4f(-0.5f,-0.5f,-0.5f,0.5f),
new Vector4f(0.5f,-0.5f,-0.5f,0.5f),
new Vector4f(0.5f,0.5f,-0.5f,0.5f),
new Vector4f(-0.5f,0.5f,-0.5f,0.5f)
);
planes[9] = new Plane(
new Vector4f(-0.5f,-0.5f,0.5f,0.5f),
new Vector4f(0.5f,-0.5f,0.5f,0.5f),
new Vector4f(0.5f,0.5f,0.5f,0.5f),
new Vector4f(-0.5f,0.5f,0.5f,0.5f)
);
planes[10] = new Plane(
new Vector4f(-0.5f,-0.5f,-0.5f,0.5f),
new Vector4f(-0.5f,0.5f,-0.5f,0.5f),
new Vector4f(-0.5f,0.5f,0.5f,0.5f),
new Vector4f(-0.5f,-0.5f,0.5f,0.5f)
);
planes[11] = new Plane(
new Vector4f(0.5f,-0.5f,-0.5f,0.5f),
new Vector4f(0.5f,0.5f,-0.5f,0.5f),
new Vector4f(0.5f,0.5f,0.5f,0.5f),
new Vector4f(0.5f,-0.5f,0.5f,0.5f)
);
planes[12] = new Plane(
new Vector4f(-0.5f,-0.5f,-0.5f,-0.5f),
new Vector4f(-0.5f,0.5f,-0.5f,-0.5f),
new Vector4f(-0.5f,0.5f,-0.5f,0.5f),
new Vector4f(-0.5f,-0.5f,-0.5f,0.5f)
);
planes[13] = new Plane(
new Vector4f(-0.5f,-0.5f,0.5f,-0.5f),
new Vector4f(-0.5f,0.5f,0.5f,-0.5f),
new Vector4f(-0.5f,0.5f,0.5f,0.5f),
new Vector4f(-0.5f,-0.5f,0.5f,0.5f)
);
planes[14] = new Plane(
new Vector4f(-0.5f,-0.5f,-0.5f,-0.5f),
new Vector4f(-0.5f,0.5f,-0.5f,-0.5f),
new Vector4f(-0.5f,0.5f,0.5f,-0.5f),
new Vector4f(-0.5f,-0.5f,0.5f,-0.5f)
);
planes[15] = new Plane(
new Vector4f(-0.5f,-0.5f,-0.5f,0.5f),
new Vector4f(-0.5f,0.5f,-0.5f,0.5f),
new Vector4f(-0.5f,0.5f,0.5f,0.5f),
new Vector4f(-0.5f,-0.5f,0.5f,0.5f)
);
planes[16] = new Plane(
new Vector4f(-0.5f,-0.5f,-0.5f,-0.5f),
new Vector4f(-0.5f,-0.5f,0.5f,-0.5f),
new Vector4f(-0.5f,-0.5f,0.5f,0.5f),
new Vector4f(-0.5f,-0.5f,-0.5f,0.5f)
);
planes[17] = new Plane(
new Vector4f(-0.5f,0.5f,-0.5f,-0.5f),
new Vector4f(-0.5f,0.5f,0.5f,-0.5f),
new Vector4f(-0.5f,0.5f,0.5f,0.5f),
new Vector4f(-0.5f,0.5f,-0.5f,0.5f)
);
planes[18] = new Plane(
new Vector4f(0.5f,-0.5f,-0.5f,-0.5f),
new Vector4f(0.5f,0.5f,-0.5f,-0.5f),
new Vector4f(0.5f,0.5f,-0.5f,0.5f),
new Vector4f(0.5f,-0.5f,-0.5f,0.5f)
);
planes[19] = new Plane(
new Vector4f(0.5f,-0.5f,0.5f,-0.5f),
new Vector4f(0.5f,0.5f,0.5f,-0.5f),
new Vector4f(0.5f,0.5f,0.5f,0.5f),
new Vector4f(0.5f,-0.5f,0.5f,0.5f)
);
planes[20] = new Plane(
new Vector4f(0.5f,-0.5f,-0.5f,-0.5f),
new Vector4f(0.5f,0.5f,-0.5f,-0.5f),
new Vector4f(0.5f,0.5f,0.5f,-0.5f),
new Vector4f(0.5f,-0.5f,0.5f,-0.5f)
);
planes[21] = new Plane(
new Vector4f(0.5f,-0.5f,-0.5f,0.5f),
new Vector4f(0.5f,0.5f,-0.5f,0.5f),
new Vector4f(0.5f,0.5f,0.5f,0.5f),
new Vector4f(0.5f,-0.5f,0.5f,0.5f)
);
planes[22] = new Plane(
new Vector4f(0.5f,-0.5f,-0.5f,-0.5f),
new Vector4f(0.5f,-0.5f,0.5f,-0.5f),
new Vector4f(0.5f,-0.5f,0.5f,0.5f),
new Vector4f(0.5f,-0.5f,-0.5f,0.5f)
);
planes[23] = new Plane(
new Vector4f(0.5f,0.5f,-0.5f,-0.5f),
new Vector4f(0.5f,0.5f,0.5f,-0.5f),
new Vector4f(0.5f,0.5f,0.5f,0.5f),
new Vector4f(0.5f,0.5f,-0.5f,0.5f)
);
}
@SideOnly(Side.CLIENT)
public void draw(RGBA color, double radian) {
for (Plane plane : planes) {
plane.draw(color, radian);
}
}
}