Guest User

Untitled

a guest
Feb 21st, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.20 KB | None | 0 0
  1.  public Cube()
  2.         {
  3.             vertices = new VertexPositionNormalTexture[24];
  4.             indices = new int[36];
  5.             Vector3 size = new Vector3(3, 3, 3);
  6.            
  7.             //Corner points
  8.             Vector3 topLeftFront = new Vector3(-1, 1, 1) * size;
  9.             Vector3 topRightFront = new Vector3(1, 1, 1) * size;
  10.             Vector3 bottomLeftFront = new Vector3(-1, -1, 1) * size;
  11.             Vector3 bottomRightFront = new Vector3(1, -1, 1) * size;
  12.             Vector3 topLeftBack = new Vector3(-1, 1, -1) * size;
  13.             Vector3 topRightBack = new Vector3(1, 1, -1) * size;
  14.             Vector3 bottomLeftBack = new Vector3(-1, -1, -1) * size;
  15.             Vector3 bottomRightBack = new Vector3(1, -1, -1) * size;
  16.  
  17.             //Front face
  18.             Vector3 normal = new Vector3(0, 0, 1);
  19.             vertices[0] = new VertexPositionNormalTexture(bottomLeftFront, normal, new Vector2(0, 1));
  20.             vertices[1] = new VertexPositionNormalTexture(bottomRightFront, normal, new Vector2(1 / 3f, 1));
  21.             vertices[2] = new VertexPositionNormalTexture(topRightFront, normal, new Vector2(1 / 3f, 0));
  22.             vertices[3] = new VertexPositionNormalTexture(topLeftFront, normal, new Vector2(0, 0));
  23.  
  24.             int offset = 0;
  25.             indices[0] = 3 + offset;
  26.             indices[1] = 2 + offset;
  27.             indices[2] = 0 + offset;
  28.             indices[3] = 2 + offset;
  29.             indices[4] = 1 + offset;
  30.             indices[5] = 0 + offset;
  31.  
  32.             //top face
  33.             normal = new Vector3(0, 1, 0);
  34.             vertices[4] = new VertexPositionNormalTexture(topLeftFront, normal, new Vector2(2f / 3f, 1));
  35.             vertices[5] = new VertexPositionNormalTexture(topRightFront, normal, new Vector2(1, 1));
  36.             vertices[6] = new VertexPositionNormalTexture(topRightBack, normal, new Vector2(1, 0));
  37.             vertices[7] = new VertexPositionNormalTexture(topLeftBack, normal, new Vector2(2f / 3f, 0));
  38.  
  39.             offset = 4;
  40.             indices[6] = 3 + offset;
  41.             indices[7] = 2 + offset;
  42.             indices[8] = 0 + offset;
  43.             indices[9] = 2 + offset;
  44.             indices[10] = 1 + offset;
  45.             indices[11] = 0 + offset;
  46.  
  47.             //bottom face
  48.             normal = new Vector3(0, -1, 0);
  49.             vertices[8] = new VertexPositionNormalTexture(bottomRightFront, normal, new Vector2(1f / 3f, 1));
  50.             vertices[9] = new VertexPositionNormalTexture(bottomLeftFront, normal, new Vector2(2f / 3f, 1));
  51.             vertices[10] = new VertexPositionNormalTexture(bottomLeftBack, normal, new Vector2(2 / 3f, 0));
  52.             vertices[11] = new VertexPositionNormalTexture(bottomRightBack, normal, new Vector2(1f / 3f, 0));
  53.  
  54.             offset = 8;
  55.             indices[12] = 3 + offset;
  56.             indices[13] = 2 + offset;
  57.             indices[14] = 0 + offset;
  58.             indices[15] = 2 + offset;
  59.             indices[16] = 1 + offset;
  60.             indices[17] = 0 + offset;
  61.  
  62.             //Back face
  63.             normal = new Vector3(0, 0, -1);
  64.             vertices[12] = new VertexPositionNormalTexture(bottomRightBack, normal, new Vector2(0, 1));
  65.             vertices[13] = new VertexPositionNormalTexture(bottomLeftBack, normal, new Vector2(1 / 3f, 1));
  66.             vertices[14] = new VertexPositionNormalTexture(topLeftBack, normal, new Vector2(1 / 3f, 0));
  67.             vertices[15] = new VertexPositionNormalTexture(topRightBack, normal, new Vector2(0, 0));
  68.  
  69.             offset = 12;
  70.             indices[18] = 3 + offset;
  71.             indices[19] = 2 + offset;
  72.             indices[20] = 0 + offset;
  73.             indices[21] = 2 + offset;
  74.             indices[22] = 1 + offset;
  75.             indices[23] = 0 + offset;
  76.  
  77.             //Right face
  78.             normal = new Vector3(1, 0, 0);
  79.             vertices[16] = new VertexPositionNormalTexture(bottomRightFront, normal, new Vector2(0, 1));
  80.             vertices[17] = new VertexPositionNormalTexture(bottomRightBack, normal, new Vector2(1 / 3f, 1));
  81.             vertices[18] = new VertexPositionNormalTexture(topRightBack, normal, new Vector2(1 / 3f, 0));
  82.             vertices[19] = new VertexPositionNormalTexture(topRightFront, normal, new Vector2(0, 0));
  83.  
  84.             offset = 16;
  85.             indices[24] = 3 + offset;
  86.             indices[25] = 2 + offset;
  87.             indices[26] = 0 + offset;
  88.             indices[27] = 2 + offset;
  89.             indices[28] = 1 + offset;
  90.             indices[29] = 0 + offset;
  91.  
  92.             //Left face
  93.             normal = new Vector3(-1, 0, 0);
  94.             vertices[20] = new VertexPositionNormalTexture(bottomLeftBack, normal, new Vector2(0, 1));
  95.             vertices[21] = new VertexPositionNormalTexture(bottomLeftFront, normal, new Vector2(1 / 3f, 1));
  96.             vertices[22] = new VertexPositionNormalTexture(topLeftFront, normal, new Vector2(1 / 3f, 0));
  97.             vertices[23] = new VertexPositionNormalTexture(topLeftBack, normal, new Vector2(0, 0));
  98.  
  99.             offset = 20;
  100.             indices[30] = 3 + offset;
  101.             indices[31] = 2 + offset;
  102.             indices[32] = 0 + offset;
  103.             indices[33] = 2 + offset;
  104.             indices[34] = 1 + offset;
  105.             indices[35] = 0 + offset;
  106.         }
Add Comment
Please, Sign In to add comment