Creating a Triangulated Plane // Generate vertices in XZ-plane for i = 0 to n for j = 0 to n Create vertex at location (i*xsize, 0, j*ysize) // step 2. Generate indices for i = 0 to ? Create triangle with indices(i, i+1, i+n+1) Create triangle with indices( i+1, i+n+2, i+n+1) xsize ysize vn v0 v1 v n+1 vn+2
Creating a Triangulated Cylinder // Generate vertices on top for i = 0 to n angle = (i*360) / (n+1) create vertex at (cos( angle), height, sin(angle)) // Generate vertices on the bottom // same process but height = 0 // Generate vertex in the middle of the top // Generate vertex in the middle of the bottom // Generate triangles on top // Generate triangles on the bottom // Generate triangles on the side v1 Vn+2 v0 Vn+1
// Generate triangles on top for (int i = 1; i<=n; i++) { m->vertexIndex.push_back(0); m->vertexIndex.push_back(i); if (i==n) { m->vertexIndex.push_back(1); }else{ m->vertexIndex.push_back(i+1); } } // There is no bottom. Use the floor. // Generate triangles on the side for (int i = 1; i<=n; i++) { m->vertexIndex.push_back(i); m->vertexIndex.push_back(n+i); if (i!=n) { m->vertexIndex.push_back(n+i+1); } else { m->vertexIndex.push_back(n+1); } m->vertexIndex.push_back(i); if (i!=n) { m->vertexIndex.push_back(i+1); m->vertexIndex.push_back(n+i+1); }else{ m->vertexIndex.push_back(1); m->vertexIndex.push_back(n+1); } } return m; }
Creating a Triangulated Cube // Generate vertices on top // Generate vertices on the bottom // Generate triangles on top // Generate triangles on the bottom // Generate triangles on the sides