Homework 5

Short Description:

Add a plane, off files and lighting to the system produced in homework 4.

This assignment is worth 50 points.

Goals

When you finish this homework, you should

Formal Description

This program will be modified and extended, we will be adding features, and functionality, so make sure that you keep your design and implementation as open as possible. In the future I plan to switch this program over to the new shader language.

Add the ability to load a terrain file. The terrain file format consists of two integers N and M, representing the size of a grid (N squares by M squares). This is followed by (N+1)*(M+1) height values. An example might be:

3 4
0    1    1.5  2 
1    1.5  2    2.5
1.5  2    2.5  3
2    2.5  3    3
2.5  3    3    3

This should be a sloped surface with a high plateau at one end.

In my world, this was generated by the function


const GLfloat  scale = sqrt(XDIM*XDIM+YDIM*YDIM)/24;

GLfloat  height(GLfloat  x, GLfloat  y) {
    GLfloat  d =sqrt(float(x)*x+y*y)/scale;
    return(cos(d)*SCALE_HEIGHT) ;
}

Your program should load these points and store them in a manner that can be used to draw a plane constructed from triangles. You should also compute normals for each point. These normals should be the average of the normals for all edges for which this point is an end point. You should store this information so that the surface can be drawn with glDrawElements.

You should implement the surface as an object.

Implement an object that will allow you load and display an off file as discussed earlier in the class.

For both of the above classes, think of the glWireTeapot command as a model. You will probably not want to draw multiple surfaces, but it might make sense to draw multiple instances of the data from an .off file. Again, your object should be drawn with a call to glMultiDrawElements.

Finally, implement lights in your world. You should have a minimum of two light sources, but you may have more. You need a "sun", which lights your world from above and a head mounted "flashlight", which is located at the eye position and travels with the camera.

Please use the following keypresses
Key Action
Up ArrowMove forward a single step along the current vector
Down ArrowMove backward a single step along the current vector
Right ArrowTurn to the right
Left ArrowTurn to the left
AIncrease look ahead distance
aDecrease look ahead distance
rReset to the default position
qExit the program
1Toggle the sun on/off
2Toggle the flashlight on/off

You may add other keypress operations as well, but please:

Discussion

Populate your world with various objects from the .off file library (or create your own).

Make sure that hidden surface removal and double buffering is enabled.

Submission

You should email tar file as an attachment to a message to danbennett360@gmail.com. This tar file should contain all of the source code required to generate your project, a Makefile, and the README file.