Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class BasicShape {
- public Vector3 shapeSize;
- public Vector3 shapePosition;
- private VertexPositionTexture[][] shapeVertices;
- private int shapeTriangles;
- private VertexBuffer shapeBuffer;
- //public Texture2D topTexture;
- //public Texture2D frontTexture;
- //public Texture2D backTexture;
- //public Texture2D leftTexture;
- //public Texture2D rightTexture;
- //public Texture2D bottomTexture;
- public int topTexture;
- public int frontTexture;
- public int backTexture;
- public int leftTexture;
- public int rightTexture;
- public int bottomTexture;
- public BasicShape(Vector3 size, Vector3 position) {
- shapeSize = size;
- shapePosition = position;
- }
- private void BuildShape() {
- shapeTriangles = 12;
- shapeVertices = new VertexPositionTexture[6][];
- for(int i = 0; i < 6; i++) {
- shapeVertices[i] = new VertexPositionTexture[6];
- }
- Vector3 topLeftFront = shapePosition +
- new Vector3(0.0f, 1.0f, 0.0f) * shapeSize;
- Vector3 bottomLeftFront = shapePosition +
- new Vector3(0.0f, 0.0f, 0.0f) * shapeSize;
- Vector3 topRightFront = shapePosition +
- new Vector3(1.0f, 1.0f, 0.0f) * shapeSize;
- Vector3 bottomRightFront = shapePosition +
- new Vector3(1.0f, 0.0f, 0.0f) * shapeSize;
- Vector3 topLeftBack = shapePosition +
- new Vector3(0.0f, 1.0f, 1.0f) * shapeSize;
- Vector3 topRightBack = shapePosition +
- new Vector3(1.0f, 1.0f, 1.0f) * shapeSize;
- Vector3 bottomLeftBack = shapePosition +
- new Vector3(0.0f, 0.0f, 1.0f) * shapeSize;
- Vector3 bottomRightBack = shapePosition +
- new Vector3(1.0f, 0.0f, 1.0f) * shapeSize;
- Vector3 topLeftFront2 = shapePosition +
- new Vector3(0.0f, 1.0f, 0.0f) * shapeSize;
- Vector3 bottomLeftFront2 = shapePosition +
- new Vector3(0.0f, 0.0f, 0.0f) * shapeSize;
- Vector3 topRightFront2 = shapePosition +
- new Vector3(1.0f, 1.0f, 0.0f) * shapeSize;
- Vector3 bottomRightFront2 = shapePosition +
- new Vector3(1.0f, 0.0f, 0.0f) * shapeSize;
- Vector3 topLeftBack2 = shapePosition +
- new Vector3(0.0f, 1.0f, 1.0f) * shapeSize;
- Vector3 topRightBack2 = shapePosition +
- new Vector3(1.0f, 1.0f, 1.0f) * shapeSize;
- Vector3 bottomLeftBack2 = shapePosition +
- new Vector3(0.0f, 0.0f, 1.0f) * shapeSize;
- Vector3 bottomRightBack2 = shapePosition +
- new Vector3(1.0f, 0.0f, 1.0f) * shapeSize;
- Vector3 topLeftFront3 = shapePosition +
- new Vector3(0.0f, 1.0f, 0.0f) * shapeSize;
- Vector3 bottomLeftFront3 = shapePosition +
- new Vector3(0.0f, 0.0f, 0.0f) * shapeSize;
- Vector3 topRightFront3 = shapePosition +
- new Vector3(1.0f, 1.0f, 0.0f) * shapeSize;
- Vector3 bottomRightFront3 = shapePosition +
- new Vector3(1.0f, 0.0f, 0.0f) * shapeSize;
- Vector3 topLeftBack3 = shapePosition +
- new Vector3(0.0f, 1.0f, 1.0f) * shapeSize;
- Vector3 topRightBack3 = shapePosition +
- new Vector3(1.0f, 1.0f, 1.0f) * shapeSize;
- Vector3 bottomLeftBack3 = shapePosition +
- new Vector3(0.0f, 0.0f, 1.0f) * shapeSize;
- Vector3 bottomRightBack3 = shapePosition +
- new Vector3(1.0f, 0.0f, 1.0f) * shapeSize;
- float tileSizeX = 1 / 16.0f;
- float tileSizeY = 1 / 16.0f;
- Vector2 textureTopLeft = new Vector2(frontTexture % 16 * tileSizeX, frontTexture / 16 * tileSizeY);
- Vector2 textureTopRight = new Vector2((frontTexture % 16 + 1) * tileSizeX, frontTexture / 16 * tileSizeY);
- Vector2 textureBottomLeft = new Vector2(frontTexture % 16 * tileSizeX, (frontTexture / 16 + 1) * tileSizeY);
- Vector2 textureBottomRight = new Vector2((frontTexture % 16 + 1) * tileSizeX, (frontTexture / 16 + 1) * tileSizeY);
- Vector2 textureTopLeft2 = new Vector2(backTexture % 16 * tileSizeX, backTexture / 16 * tileSizeY);
- Vector2 textureTopRight2 = new Vector2((backTexture % 16 + 1) * tileSizeX, backTexture / 16 * tileSizeY);
- Vector2 textureBottomLeft2 = new Vector2(backTexture % 16 * tileSizeX, (backTexture / 16 + 1) * tileSizeY);
- Vector2 textureBottomRight2 = new Vector2((backTexture % 16 + 1) * tileSizeX, (backTexture / 16 + 1) * tileSizeY);
- Vector2 textureTopLeft3 = new Vector2(topTexture % 16 * tileSizeX, topTexture / 16 * tileSizeY);
- Vector2 textureTopRight3 = new Vector2((topTexture % 16 + 1) * tileSizeX, topTexture / 16 * tileSizeY);
- Vector2 textureBottomLeft3 = new Vector2(topTexture % 16 * tileSizeX, (topTexture / 16 + 1) * tileSizeY);
- Vector2 textureBottomRight3 = new Vector2((topTexture % 16 + 1) * tileSizeX, (topTexture / 16 + 1) * tileSizeY);
- Vector2 textureTopLeft4 = new Vector2(bottomTexture % 16 * tileSizeX, bottomTexture / 16 * tileSizeY);
- Vector2 textureTopRight4 = new Vector2((bottomTexture % 16 + 1) * tileSizeX, bottomTexture / 16 * tileSizeY);
- Vector2 textureBottomLeft4 = new Vector2(bottomTexture % 16 * tileSizeX, (bottomTexture / 16 + 1) * tileSizeY);
- Vector2 textureBottomRight4 = new Vector2((bottomTexture % 16 + 1) * tileSizeX, (bottomTexture / 16 + 1) * tileSizeY);
- Vector2 textureTopLeft5 = new Vector2(leftTexture % 16 * tileSizeX, leftTexture / 16 * tileSizeY);
- Vector2 textureTopRight5 = new Vector2((leftTexture % 16 + 1) * tileSizeX, leftTexture / 16 * tileSizeY);
- Vector2 textureBottomLeft5 = new Vector2(leftTexture % 16 * tileSizeX, (leftTexture / 16 + 1) * tileSizeY);
- Vector2 textureBottomRight5 = new Vector2((leftTexture % 16 + 1) * tileSizeX, (leftTexture / 16 + 1) * tileSizeY);
- Vector2 textureTopLeft6 = new Vector2(rightTexture % 16 * tileSizeX, rightTexture / 16 * tileSizeY);
- Vector2 textureTopRight6 = new Vector2((rightTexture % 16 + 1) * tileSizeX, rightTexture / 16 * tileSizeY);
- Vector2 textureBottomLeft6 = new Vector2(rightTexture % 16 * tileSizeX, (rightTexture / 16 + 1) * tileSizeY);
- Vector2 textureBottomRight6 = new Vector2((rightTexture % 16 + 1) * tileSizeX, (rightTexture / 16 + 1) * tileSizeY);
- // Front face.
- shapeVertices[0][0] = new VertexPositionTexture(
- topLeftFront, textureTopLeft);
- shapeVertices[0][1] = new VertexPositionTexture(
- bottomLeftFront, textureBottomLeft);
- shapeVertices[0][2] = new VertexPositionTexture(
- topRightFront, textureTopRight);
- shapeVertices[0][3] = new VertexPositionTexture(
- bottomLeftFront, textureBottomLeft);
- shapeVertices[0][4] = new VertexPositionTexture(
- bottomRightFront, textureBottomRight);
- shapeVertices[0][5] = new VertexPositionTexture(
- topRightFront, textureTopRight);
- // Back face.
- shapeVertices[1][0] = new VertexPositionTexture(
- topLeftBack, textureTopRight2);
- shapeVertices[1][1] = new VertexPositionTexture(
- topRightBack, textureTopLeft2);
- shapeVertices[1][2] = new VertexPositionTexture(
- bottomLeftBack, textureBottomRight2);
- shapeVertices[1][3] = new VertexPositionTexture(
- bottomLeftBack,textureBottomRight2);
- shapeVertices[1][4] = new VertexPositionTexture(
- topRightBack, textureTopLeft2);
- shapeVertices[1][5] = new VertexPositionTexture(
- bottomRightBack, textureBottomLeft2);
- // Top face.
- shapeVertices[2][0] = new VertexPositionTexture(
- topLeftFront2, textureBottomLeft3);
- shapeVertices[2][1] = new VertexPositionTexture(
- topRightBack2, textureTopRight3);
- shapeVertices[2][2] = new VertexPositionTexture(
- topLeftBack2, textureTopLeft3);
- shapeVertices[2][3] = new VertexPositionTexture(
- topLeftFront2, textureBottomLeft3);
- shapeVertices[2][4] = new VertexPositionTexture(
- topRightFront2, textureBottomRight3);
- shapeVertices[2][5] = new VertexPositionTexture(
- topRightBack2, textureTopRight3);
- // Bottom face.
- shapeVertices[3][0] = new VertexPositionTexture(
- bottomLeftFront2, textureTopLeft4);
- shapeVertices[3][1] = new VertexPositionTexture(
- bottomLeftBack2, textureBottomLeft4);
- shapeVertices[3][2] = new VertexPositionTexture(
- bottomRightBack2, textureBottomRight4);
- shapeVertices[3][3] = new VertexPositionTexture(
- bottomLeftFront2, textureTopLeft4);
- shapeVertices[3][4] = new VertexPositionTexture(
- bottomRightBack2, textureBottomRight4);
- shapeVertices[3][5] = new VertexPositionTexture(
- bottomRightFront2, textureTopRight4);
- // Left face.
- shapeVertices[4][0] = new VertexPositionTexture(
- topLeftFront3, textureTopRight5);
- shapeVertices[4][1] = new VertexPositionTexture(
- bottomLeftBack3, textureBottomLeft5);
- shapeVertices[4][2] = new VertexPositionTexture(
- bottomLeftFront3, textureBottomRight5);
- shapeVertices[4][3] = new VertexPositionTexture(
- topLeftBack3, textureTopLeft5);
- shapeVertices[4][4] = new VertexPositionTexture(
- bottomLeftBack3, textureBottomLeft5);
- shapeVertices[4][5] = new VertexPositionTexture(
- topLeftFront3, textureTopRight5);
- // Right face.
- shapeVertices[5][0] = new VertexPositionTexture(
- topRightFront3, textureTopLeft6);
- shapeVertices[5][1] = new VertexPositionTexture(
- bottomRightFront3, textureBottomLeft6);
- shapeVertices[5][2] = new VertexPositionTexture(
- bottomRightBack3, textureBottomRight6);
- shapeVertices[5][3] = new VertexPositionTexture(
- topRightBack3, textureTopRight6);
- shapeVertices[5][4] = new VertexPositionTexture(
- topRightFront3, textureTopLeft6);
- shapeVertices[5][5] = new VertexPositionTexture(
- bottomRightBack3, textureBottomRight6);
- }
- public void SetTopTexture(int tex) {
- topTexture = tex;
- }
- public void SetSideTexture(int tex) {
- frontTexture = tex;
- backTexture = tex;
- leftTexture = tex;
- rightTexture = tex;
- }
- public void SetBottomTexture(int tex) {
- bottomTexture = tex;
- }
- public void RenderShape(GraphicsDevice device, Effect effect) {
- BuildShape();
- AddVertices(topTexture, shapeVertices[2]);
- AddVertices(bottomTexture, shapeVertices[3]);
- AddVertices(frontTexture, shapeVertices[0]);
- AddVertices(backTexture, shapeVertices[1]);
- AddVertices(leftTexture, shapeVertices[4]);
- AddVertices(rightTexture, shapeVertices[5]);
- }
- private void AddVertices(int texnum, VertexPositionTexture[] vertices) {
- if(!MinecraftGame.CurrentGame.vertexlist.ContainsKey(texnum)) {
- MinecraftGame.CurrentGame.vertexlist.Add(texnum, new List<VertexPositionTexture>(1024));
- MinecraftGame.CurrentGame.indexlist.Add(texnum, new List<int>(1024));
- }
- List<VertexPositionTexture> vertlist = MinecraftGame.CurrentGame.vertexlist[texnum];
- List<int> indexlist = MinecraftGame.CurrentGame.indexlist[texnum];
- //int[] pending = new int[6];
- //for(int i = 0; i < vertices.Length; i++) {
- // pending[i] = -1;
- // for(int j = 0; j < vertlist.Count; j++) {
- // if(vertlist[j].Position == vertices[i].Position && vertlist[j].TextureCoordinate == vertices[i].TextureCoordinate) {
- // pending[i] = j;
- // break;
- // }
- // }
- //}
- for(int i = 0, j = vertlist.Count; i < vertices.Length; i++, j++) {
- //if(pending[i] == -1) {
- vertlist.Add(vertices[i]);
- indexlist.Add(j);
- //}
- //else {
- // indexlist.Add(pending[i]);
- //}
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement