Terrain Generation Tutorial: Island Modification
previous | next
| code
The algorithm as it has been presented so far works well for generating
terrains that run all the way to the edge of the height map. In many cases,
this may be what we want. However, if you find yourself needing islands,
where the heightmap tends towards zero at the edges, there is a simple
modification we can make to the algorithm.
Choosing Centerpoints
As we saw, step 2 involves choosing a random
centerpoint for a hill. Normally, this is chosen to be anywhere on the
heightmap, evenly distributed. What we want now is to have our hills clustered
towards the middle of the heightmap. To do this, we need two random values,
call them distance and theta. The distance will be how far from the center
of the heightmap our hill will be placed. It can range from zero (right
in the middle) to half the size of the heightmap minus the radius of the
hill. This will prevent hills from reaching the edge of the heightmap.
Theta determines in which direction from the center the hill be placed.
It ranges from 0 to two pi. From these two values, we can then calculate
the x and y coordinates for the centerpoint of the hill and proceed as
usual with the algorithm. So, to generate centerpoints for hills using
the island modification, we use the following equations:

Note that the maximum radius for a hill should
be less than half
of the size of the heightmap.
Using this, we can add as many hills as we want, and still be sure that
the outer edge of the heightmap will reach zero. It looks something like
this:

Note that when we run the flattening step on the
island, it ends up shrinking the
coastline pretty significantly. If using islands, you might want to avoid
flattening.
Water Plane
By adding a water plane at a height slightly above zero, we get something
like this:

Here you can clearly see the coastline. For a more
irregular coastline, try decreasing the
maximum hill size and/or lowering the number of hills.
That's about it. I hope this has been interesting and useful to you.
As you can see, the algorithm is pretty straightforward. Finally, on to
the code itself.
Copyright © 1999-2002 Bob Nystrom.
|