More interesting Meshes
This week I want you to finish up your z-buffering if you haven't done that yet, and I want you to start using more general purpose mesh objects, and try to make cool things with them. Don't be afraid to use your matrix operations like rotations, translations, scaling, push() and pop() to make interesting scenes.
As we discussed in class, a more general way to store polyhedral meshes is to use a vertex array and a face array. Each element of the vertex array contains point/normal values for a single vertex:
vertices = { { x,y,z, nx,ny,nz }_{0}, { x,y,z, nx,ny,nz }_{1}, ... }
Each element of the face array contains an ordered list of the vertices in that face:
faces = { { v_{0},v_{1},v_{2},... }_{0}, { v_{0},v_{1},v_{2},... }_{1}, ... }
A vertex is specified by both its location and its normal vector direction. As I said in class, if vertex normals are different, then two vertices are not the same. For example, here is a declaration for the vertices and the faces of a unit cube:
int[][] faces = { { 0, 1, 2, 3 }, { 4, 5, 6, 7 }, { 8, 9, 10, 11 }, { 12, 13, 14, 15 }, { 16, 17, 18, 19 }, { 20, 21, 22, 23 } }; double[][] vertices = { {-1,-1,-1,-1, 0, 0 }, {-1,-1, 1,-1, 0, 0 }, {-1, 1, 1,-1, 0, 0 }, {-1, 1,-1,-1, 0, 0 }, { 1,-1,-1, 1, 0, 0 }, { 1, 1,-1, 1, 0, 0 }, { 1, 1, 1, 1, 0, 0 }, { 1,-1, 1, 1, 0, 0 }, {-1,-1,-1, 0,-1, 0 }, { 1,-1,-1, 0,-1, 0 }, { 1,-1, 1, 0,-1, 0 }, {-1,-1, 1, 0,-1, 0 }, {-1, 1,-1, 0, 1, 0 }, {-1, 1, 1, 0, 1, 0 }, { 1, 1, 1, 0, 1, 0 }, { 1, 1,-1, 0, 1, 0 }, {-1,-1,-1, 0, 0,-1 }, {-1, 1,-1, 0, 0,-1 }, { 1, 1,-1, 0, 0,-1 }, { 1,-1,-1, 0, 0,-1 }, {-1,-1, 1, 0, 0, 1 }, { 1,-1, 1, 0, 0, 1 }, { 1, 1, 1, 0, 0, 1 }, {-1, 1, 1, 0, 0, 1 } };
compute normals, transforming normals:
If you want to create the illusion of smooth interpolated normals when you're approximating rounded shapes (like spheres and cylinders) you can do so either by using special purpose methods for that particular shape (like using the direction from the center of a sphere to each vertex), or else you can use the following more general purpose method:
To transform a normal vector, you need to transform it by the transpose of M^{-1}, where M is the matrix that you are using to transform the associate vertex location. As I said i class, you can use the MatrixInverter class to compute a matrix inverse. Remember that you need to use the transpose of this matrix (ie: flip the rows and columns).
As usual, try to make fun, cool and interesting content. See if you can make various shapes that are built up from things like tubes and cylinders or tori, as in the applet I showed in class. We haven't done the math yet to do spline surfaces like teapots.