Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / [DBP] 2D Mountain/Landscape Generator

Author
Message
enderleit
16
Years of Service
User Offline
Joined: 30th May 2007
Location: Denmark
Posted: 12th Aug 2009 01:54 Edited at: 12th Aug 2009 01:55
Hey guys,

I am having troubles with the Diamond-Square algorithm, which is why i started messing about with this simple program, and it has helped my understanding of how it works alot, so I decided to post it here for others to maybe learn a little from.

It's basically the first step on the road to learning the Diamond-Square algorithm to make a heightmap for 3D landscapes, or clouds.

The program generates an array of height-values that looks like a landscape or mountains if drawn as series of dots.
The next step is ofcourse to generate a 2D array to use as a heightmap for 3D terrains.

I have commented the code as best I could, although I'm not always great at making good comments.
If you have any questions about this snippet, go ahead and ask.

EDIT: Forgot to put the code in!



- enderleit
[href]www.eleit.dk[/href]
Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 12th Aug 2009 18:40
Nice example.

Making terrains can be a pain, making realistic terrains can be impossible for some - if you can reduce the amount of editing down to say, a 16x16 grid then use that to create big terrains then you can save tons of space. For instance a 512x512 terrain needs about a megabyte, whereas a 16x16 terrain with a perlin calculation would only need a kilobyte, in other words 1000 times smaller.

Might be cool to see a seed based terrain generator like this in a Worms game. Thanks for posting such a well commented and efficient example.


Health, Ammo, and bacon and eggs!

Login to post a reply

Server time is: 2024-05-05 00:43:34
Your offset time is: 2024-05-05 00:43:34