In this exercise you will work with a program that computes a mathematical function that generates height values for a terrain. You will modify the program to add color to the terrain, varying colors with elevation.
In visualization, real and mathematical surfaces are often computed on a 2D regular grid. Calculated values are mapped to heights above the grid, creating mathematical terrains. Similarly, terrain surfaces can be created using real-world elevation information for parts of the Earth.
This exercise focuses upon use of ElevationGrid and Color nodes.
View the resulting VRML scene by loading the "terrain.wrl" file into your browser.
The program generates a terrain using an ElevationGrid node with terrain elevations set in the node's height field.
In complex visualizations, the height and color of a terrain may each vary with the output of a mathematical function or simulation. Your task is to modify the terrain1.c program to vary the terrain color with the height. You will need to add one color to each vertex in the terrain. For simplicity, compute the color based upon the height, though you could use a separate function if you like.
HINT: You will need to add an additional field to the ElevationGrid node so that it colors each vertex with your list of colors.
HINT: You will need to declare variables at the top of
the program to contain the color values:
HINT: You will need to output the correct number of colors in the correct order. In C you would use two nested loops like:
HINT: You will need to compute colors based on terrain height.
A nice color scheme is a ramp from blue to red:
SOLUTION: terrain1.c, terrain1.wrl