Program 3

Program 3: Terrain Viewer

Due: Thursday, September 16th, 2010 (before lab session starts)

Utilize your base code from the previous lab assignment, tview. For this program, you will modify tview and enhance its capabilities.

Your base program should satisfy the requirements of the lab 3 assignment: it should be able to load DEM files, the user should be able to control camera movement around the scene, and it should be capable of rendering the terrain with points and lines.

Terrain Rendering

Part 1 - Color the Heightmap

The first step is to color the terrain based on point height. Obtain the maximum and minimum height values of the terrain, and scale each point's height value to a range of [0,1]. Assign colors to points based on their scaled height values by linearly interpolating between two or more colors in a colormap. If you use the included jetColormap() function, you should see the following:

pgm_03/colored_points.png

Feel free to experiment with your own colormaps! Even with two or three colors, the results can be pretty and helpful.

Note: this is just one of countless applications of linear interpolation, frequently just called lerping, which is ubiquitous in computer graphics. For more information, see here.

Part 2 - Solid Terrain Rendering

Next, render the terrain as a solid surface. You are required to render the terrain with triangles and quads, but may choose whether to use GL_TRIANGLES or GL_TRIANGLE_STRIP, and correspondingly, GL_QUADS or GL_QUAD_STRIP. It is recommended that you use strips, as they are more efficient and perfectly suited for this application. Your solid heightmap should look something like this if you have used the included jetColormap() function:

pgm_03/colored_heightmap.png

Terrain Manipulation

Part 1 - User-Controlled Elevation Exaggeration

Allow the user to perform terrain exaggeration through use of a mouse or keyboard callback. Terrain exaggeration should scale the height of the terrain map, causing the differences in elevation to become much more noticeable:

pgm_03/elevation_exaggeration.png

Don't modify the height values of the terrain data itself; if you do, you will have to free and regenerate the terrain list whenever the user changes the exaggeration constant. This can be an expensive and time-consuming operation; instead, use glScalef to scale the terrain before it is drawn.

Part 2 - Elevation Animation

Animate the terrain exaggeration scalar with a sinusoid based on time. You can either do this by registering an idle callback with glutIdleFunc and checking how much time has elapsed each loop with glutGet(GLUT_ELAPSED_TIME), or by utilizing a timer callback with glutTimerFunc as in Example 05. When enabled, the terrain's elevation exaggeration should oscillate between some reasonable values (your choice).

Once this is done, create a menu item at the top level of the menu to allow the user to toggle elevation animation on and off. When the user enables or disables the elevation animation, be sure to change the name of the menu item appropriately using glutChangeToMenuEntry (i.e., if the user has just disabled animation, change the menu item title to "Enable Exaggeration Animation" and vice-versa). Your final menu should look as follows:

pgm_03/menu.png

Usage

To specify the input data file, your program should have at least the following command line interface:

usage: tview [options] <datafile>
Options:
    -h         Show this help message

An example invocation would be:

$ ./tview all_campus.dem

Feel free to add additional flags and options to modify your programs behavior at runtime.

Grading Rubric

Grading for this assignment is out of 10 points:

Points Requirement
1 Program colors terrain based on height.
3 Program displays terrain using triangles and quads.
2 Program has menus that allow for selecting rendering modes.
1 Program uses Scalef to exaggerate terrain height.
1 Program includes terrain height exaggeration animation.
1 Submission includes Makefile, source code, and README, and builds and runs on RHEL5 machine.
1 Program source code is commented appropriately.

Submission

Submit your source code, Makefile, and README to your course dropbox:

/afs/nd.edu/coursefa.10/cse/cse40166.01/dropbox/<afsid>/pgm3

Do not include the DEM files you used.

Solutions

Alex Zavodny: