Q:

Marching Cubes Terrain

For the past week I've been researching the Marching Cubes algorithm. I hope to use this for Terrain as it would allow the creation of destruction of terrain. After looking at source code and reading many articles I decided to try compiling some of it myself and playing around with it to attempt to make terrain. However, It's giving me a headache and I can't seem to find any good resources on how to do it.
http://i.stack.imgur.com/BbvJR.png
This is from the example found here - http://www.angelfire.com/linux/myp/MC/
The sourcecode relevant can be found on the website.
I added the source code to my project and converted all the code to be used with OpenGL 3.2. However, I don't want to be using this code in my final project. (This is just so I can understand it). I'm having trouble understanding the code. I feel I understand the algorithm now but I can't seem to understand how the object is actually formed.
How can I change this object to create terrain? Are there any better resources on the internet? Thanks in advance.

A:

Marching cubes is an algorithm for polygonizing an implicit surface - i.e. one defined by an equation of the form f(x, y, z) = 0.  You can evaluate any function f(x, y, z) you like, and the algorithm tries to make a polygonal model of the surface formed by the points where the function is zero.
I haven't looked at the source code, but from the screenshot, the test object looks like a metaball, which is a common application of marching cubes.  You could perhaps sculpt your terrain out of metaballs.
Another approach, perhaps better suited for terrain, would be to use a noise function like Perlin noise.  3D noise by itself will just make 3D blobs, but to make it more terrain-like, you could use 2D noise and set f(x, y, z) = noise(x, y) - z.
You can combine noise-based terrain with metaballs, too, just by adding their functions together.  Therefore you could use metaballs to add additional terrain, or negative-weight metaballs to hollow out caves or destroy terrain.

