-
Notifications
You must be signed in to change notification settings - Fork 497
/
ModelFrustum.java
128 lines (103 loc) · 5.72 KB
/
ModelFrustum.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package buildcraft.factory.render;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.client.model.PositionTextureVertex;
import net.minecraft.client.model.TexturedQuad;
import net.minecraft.client.renderer.Tessellator;
public class ModelFrustum {
/**
* The (x,y,z) vertex positions and (u,v) texture coordinates for each of the 8 points on a cube
*/
private PositionTextureVertex[] vertexPositions;
/** An array of 6 TexturedQuads, one for each face of a cube */
private TexturedQuad[] quadList;
/** X vertex coordinate of lower box corner */
public final float posX1;
/** Y vertex coordinate of lower box corner */
public final float posY1;
/** Z vertex coordinate of lower box corner */
public final float posZ1;
/** X vertex coordinate of upper box corner */
public final float posX2;
/** Y vertex coordinate of upper box corner */
public final float posY2;
/** Z vertex coordinate of upper box corner */
public final float posZ2;
public String field_40673_g;
public ModelFrustum(ModelRenderer par1ModelRenderer, int textureOffsetX, int textureOffsetY, float originX, float originY, float originZ, int bottomWidth,
int bottomDepth, int topWidth, int topDepth, int height, float scaleFactor) {
this.posX1 = originX;
this.posY1 = originY;
this.posZ1 = originZ;
this.vertexPositions = new PositionTextureVertex[8];
this.quadList = new TexturedQuad[6];
float bottomDeltaX = bottomWidth > topWidth ? 0 : (topWidth - bottomWidth) / 2f;
float topDeltaX = bottomWidth > topWidth ? (bottomWidth - topWidth) / 2f : 0;
float bottomDeltaZ = bottomDepth > topDepth ? 0 : (topDepth - bottomDepth) / 2f;
float topDeltaZ = bottomDepth > topDepth ? (bottomDepth - topDepth) / 2f : 0;
float targetX = originX + Math.max((float) bottomWidth, (float) topWidth);
float targetY = originY + height;
float targetZ = originZ + Math.max((float) bottomDepth, (float) topDepth);
this.posX2 = targetX;
this.posY2 = targetY;
this.posZ2 = targetZ;
originX -= scaleFactor;
originY -= scaleFactor;
originZ -= scaleFactor;
targetX += scaleFactor;
targetY += scaleFactor;
targetZ += scaleFactor;
if (par1ModelRenderer.mirror) {
float var14 = targetX;
targetX = originX;
originX = var14;
}
PositionTextureVertex var23 = new PositionTextureVertex(originX + bottomDeltaX, originY, originZ + bottomDeltaZ, 0.0F, 0.0F);
PositionTextureVertex var15 = new PositionTextureVertex(targetX - bottomDeltaX, originY, originZ + bottomDeltaZ, 0.0F, 8.0F);
PositionTextureVertex var16 = new PositionTextureVertex(targetX - topDeltaX, targetY, originZ + topDeltaZ, 8.0F, 8.0F);
PositionTextureVertex var17 = new PositionTextureVertex(originX + topDeltaX, targetY, originZ + topDeltaZ, 8.0F, 0.0F);
PositionTextureVertex var18 = new PositionTextureVertex(originX + bottomDeltaX, originY, targetZ - bottomDeltaZ, 0.0F, 0.0F);
PositionTextureVertex var19 = new PositionTextureVertex(targetX - bottomDeltaX, originY, targetZ - bottomDeltaZ, 0.0F, 8.0F);
PositionTextureVertex var20 = new PositionTextureVertex(targetX - topDeltaX, targetY, targetZ - topDeltaZ, 8.0F, 8.0F);
PositionTextureVertex var21 = new PositionTextureVertex(originX + topDeltaX, targetY, targetZ - topDeltaZ, 8.0F, 0.0F);
this.vertexPositions[0] = var23;
this.vertexPositions[1] = var15;
this.vertexPositions[2] = var16;
this.vertexPositions[3] = var17;
this.vertexPositions[4] = var18;
this.vertexPositions[5] = var19;
this.vertexPositions[6] = var20;
this.vertexPositions[7] = var21;
int depth = Math.max(bottomDepth, topDepth);
int width = Math.max(bottomWidth, topWidth);
this.quadList[0] = new TexturedQuad(new PositionTextureVertex[] { var19, var15, var16, var20 }, textureOffsetX + depth + width, textureOffsetY + depth,
textureOffsetX + depth + width + depth, textureOffsetY + depth + height, par1ModelRenderer.textureWidth, par1ModelRenderer.textureHeight);
this.quadList[1] = new TexturedQuad(new PositionTextureVertex[] { var23, var18, var21, var17 }, textureOffsetX, textureOffsetY + depth, textureOffsetX
+ depth, textureOffsetY + depth + height, par1ModelRenderer.textureWidth, par1ModelRenderer.textureHeight);
this.quadList[2] = new TexturedQuad(new PositionTextureVertex[] { var19, var18, var23, var15 }, textureOffsetX + depth, textureOffsetY, textureOffsetX
+ depth + width, textureOffsetY + depth, par1ModelRenderer.textureWidth, par1ModelRenderer.textureHeight);
this.quadList[3] = new TexturedQuad(new PositionTextureVertex[] { var16, var17, var21, var20 }, textureOffsetX + depth + width, textureOffsetY + depth,
textureOffsetX + depth + width + width, textureOffsetY, par1ModelRenderer.textureWidth, par1ModelRenderer.textureHeight);
this.quadList[4] = new TexturedQuad(new PositionTextureVertex[] { var15, var23, var17, var16 }, textureOffsetX + depth, textureOffsetY + depth,
textureOffsetX + depth + width, textureOffsetY + depth + height, par1ModelRenderer.textureWidth, par1ModelRenderer.textureHeight);
this.quadList[5] = new TexturedQuad(new PositionTextureVertex[] { var18, var19, var20, var21 }, textureOffsetX + depth + width + depth, textureOffsetY
+ depth, textureOffsetX + depth + width + depth + width, textureOffsetY + depth + height, par1ModelRenderer.textureWidth,
par1ModelRenderer.textureHeight);
if (par1ModelRenderer.mirror) {
for (int var22 = 0; var22 < this.quadList.length; ++var22) {
this.quadList[var22].flipFace();
}
}
}
/**
* Draw the six sided box defined by this ModelBox
*/
public void render(Tessellator par1Tessellator, float par2) {
for (int var3 = 0; var3 < this.quadList.length; ++var3) {
this.quadList[var3].draw(par1Tessellator, par2);
}
}
public ModelFrustum func_40671_a(String par1Str) {
this.field_40673_g = par1Str;
return this;
}
}