Fractal mountain generation

Started by
5 comments, last by skwee 16 years, 10 months ago
Hello i want to do a random fractal mountain generation. I read about random midpoint displacement algorithm but no i dead how to apply it in my program =I cant draw line cause every time I'm taking mid point of the line so the only way to do it by pixels. But i tried to do it and go sh**. I have no idea how to use this algorithm. I looked over all google and cant find any tutorial in programing language of view not mathematical way, also cant find source or even example.. Thanks a lot.

I would love to change the world, but they won’t give me the source code.

Advertisement
There are two logical steps: first you get an height map h(x,y) by midpoint displacement or any other algorithm, then you render a 3D surface interpolating these height samples.
Three easy ways using lines are:
1) At every grid point, draw a vertical cylinder or a thick line from (x,y,0) to z,y,h(x,y). Can have gaps.
2) Draw lines connecting all samples in each column and in each row of the heightmap.
3) For every rectangle with four samples at its corners, make two triangles with its sides and either diagonal. The resulting triangle mesh can be rendered with suitable colours or textures, possibly with the smoothing trick of using identical (averaged) normal directions for each vertex in every triangle.

Omae Wa Mou Shindeiru

Ok i think I got your idea.
But when i said fractal mountain i mentioned this:

I would love to change the world, but they won’t give me the source code.

So you're looking for a midpoint displacement description or something similar?

For having your terrain look more realistic you could mix some generation methods like the guys from Oddlabs did: http://oddlabs.com/blog/?p=94. They combined a midpoint displacement map with a voronoi map then perturbed it and finally applied an erosion filter. This produces great looking terrain.

If you have generated a heightmap you can render it using the methods LorenzoGatti mentioned.


As for the midpoint displacement method:

Rather than using a recursive approach I'd suggest an iterative approach since this will save you some headaches (e.g. when referenced points/samples are not initialized yet).

The algorithm would look like this:
[soucre]
for each level up to max_level
get the size of the squares in that level (usually size_of_prev_level / 2)
for each row in level
for square in row
do diamond step (calculate the height of the midpoint = sum(heights of corners) / 4 + random offset)
for each row in level
for square in row
do square step (calculate heights of the edge midpoints = sum(heights of edge endpoints and adjecent squares' midpoints)/num_points_considered + random offset)
[/source]
The reason for doing two separate loops is that you need the adjacent squares' midpoints in order to calculate the edge midpoints. You could implement an algorithm that needs only one loop but using two loops is much simpler.


Btw, there's plenty of material on midpoint displacement on the web.
If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!
I think you will fing perlin noise, fBm, and erosion algorithms interesting. Try google ;)
-----------------------------------"After you finish the first 90% of a project, you have to finish the other 90%." - Michael Abrashstickman.hu <=my game (please tell me your opinion about it)
If i understand the OP correct this is about 1D-Midpoint-Displacement and not about generating a heightmap.

I recommend first creating an array with your fractal and then drawing the lines.
Here's some pseudocode:
Start with a single horizontal line segment.Repeat for a sufficiently large number of times { Repeat over each line segment in the scene {  Find the midpoint of the line segment.  Displace the midpoint in Y by a random amount.  Reduce the range for random numbers. }}


regards,
m4gnus




"There are 10 types of people in the world... those who understand binary and those who don't."
Thanks you all ppl :)

I would love to change the world, but they won’t give me the source code.

This topic is closed to new replies.

Advertisement