Game Development Reference
In-Depth Information
Objectives
To learn how to generate height info for the terrain that results in
smooth transitions of mountains and valleys, simulating a natural
terrain
To understand how to generate the vertex and triangle data for a
terrain
To learn a technique that we can use to texture and light the terrain
To discover a way to keep the camera planted on the terrain so that
walking or running on the terrain is simulated
13.1 Heightmaps
We use a heightmap to describe the hills and valleys of our terrain. A
heightmap is an array where each element specifies the height of a par-
ticular vertex in the terrain grid. (An alternate implementation might
have a heightmap entry for each square world unit.) We usually think of
a heightmap as a matrix so that each element has a one-to-one corre-
spondence with each vertex in the terrain grid.
When we store our heightmaps on disk, we usually allocate a byte
of memory for each element in heightmap, so the height can range from
0 to 255. The range 0 to 255 is enough to preserve the transition
between heights of our terrain, but in our application we may need to
scale out of the 0 to 255 range in order to match the scale of our 3D
world. For example, if our unit of measure in the 3D world is feet, then
0 to 255 does not give us enough values to represent anything interest-
ing. For this reason, when we load the data into our applications we
allocate an integer (or float) for each height element. This allows us to
scale well outside the 0 to 255 range to match any scale necessary.
One of the possible graphical representations of a heightmap is a
grayscale map, where darker values reflect portions of the terrain with
low altitudes and whiter values reflect portions of the terrain with
higher altitudes. Figure 13.2 shows a grayscale map.
Search WWH ::




Custom Search