Wednesday 24 December 2008

Fairly odd stitching

In my previous blog I explained the need for a fair playground. Developing a fair heightmap from an unfair one is quite easy. The key is to tile the original on a 2 x 2 grid such that the edges are mirrors of one another. This way the resulting playground is not only fair, but the edges where the tiles meet are seamless.

This idea was implemented in a class called HeightMapMirror that takes an IHeightMap as argument. This class also implements the IHeightMap
interface. This means a mirror can now be created from any other height map on the fly - whether that map is generated or whether it is loaded from an image file.

Obviously you can feed the constructor of the new class another instance of a HeightMapMirror effectively creating a 4 x 4 tile (who wouldn't give that a try?). Surprisingly, from an almost featureless patch of a HeightMapPerlin terrain an interesting and attractive fair playground is produced using this plan . The image shown above is produced that way. Notice the repeating pattern of water and hills.

The other thing I did today was to create a HeightMapIslandTrim class. Its function is simply to put a coastline on the edge of the heightmap. Like HeightMapMirror (the other modifier of heightmaps) this class constructor also takes another map as source.

First I tried a circle island and did not like the loss of real estate. I then tried creating a square island and did not like the look of it too much. I'll experiment more with this when creating a terrain in the context of a game.

The basic idea of adding a coastline is simple: the height is calculated using a linear interpolation that is based on the distance from the edge of the island. This class can also be (ab)used to create a wall around the terrain by specifying impossible values for waterlevel or shoreheight.

This concludes today's blog. Not much added, but at least some progress has been made.

No comments:

Post a Comment