Slide 1

Slide 1 text

jgs SER332 Introduction to Graphics and Game Development Lecture 18: Mesh Data Structure II Javier Gonzalez-Sanchez [email protected] PERALTA 230U Office Hours: By appointment

Slide 2

Slide 2 text

jgs Plane, Cylinder, and Box

Slide 3

Slide 3 text

Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 3 jgs 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

Slide 4

Slide 4 text

Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 4 jgs Creating a Triangulated Plane // creating a triangulated plane Mesh* createPlane(int arena_width, int arena_depth, int arena_cell) { Mesh *me = new Mesh; int n = arena_width / arena_cell; int m = arena_depth / arena_cell; // vertices for (int i = 0; idot_vertex.push_back(Vec3(i*arena_cell, 0.0, j*arena_cell)); } } // faces for (int i = 0; i<(n*m) - m; i++) { if ((i + 1) % n == 0) continue; me->face_index_vertex.push_back(i); me->face_index_vertex.push_back(i + 1); me->face_index_vertex.push_back(i + n); me->face_index_vertex.push_back(i + 1); me->face_index_vertex.push_back(i+ n + 1); me->face_index_vertex.push_back(i + n); } return me; }

Slide 5

Slide 5 text

Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 5 jgs Creating a Triangulated Plane § Use colors to verify right-hand rule.

Slide 6

Slide 6 text

Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 6 jgs 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

Slide 7

Slide 7 text

Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 7 jgs Creating a Triangulated Cylinder // create a triangulated cylinder Mesh* createCylinder(int h, int radio) { int n = 100; double angle; Mesh *m =new Mesh; // Generate vertices on top m->vertex.push_back(Vec3(0.0, h, 0.0)); for (int i = 0; ivertex.push_back(Vec3 (cos(angle)* radio, h, sin(angle)* radio)); } // Generate vertices on bottom for (int i = 0; ivertex.push_back(Vec3 (cos(angle)* radio, 0.0, sin(angle)* radio)); }

Slide 8

Slide 8 text

jgs Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 8 // 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; }

Slide 9

Slide 9 text

Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 9 jgs Creating a Triangulated Cylinder

Slide 10

Slide 10 text

Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 10 jgs 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

Slide 11

Slide 11 text

Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 11 jgs Creating a Triangulated Cube

Slide 12

Slide 12 text

Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 12 jgs Source Code § https://github.com/javiergs/SER332/blob/master/Lecture18/main.cpp

Slide 13

Slide 13 text

Javier Gonzalez-Sanchez | SER332 | Spring 2018 | 13 jgs Test Yourselves § Include methods to create cubes, planes, and cylinders § Include methods to create spheres

Slide 14

Slide 14 text

jgs SER332 Introduction to Graphics Javier Gonzalez-Sanchez [email protected] Spring 2018 Disclaimer. These slides can only be used as study material for the class SER332 at ASU. They cannot be distributed or used for another purpose.