Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Cube()
- {
- vertices = new VertexPositionNormalTexture[24];
- indices = new int[36];
- Vector3 size = new Vector3(3, 3, 3);
- //Corner points
- Vector3 topLeftFront = new Vector3(-1, 1, 1) * size;
- Vector3 topRightFront = new Vector3(1, 1, 1) * size;
- Vector3 bottomLeftFront = new Vector3(-1, -1, 1) * size;
- Vector3 bottomRightFront = new Vector3(1, -1, 1) * size;
- Vector3 topLeftBack = new Vector3(-1, 1, -1) * size;
- Vector3 topRightBack = new Vector3(1, 1, -1) * size;
- Vector3 bottomLeftBack = new Vector3(-1, -1, -1) * size;
- Vector3 bottomRightBack = new Vector3(1, -1, -1) * size;
- //Front face
- Vector3 normal = new Vector3(0, 0, 1);
- vertices[0] = new VertexPositionNormalTexture(bottomLeftFront, normal, new Vector2(0, 1));
- vertices[1] = new VertexPositionNormalTexture(bottomRightFront, normal, new Vector2(1 / 3f, 1));
- vertices[2] = new VertexPositionNormalTexture(topRightFront, normal, new Vector2(1 / 3f, 0));
- vertices[3] = new VertexPositionNormalTexture(topLeftFront, normal, new Vector2(0, 0));
- int offset = 0;
- indices[0] = 3 + offset;
- indices[1] = 2 + offset;
- indices[2] = 0 + offset;
- indices[3] = 2 + offset;
- indices[4] = 1 + offset;
- indices[5] = 0 + offset;
- //top face
- normal = new Vector3(0, 1, 0);
- vertices[4] = new VertexPositionNormalTexture(topLeftFront, normal, new Vector2(2f / 3f, 1));
- vertices[5] = new VertexPositionNormalTexture(topRightFront, normal, new Vector2(1, 1));
- vertices[6] = new VertexPositionNormalTexture(topRightBack, normal, new Vector2(1, 0));
- vertices[7] = new VertexPositionNormalTexture(topLeftBack, normal, new Vector2(2f / 3f, 0));
- offset = 4;
- indices[6] = 3 + offset;
- indices[7] = 2 + offset;
- indices[8] = 0 + offset;
- indices[9] = 2 + offset;
- indices[10] = 1 + offset;
- indices[11] = 0 + offset;
- //bottom face
- normal = new Vector3(0, -1, 0);
- vertices[8] = new VertexPositionNormalTexture(bottomRightFront, normal, new Vector2(1f / 3f, 1));
- vertices[9] = new VertexPositionNormalTexture(bottomLeftFront, normal, new Vector2(2f / 3f, 1));
- vertices[10] = new VertexPositionNormalTexture(bottomLeftBack, normal, new Vector2(2 / 3f, 0));
- vertices[11] = new VertexPositionNormalTexture(bottomRightBack, normal, new Vector2(1f / 3f, 0));
- offset = 8;
- indices[12] = 3 + offset;
- indices[13] = 2 + offset;
- indices[14] = 0 + offset;
- indices[15] = 2 + offset;
- indices[16] = 1 + offset;
- indices[17] = 0 + offset;
- //Back face
- normal = new Vector3(0, 0, -1);
- vertices[12] = new VertexPositionNormalTexture(bottomRightBack, normal, new Vector2(0, 1));
- vertices[13] = new VertexPositionNormalTexture(bottomLeftBack, normal, new Vector2(1 / 3f, 1));
- vertices[14] = new VertexPositionNormalTexture(topLeftBack, normal, new Vector2(1 / 3f, 0));
- vertices[15] = new VertexPositionNormalTexture(topRightBack, normal, new Vector2(0, 0));
- offset = 12;
- indices[18] = 3 + offset;
- indices[19] = 2 + offset;
- indices[20] = 0 + offset;
- indices[21] = 2 + offset;
- indices[22] = 1 + offset;
- indices[23] = 0 + offset;
- //Right face
- normal = new Vector3(1, 0, 0);
- vertices[16] = new VertexPositionNormalTexture(bottomRightFront, normal, new Vector2(0, 1));
- vertices[17] = new VertexPositionNormalTexture(bottomRightBack, normal, new Vector2(1 / 3f, 1));
- vertices[18] = new VertexPositionNormalTexture(topRightBack, normal, new Vector2(1 / 3f, 0));
- vertices[19] = new VertexPositionNormalTexture(topRightFront, normal, new Vector2(0, 0));
- offset = 16;
- indices[24] = 3 + offset;
- indices[25] = 2 + offset;
- indices[26] = 0 + offset;
- indices[27] = 2 + offset;
- indices[28] = 1 + offset;
- indices[29] = 0 + offset;
- //Left face
- normal = new Vector3(-1, 0, 0);
- vertices[20] = new VertexPositionNormalTexture(bottomLeftBack, normal, new Vector2(0, 1));
- vertices[21] = new VertexPositionNormalTexture(bottomLeftFront, normal, new Vector2(1 / 3f, 1));
- vertices[22] = new VertexPositionNormalTexture(topLeftFront, normal, new Vector2(1 / 3f, 0));
- vertices[23] = new VertexPositionNormalTexture(topLeftBack, normal, new Vector2(0, 0));
- offset = 20;
- indices[30] = 3 + offset;
- indices[31] = 2 + offset;
- indices[32] = 0 + offset;
- indices[33] = 2 + offset;
- indices[34] = 1 + offset;
- indices[35] = 0 + offset;
- }
Add Comment
Please, Sign In to add comment