|
| 1 | + public static Shape makeHouse() |
| 2 | + { |
| 3 | + // A house |
| 4 | + float vertices[] = {-4,-4,4, 4,-4,4, 4,4,4, -4,4,4, // front face |
| 5 | + -4,-4,-4, -4,-4,4, -4,4,4, -4,4,-4, // left face |
| 6 | + 4,-4,-4,-4,-4,-4, -4,4,-4, 4,4,-4, // back face |
| 7 | + 4,-4,4, 4,-4,-4, 4,4,-4, 4,4,4, // right face |
| 8 | + 4,4,4, 4,4,-4, -4,4,-4, -4,4,4, // top face |
| 9 | + -4,-4,4, -4,-4,-4, 4,-4,-4, 4,-4,4, // bottom face |
| 10 | + |
| 11 | + -20,-4,20, 20,-4,20, 20,-4,-20, -20,-4,-20, // ground floor |
| 12 | + -4,4,4, 4,4,4, 0,8,4, // the roof |
| 13 | + 4,4,4, 4,4,-4, 0,8,-4, 0,8,4, |
| 14 | + -4,4,4, 0,8,4, 0,8,-4, -4,4,-4, |
| 15 | + 4,4,-4, -4,4,-4, 0,8,-4}; |
| 16 | + |
| 17 | + float normals[] = {0,0,1, 0,0,1, 0,0,1, 0,0,1, // front face |
| 18 | + -1,0,0, -1,0,0, -1,0,0, -1,0,0, // left face |
| 19 | + 0,0,-1, 0,0,-1, 0,0,-1, 0,0,-1, // back face |
| 20 | + 1,0,0, 1,0,0, 1,0,0, 1,0,0, // right face |
| 21 | + 0,1,0, 0,1,0, 0,1,0, 0,1,0, // top face |
| 22 | + 0,-1,0, 0,-1,0, 0,-1,0, 0,-1,0, // bottom face |
| 23 | + |
| 24 | + 0,1,0, 0,1,0, 0,1,0, 0,1,0, // ground floor |
| 25 | + 0,0,1, 0,0,1, 0,0,1, // front roof |
| 26 | + 0.707f,0.707f,0, 0.707f,0.707f,0, 0.707f,0.707f,0, 0.707f,0.707f,0, // right roof |
| 27 | + -0.707f,0.707f,0, -0.707f,0.707f,0, -0.707f,0.707f,0, -0.707f,0.707f,0, // left roof |
| 28 | + 0,0,-1, 0,0,-1, 0,0,-1}; // back roof |
| 29 | + |
| 30 | + float colors[] = {1,0,0, 1,0,0, 1,0,0, 1,0,0, |
| 31 | + 0,1,0, 0,1,0, 0,1,0, 0,1,0, |
| 32 | + 1,0,0, 1,0,0, 1,0,0, 1,0,0, |
| 33 | + 0,1,0, 0,1,0, 0,1,0, 0,1,0, |
| 34 | + 0,0,1, 0,0,1, 0,0,1, 0,0,1, |
| 35 | + 0,0,1, 0,0,1, 0,0,1, 0,0,1, |
| 36 | + |
| 37 | + 0,0.5f,0, 0,0.5f,0, 0,0.5f,0, 0,0.5f,0, // ground floor |
| 38 | + 0,0,1, 0,0,1, 0,0,1, // roof |
| 39 | + 1,0,0, 1,0,0, 1,0,0, 1,0,0, |
| 40 | + 0,1,0, 0,1,0, 0,1,0, 0,1,0, |
| 41 | + 0,0,1, 0,0,1, 0,0,1,}; |
| 42 | + |
| 43 | + // Set up the vertex data |
| 44 | + VertexData vertexData = new VertexData(42); |
| 45 | + |
| 46 | + // Specify the elements of the vertex data: |
| 47 | + // - one element for vertex positions |
| 48 | + vertexData.addElement(vertices, VertexData.Semantic.POSITION, 3); |
| 49 | + // - one element for vertex colors |
| 50 | + vertexData.addElement(colors, VertexData.Semantic.COLOR, 3); |
| 51 | + // - one element for vertex normals |
| 52 | + vertexData.addElement(normals, VertexData.Semantic.NORMAL, 3); |
| 53 | + |
| 54 | + // The index data that stores the connectivity of the triangles |
| 55 | + int indices[] = {0,2,3, 0,1,2, // front face |
| 56 | + 4,6,7, 4,5,6, // left face |
| 57 | + 8,10,11, 8,9,10, // back face |
| 58 | + 12,14,15, 12,13,14, // right face |
| 59 | + 16,18,19, 16,17,18, // top face |
| 60 | + 20,22,23, 20,21,22, // bottom face |
| 61 | + |
| 62 | + 24,26,27, 24,25,26, // ground floor |
| 63 | + 28,29,30, // roof |
| 64 | + 31,33,34, 31,32,33, |
| 65 | + 35,37,38, 35,36,37, |
| 66 | + 39,40,41}; |
| 67 | + |
| 68 | + vertexData.addIndices(indices); |
| 69 | + |
| 70 | + Shape house = new Shape(vertexData); |
| 71 | + |
| 72 | + return house; |
| 73 | + } |
| 74 | + |
0 commit comments