Creating a mesh
We showed that we can implement a single
createMesh function, and use that
to generate lots of different kinds of
parametric surface meshes, each stored as a single triangle strip.
The createMesh function takes as one of its arguments
a function that maps (u,v) to (x,y,x,nx,ny,nz).
We showed how this approach can be used
to create a square, open tube, disk and sphere.
But then we encounter some shapes, such as a
cylinder or cube, that are best made by glueing together
multiple simple meshes into a single triangle strip.
We showed how to do this as follows:
-
glueTwoMeshes(mesh1,mesh2):
To glue together two triangle strips a and b,
concatenate together the following four things:
- Triangle strip a
- The last vertex of a
- The first vertex of b
- Triangle strip b
-
glueMeshes(arrayOfMeshes):
To glue together an array of triangle strips,
we just repeated the glueTwoMeshes() function in a loop.
In order to make the above work, we
introduced an optional third info
argument into functions that are passed to
createMesh.
This argument contains any extra info
needed to customize the mesh.
Homework
Due next Wednesday before the start of class
Start with the included code in
hw7.zip.
Create an interesting scene using the matrix operations
and the shape primitives that we created.
Perhaps it can be a house,
or a tree,
or an alien spaceship,
or your favorite childhood toy.
Use your imagination. Be creative.
For extra credit, see if you can figure out how to
make different colors and/or procedural textures for different
objects in your scene.
Hint: One way to implement the extra credit is to send down to the GPU different
values for the uPhong
matrix when you do the
draw calls to render different shapes in your scene.