The Sewer

Top  Previous  Next

This month's "Plug and play" article was inspired by one of Grafton's snippets and doesn't have anything to do with the sewers, but with terrain sewing. Grafton has written two tiny functions that do a great job when it comes to terrain sewing, but they require quite a bit of setup. This snippet takes 9 terrain entities with any horizontal / vertical scale, with any number of vertices, and then it creates the terrain pieces at runtime and sews them automatically.


The terrain pieces that came with this demo weren't built in order to match each other; see for yourself:




Nevertheless, the sewing code does a great job getting the needed info about the terrains and stitching them together:




You can set the horizontal and / or vertical scale of the terrains by playing with these variables at the top of the sewer.c file:


var horizontal_scale = 5; // horizontal scale of the terrain entities, play with it

var vertical_scale = 2; // vertical scale of the terrain entities, play with it




These terrain pieces are sewed together very well even if we choose a huge vertical scale; see for yourself:




And here's how the entire level looks when seen from above:




I chose a totally random heightmap for my terrains because I wanted to see if the sewing algorithm works fine even under extreme conditions. You should split a huge heightmap in 9 parts in order to create the 9 terrain pieces - the end result will look more natural.


The code is very well commented, as always.