This assignment is worth 50 points.
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 Arrow | Move forward a single step along the current vector |
Down Arrow | Move backward a single step along the current vector |
Right Arrow | Turn to the right |
Left Arrow | Turn to the left |
A | Increase look ahead distance |
a | Decrease look ahead distance |
r | Reset to the default position |
q | Exit the program |
1 | Toggle the sun on/off |
2 | Toggle the flashlight on/off |
You may add other keypress operations as well, but please:
Make sure that hidden surface removal and double buffering is enabled.