• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1004
  • Last Modified:

Terrain generating....help

Could someone point me the right direction in the way to make a algorythm to generate a random map (with % of mountain, lakes, forest, etc.), I don't use MFC, but the game is starting to implement Windows programming stuff, so if anyone has links to tutorials, I would appreciate...

I had the idea to use fractal generating for the map, but then I can't specify the % of terrain type wanted....  
David MacDonald
David MacDonald
1 Solution
If you are trying to do this on-the-fly during your program, this tip won't help.  But if you'd like to generate 3D terrain before the fact, I'd really suggest checking out Bryce (formerly produced by MetaCreations, now owned by Corel).  9 months ago I wrote a simple program to generate terrain and just 2 weeks ago I found that Bryce does everything I originally wanted and oh so much more.

There are also a lot of rendering features such as textures and effects, but the actual terrain modeling tool is what I use it for.  There are several pre-packaged filters for different effects (water, lava, fractals, mountains, crystals, to name a few).

The real-time editing is done through a 2D bitmap & paintbrush, while the 3D preview version is shown using some kind of volume-rendering.  When you achieve the terrain you're going for, you accept the preview and it is tesselated into 3D polygons for you.

So far I haven't found any controls over the polygons that are created (which is necessary when concerned with 3D game performance) so another 3rd-party application might be needed for optimizations (Blender?, 3D Studio Max?).

Anyway, I hope this helps you out.
David MacDonaldChargé de projet processus d’affaires et systèmes TIAuthor Commented:
Thanks, your tip gave me an idea about another concern we had about the game, but the maps have to be generated during the program. Basically what we are doing is kind of an old type rpg sim game. The user will be asked what kind of terrain he wants, so the maps have to be generated on demand....
This site has a few links which might be helpful:

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

why don't you like fractals?
you may generate fractal different elevation (height) map; so low is lakes, high is mountains, and then randomly create some forests
David MacDonaldChargé de projet processus d’affaires et systèmes TIAuthor Commented:
It's not really that I don't like fractals (I love em...hehe)... but I can't think of a way to generate a fractal with a % of land, mountain, sea..etc.


I've looked at the site....pretty nice... it gave us an idea about another game we hope to make soon.... but the terrain we want for the present game is a 2D map..... more like a gameboard...
but thanks a lot...this link as been bookmarked...:)
You can use fractals and still exert some control over what percentage of the map is water, what percentage is mountain, what percentage is plains, etc.

To explain how, let me first briefly outline how a fractal map would be generated in the first place.  You probably already know this, but just in case...

The usual procedure is to assign random (or pseudo-random) numbers to the corners of the map.  This gives you a single large rectangle with values for each corner.  Now you subdivide that rectangle into 4 quadrants.  

To get the values for the new points of the 4 quadrants, you interpolate the corner values of the rectangle you just subdivided, then another random value is added to the result.

The magnitude of the random value that gets added is weighted by how many steps of subdivision you have done so far, so that in the early stages of creating the map, the random numbers may be large, indicating large changes in terrain.  In later stages of map creation, the random numbers are smaller, which would indicate more gradual changes in terrain.

This is one place where you can control your resulting map.  By changing the weighting of the random value according to how many subdivision steps you've done so far, you will get different types of landscape.

The subdivision process is repeated until you get down to the point where you can't subdivide any more because you can't split a pixel in half.

Now we get to how to control the map output.  If you want to specify certain percentages of certain terrain types, then instead of simply assigning random numbers to the map, select values that indicate the desired type of terrain.  

Instead of simply assigning the original 4 corners, you'll start out by subdividing the map into smaller sections right from the beginning.  For example, if you have a 256x256 map, then breaking it down into 16x16 squares will give you 256 points to set.  By selecting 256 values that are weighted towards your desired percentages of each terrain type, this should give you the control you want.

It may also be that doing an initial 8x8 grid with 64 seed values gives you fine enough control.  You'll have to experiment a bit.

By the way, when you assign your initial 256 values (or 64 values, or whatever) you might want to set two adjacent points to the same value.  This would give you a better guarantee that a particular area will show the desired terrain type.  If you set just one point, then the surrounding points could still be drastically different, and you might not get the desired result.  It's something you'd have to play around with a bit.

Another thing to consider is that you might want to specify terrain using two values instead of one.  The most simple fractal landscape generation uses a single value and presumes that everything below a certain threshold is in water, and everything above another threshold is snow-capped mountain.

There's no reason you *have* to do it that way.  You could use two values.  One would indicate the basic terrain type, such as water, grassland, forest, desert.  A second value would indicate elevation relative to the terrain type.  The combination of the two values would allow you to do things that a single value wouldn't allow, such as having a lake in a mountain valley.

Well, I hope this helps.
David MacDonaldChargé de projet processus d’affaires et systèmes TIAuthor Commented:
Adjusted points from 40 to 50
David MacDonaldChargé de projet processus d’affaires et systèmes TIAuthor Commented:
Answer accepted
David MacDonaldChargé de projet processus d’affaires et systèmes TIAuthor Commented:
Altough I do not understand all of it, I think I grasped much of the concept....

I'll try this one.... thanks mike!!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now