Diamond Square

Started by
4 comments, last by Numsgil 16 years, 6 months ago
I've done on and off atempts at fractal terrain and just CAN'T get it. I understand the concept, just can't implement it, especially figuring out how to move on to another iteration. Could someone give me some basic code or an example to build off? I just cant get it, even after at least a few months researching it. I'm sure it's something really simple I just don't see, but please help. Thanks! -Regards, Brandonman
Advertisement
Well there are numerous approaches to fractal terrain that you can take... One can make a true fractal noise (eg perlin) to generate a terrain directly or iterate an initial mesh to produce a terrain. A Fractal noise can produce an infinite terrain whereas an iteration produces a finite one. The easiest iteration I have used is as follows:
1. Pick a point at random on the terrain you're generating
2. Make a random vector
3. For each terrain node, dot product the random vector with the vector from the randomly chosen point to that node.
3.a If it's positive, raise that node by some set ammount
3.b otherwise lower that node by a set amount
4. Goto 1 until you are happy with the terrain
5. Possibly normalise, smooth, apply curves, contrast, offset etc as a post process.

This is very simple mathematically and can also be programmed efficiently. The size of terrain required and efficiency of the algorithms (your implementation of this vs fractal noise) determine how large your required terrain should be before the fractal noise becomes a better option. Neither are that complex and I'm sure you can find information about both with a bit of searching.
Good luck,

Dan
hmmm mrcheesewheel, that idea got me thinking. That concept sounds a lot easier. I'll do that! Thanks!
Now that I'm thinking, random terain wouldn't be very useful in a fps/rpg game... Be impossible to have cities. So, how can I do heightmaps? I understand you load the pixels into a 2d array, but how?
There are some decent terrain tutorials here: http://www.riemers.net/

The tutorials are using XNA and C#, but the concepts pretty clear.

You can have cities, you just need to apply a "flatening" algorithm to the heightfield after the noise is finished. Build up your city building by building, "flatening" the ground along the way to build the foundations. The foundations only need to be level individually, there's nothing stopping you from building a city on a huge slope. Then you could have sloping streets, too, which open up interesting possibilities for FPS especially (use height advantage to throw your grenade effectively further than your opponents).

Of course, this is a whole level of complexity you might not want to wrestle with if you're having problems with the basic noise terrain.
[size=2]Darwinbots - [size=2]Artificial life simulation

This topic is closed to new replies.

Advertisement