# Diamond Square

This topic is 4091 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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

##### Share on other sites
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

##### Share on other sites
hmmm mrcheesewheel, that idea got me thinking. That concept sounds a lot easier. I'll do that! Thanks!

##### Share on other sites
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?

##### Share on other sites
There are some decent terrain tutorials here: http://www.riemers.net/

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

##### Share on other sites
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.

1. 1
2. 2
3. 3
Rutin
15
4. 4
5. 5

• 10
• 9
• 9
• 11
• 11
• ### Forum Statistics

• Total Topics
633682
• Total Posts
3013309
×

## Important Information

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!