public static void CreateUnitCube(List <Vector3> pos, List <Vector3> normal, List <Vector2> tex, List <uint> indices) { VertexPNT[] v = new VertexPNT[24]; // Fill in the front face vertex data. v[0] = new VertexPNT(-0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 0.0f, 1.0f); v[1] = new VertexPNT(-0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f); v[2] = new VertexPNT(0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 1.0f, 0.0f); v[3] = new VertexPNT(0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 1.0f, 1.0f); // Fill in the back face vertex data. v[4] = new VertexPNT(-0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f); v[5] = new VertexPNT(0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f); v[6] = new VertexPNT(0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f); v[7] = new VertexPNT(-0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f); // Fill in the top face vertex data. v[8] = new VertexPNT(-0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f); v[9] = new VertexPNT(-0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f); v[10] = new VertexPNT(0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f); v[11] = new VertexPNT(0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f); // Fill in the bottom face vertex data. v[12] = new VertexPNT(-0.5f, -0.5f, -0.5f, 0.0f, -1.0f, 0.0f, 1.0f, 1.0f); v[13] = new VertexPNT(0.5f, -0.5f, -0.5f, 0.0f, -1.0f, 0.0f, 0.0f, 1.0f); v[14] = new VertexPNT(0.5f, -0.5f, 0.5f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f); v[15] = new VertexPNT(-0.5f, -0.5f, 0.5f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f); // Fill in the left face vertex data. v[16] = new VertexPNT(-0.5f, -0.5f, 0.5f, -1.0f, 0.0f, 0.0f, 0.0f, 1.0f); v[17] = new VertexPNT(-0.5f, 0.5f, 0.5f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f); v[18] = new VertexPNT(-0.5f, 0.5f, -0.5f, -1.0f, 0.0f, 0.0f, 1.0f, 0.0f); v[19] = new VertexPNT(-0.5f, -0.5f, -0.5f, -1.0f, 0.0f, 0.0f, 1.0f, 1.0f); // Fill in the right face vertex data. v[20] = new VertexPNT(0.5f, -0.5f, -0.5f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f); v[21] = new VertexPNT(0.5f, 0.5f, -0.5f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f); v[22] = new VertexPNT(0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f); v[23] = new VertexPNT(0.5f, -0.5f, 0.5f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f); for (int i = 0; i < v.Length; ++i) { v[i].Position.Z *= -1; v[i].Normal.Z *= -1; pos.Add(v[i].Position); normal.Add(v[i].Normal); if (tex != null) { tex.Add(v[i].Tex); } } uint[] index = new uint[36]; // Fill in the front face index data index[0] = 0; index[1] = 1; index[2] = 2; index[3] = 0; index[4] = 2; index[5] = 3; // Fill in the back face index data index[6] = 4; index[7] = 5; index[8] = 6; index[9] = 4; index[10] = 6; index[11] = 7; // Fill in the top face index data index[12] = 8; index[13] = 9; index[14] = 10; index[15] = 8; index[16] = 10; index[17] = 11; // Fill in the bottom face index data index[18] = 12; index[19] = 13; index[20] = 14; index[21] = 12; index[22] = 14; index[23] = 15; // Fill in the left face index data index[24] = 16; index[25] = 17; index[26] = 18; index[27] = 16; index[28] = 18; index[29] = 19; // Fill in the right face index data index[30] = 20; index[31] = 21; index[32] = 22; index[33] = 20; index[34] = 22; index[35] = 23; // reverse windings for (int i = 0; i < 34; i += 3) { indices.Add(index[i + 2]); indices.Add(index[i + 1]); indices.Add(index[i]); } }
public static void CreateUnitCube(List<Vector3> pos, List<Vector3> normal, List<Vector2> tex, List<uint> indices) { VertexPNT[] v = new VertexPNT[24]; // Fill in the front face vertex data. v[0] = new VertexPNT(-0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 0.0f, 1.0f); v[1] = new VertexPNT(-0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f); v[2] = new VertexPNT( 0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 1.0f, 0.0f); v[3] = new VertexPNT( 0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 1.0f, 1.0f); // Fill in the back face vertex data. v[4] = new VertexPNT(-0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f); v[5] = new VertexPNT( 0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f); v[6] = new VertexPNT( 0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f); v[7] = new VertexPNT(-0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f); // Fill in the top face vertex data. v[8] = new VertexPNT(-0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f); v[9] = new VertexPNT(-0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f); v[10] = new VertexPNT( 0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f); v[11] = new VertexPNT( 0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f); // Fill in the bottom face vertex data. v[12] = new VertexPNT(-0.5f, -0.5f, -0.5f, 0.0f, -1.0f, 0.0f, 1.0f, 1.0f); v[13] = new VertexPNT( 0.5f, -0.5f, -0.5f, 0.0f, -1.0f, 0.0f, 0.0f, 1.0f); v[14] = new VertexPNT( 0.5f, -0.5f, 0.5f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f); v[15] = new VertexPNT(-0.5f, -0.5f, 0.5f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f); // Fill in the left face vertex data. v[16] = new VertexPNT(-0.5f, -0.5f, 0.5f, -1.0f, 0.0f, 0.0f, 0.0f, 1.0f); v[17] = new VertexPNT(-0.5f, 0.5f, 0.5f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f); v[18] = new VertexPNT(-0.5f, 0.5f, -0.5f, -1.0f, 0.0f, 0.0f, 1.0f, 0.0f); v[19] = new VertexPNT(-0.5f, -0.5f, -0.5f, -1.0f, 0.0f, 0.0f, 1.0f, 1.0f); // Fill in the right face vertex data. v[20] = new VertexPNT( 0.5f, -0.5f, -0.5f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f); v[21] = new VertexPNT( 0.5f, 0.5f, -0.5f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f); v[22] = new VertexPNT( 0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f); v[23] = new VertexPNT( 0.5f, -0.5f, 0.5f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f); for(int i = 0; i < v.Length; ++i) { v[i].Position.Z *= -1; v[i].Normal.Z *= -1; pos.Add(v[i].Position); normal.Add(v[i].Normal); if(tex != null) tex.Add(v[i].Tex); } uint[] index = new uint[36]; // Fill in the front face index data index[0] = 0; index[1] = 1; index[2] = 2; index[3] = 0; index[4] = 2; index[5] = 3; // Fill in the back face index data index[6] = 4; index[7] = 5; index[8] = 6; index[9] = 4; index[10] = 6; index[11] = 7; // Fill in the top face index data index[12] = 8; index[13] = 9; index[14] = 10; index[15] = 8; index[16] = 10; index[17] = 11; // Fill in the bottom face index data index[18] = 12; index[19] = 13; index[20] = 14; index[21] = 12; index[22] = 14; index[23] = 15; // Fill in the left face index data index[24] = 16; index[25] = 17; index[26] = 18; index[27] = 16; index[28] = 18; index[29] = 19; // Fill in the right face index data index[30] = 20; index[31] = 21; index[32] = 22; index[33] = 20; index[34] = 22; index[35] = 23; // reverse windings for (int i = 0; i < 34; i += 3) { indices.Add(index[i + 2]); indices.Add(index[i + 1]); indices.Add(index[i]); } }