| 1 | package net.minecraft.client.model;
|
| 2 |
|
| 3 | import net.minecraft.client.renderer.Tessellator;
|
| 4 | import net.minecraft.client.renderer.WorldRenderer;
|
| 5 | import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
| 6 | import net.minecraft.util.Vec3;
|
| 7 |
|
| 8 | public class TexturedQuad
|
| 9 | {
|
| 10 | public PositionTextureVertex[] vertexPositions;
|
| 11 | public int nVertices;
|
| 12 | private boolean invertNormal;
|
| 13 |
|
| 14 | public TexturedQuad(PositionTextureVertex[] vertices)
|
| 15 | {
|
| 16 | this.vertexPositions = vertices;
|
| 17 | this.nVertices = vertices.length;
|
| 18 | }
|
| 19 |
|
| 20 | public TexturedQuad(PositionTextureVertex[] vertices, int texcoordU1, int texcoordV1, int texcoordU2, int texcoordV2, float textureWidth, float textureHeight)
|
| 21 | {
|
| 22 | this(vertices);
|
| 23 | float f = 0.0F / textureWidth;
|
| 24 | float f1 = 0.0F / textureHeight;
|
| 25 | vertices[0] = vertices[0].setTexturePosition((float)texcoordU2 / textureWidth - f, (float)texcoordV1 / textureHeight + f1);
|
| 26 | vertices[1] = vertices[1].setTexturePosition((float)texcoordU1 / textureWidth + f, (float)texcoordV1 / textureHeight + f1);
|
| 27 | vertices[2] = vertices[2].setTexturePosition((float)texcoordU1 / textureWidth + f, (float)texcoordV2 / textureHeight - f1);
|
| 28 | vertices[3] = vertices[3].setTexturePosition((float)texcoordU2 / textureWidth - f, (float)texcoordV2 / textureHeight - f1);
|
| 29 | }
|
| 30 |
|
| 31 | public void flipFace()
|
| 32 | {
|
| 33 | PositionTextureVertex[] apositiontexturevertex = new PositionTextureVertex[this.vertexPositions.length];
|
| 34 |
|
| 35 | for (int i = 0; i < this.vertexPositions.length; ++i)
|
| 36 | {
|
| 37 | apositiontexturevertex[i] = this.vertexPositions[this.vertexPositions.length - i - 1];
|
| 38 | }
|
| 39 |
|
| 40 | this.vertexPositions = apositiontexturevertex;
|
| 41 | }
|
| 42 |
|
| 43 | /**
|
| 44 | * Draw this primitve. This is typically called only once as the generated drawing instructions are saved by the
|
| 45 | * renderer and reused later.
|
| 46 | */
|
| 47 | public void draw(WorldRenderer renderer, float scale)
|
| 48 | {
|
| 49 | Vec3 vec3 = this.vertexPositions[1].vector3D.subtractReverse(this.vertexPositions[0].vector3D);
|
| 50 | Vec3 vec31 = this.vertexPositions[1].vector3D.subtractReverse(this.vertexPositions[2].vector3D);
|
| 51 | Vec3 vec32 = vec31.crossProduct(vec3).normalize();
|
| 52 | float f = (float)vec32.xCoord;
|
| 53 | float f1 = (float)vec32.yCoord;
|
| 54 | float f2 = (float)vec32.zCoord;
|
| 55 |
|
| 56 | if (this.invertNormal)
|
| 57 | {
|
| 58 | f = -f;
|
| 59 | f1 = -f1;
|
| 60 | f2 = -f2;
|
| 61 | }
|
| 62 |
|
| 63 | renderer.begin(7, DefaultVertexFormats.OLDMODEL_POSITION_TEX_NORMAL);
|
| 64 |
|
| 65 | for (int i = 0; i < 4; ++i)
|
| 66 | {
|
| 67 | PositionTextureVertex positiontexturevertex = this.vertexPositions[i];
|
| 68 | renderer.pos(positiontexturevertex.vector3D.xCoord * (double)scale, positiontexturevertex.vector3D.yCoord * (double)scale, positiontexturevertex.vector3D.zCoord * (double)scale).tex((double)positiontexturevertex.texturePositionX, (double)positiontexturevertex.texturePositionY).normal(f, f1, f2).endVertex();
|
| 69 | }
|
| 70 |
|
| 71 | Tessellator.getInstance().draw();
|
| 72 | }
|
| 73 | }
|
| 74 |
|