CS 455 - Programming Assignment 7

This assignment is about textures and it introduces the idea of a "mesh". This assignment is due Thursday, May 12.

Download this zip file. In the zip file you will find a demo program, CS455Hw7-Demo.exe. You are to write the code for this program. In the zip file there is also a file CS455Hw7-baby-demo.c that you can compile and run. This is a simplified version of the program that you are to write and it can serve as a starting point.

When you run the demo program, you will see that the goal of this assignment is to create a "flexible" texture. To understand how we will do this, first think about applying the earth.raw image as a texture on the rectangle with (model) coordinates (-2,1,0), (2,1,0), (2,-1,0), and (-2,-1,0). This is easy since we only need to give OpenGL these four vertices and the four texture coordinates (0,1), (1,1), (1,0), (0,0) respectively. But the result would be a "rigid" geometric object (that we can move around with transformations, but not bend). What if we want to bend this textured piece of geometry? In the program CS455Hw7-baby-demo.c we add eight vertices to our rectangle so that it has 12 vertices in eight quads (look at the code and draw yourself a sketch of the quads). These eight new vertices are each given an appropriate texture coordinate, so the texture can be thought of as being "stretched" onto the grid of quads. The edges of our new quads are now places where we can flex our original rectangle. When we flex this grid of quads, the texture coordinates remain bound to their respective vertices, and so the texture stays in place (that is, the texture moves with the quads).

Since the program CS455Hw7-baby-demo.c only uses eight quads, it does not make for a very flexible texture. But if we subdivide our original rectangle into a large number of (small) quads, then we have more places where we can flex our geometric object. Run the program CS455Hw7-Demo.exe and use the 't' and 'T' keys to turn off and on the texture. With the texture turned off, you can see that this program is using 80 quads (in 20 rows of 40 quads). The subdivision of a large polygon into smaller polygons is often called a "mesh". A mesh of small polygons gives you more control over the "flexibility" of a geometric object (at the expense of doing more computation in the graphics pipeline).

Your first step in writing this program is to take CS455Hw7-baby-demo.c and write nested for-loops that create the vertices for the 80 quads. Do this without any texture (as a wire frame) and without any animation (make all the z-coordinates of your vertices 0). After you have the appropriate quads, give all of the vertices the appropriate texture coordinates. When you have the image earth.raw drawn on your mesh of 80 quads, then you can add the animation. All the animation does is make each vertex oscillate in the z-direction (that is, the animation never changes the x or y coordinates of any vertex, it just changes the z-coordinate). If a vertex in the mesh has coordinates (x,y,z), then the formula for the animation of the z-coordinate is

z = A*sin(wl*PI*(t-sqrt(x*x+y*y))
where A represents the amplitude of the oscillation, wl represents the "wave length" of the wave created in the mesh, and t is time.

When you run the program CS455Hw7-Demo.exe, notice that it allows you to change the amplitude of the oscillation, the "wave length" of the oscillation, and the speed of the animation. Your program should do the same. When you change one of these parameters using the keyboard, the console lets you know the value of the parameter. Be sure to experiment with these parameters. Usually, turning off the texture makes it easier to see the effect that a parameter has.

If you want to experiment, try using your own image file as a texture. Also, you can try different functions z=f(x,y) for the animation. For example, the function z=A*sin(wl*PI*(t+x))*cos(wl*PI*(t+y)) creates a kind of waving flag animation (if you play around with the parameters A and wl).

Turn in a zip file called CS455Hw7Surname.zip containing your version of CS455Hw7Surname.c. Please remember to put your name inside of each of your source files. This assignment is due Thursday, May 12.


Return to the main homework page.
Return to the CS 45500 home page.


compliments and criticisms