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/DBC/GDK] Simple terrain generation using recursion

Author
Message
Pharoseer
17
Years of Service
User Offline
Joined: 21st Feb 2007
Location: Right behind you
Posted: 8th Feb 2008 03:32 Edited at: 8th Feb 2008 03:36
Hey gang,

I just thought I'd post this since I just verified that it works for all three (yep all three) development environments. The DBP/DBC code is identical. The DGDK code is nearly identical. To save space, I'll include all of the code in a single post.

The technique is based on the Midpoint Displacement Algorithm that I learned back when I was in college working on transputers. Anyway, that isn't important. What is important is that you can make some pretty cool heightmaps for your terrains with very little effort.

You may have to run the app a few times to truly see the versatility of this technique, but I'm sure that someone will find it useful. Feel free to use it if it helps!

-Frank

Here's the screenshots:



And here's the code:

[DBP/DBC code]


[Dark GDK code]
Toz
16
Years of Service
User Offline
Joined: 14th Oct 2007
Location: The Netherlands
Posted: 8th Feb 2008 09:25 Edited at: 8th Feb 2008 09:26
I'm sorry to tell you this but your code snippet is bassicly the same as the advance terrain commands in dbpro. Might be handy for the people who own dbc though (or do they have AT as well?). I must say you have a good style of coding though .

Don't read this, read the above.
Pharoseer
17
Years of Service
User Offline
Joined: 21st Feb 2007
Location: Right behind you
Posted: 8th Feb 2008 09:47
Thanks for the compliment on my coding style. I try to keep it neat.

I don't think that the Advanced Terrain commands CREATE their heightmap. You have to make one yourself and then load it in. The code I posted is highlighting a method of CREATING a natural looking heightmap. You could then use that heightmap with whichever "ground" type you prefer.

Still, I appreciate the comparison. If I'm mistaken about advanced terrains though, let me know. It'd save me a ton of time.

-Frank
Toz
16
Years of Service
User Offline
Joined: 14th Oct 2007
Location: The Netherlands
Posted: 8th Feb 2008 10:14
Quote: "I don't think that the Advanced Terrain commands CREATE their heightmap. "


Oh...forgot to mention that part. Thats a pretty nifty algorithm for generating a heightmap, I always knew you could use functions in that way but never really found a practical use for it. Any way I would still use advance terrain instead of matrices because AT is way faster because of the build in frustum culling.

Don't read this, read the above.
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 8th Feb 2008 11:27
@Pharoseer

That's really nice (using DBC). Those are some great functions! I would suggest changing the influence of a single variable 'size' on all aspects of the terrain generation. I think for the height map itself, it should remain at 256x256. As far as the matrix, the function to generate it should have flexible parameters, for x and z size as well as number of tiles. Also a height factor would be a nice inclusion.

Since you are maxing the size of the matrix to 64 x 64 tiles, are you using the whole height map, or just one corner of it?

Enjoy your day.
AndrewT
17
Years of Service
User Offline
Joined: 11th Feb 2007
Location: MI, USA
Posted: 8th Feb 2008 21:20
Quote: "Any way I would still use advance terrain instead of matrices because AT is way faster because of the build in frustum culling."


I don't think that Pharoseer made this to use the actual terrain matrix in-game, I think it's being used exclusively to generate heightmaps for use with something such as AT. At any rate, this is a very nice tool!
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 9th Feb 2008 00:25
Quote: "I don't think that Pharoseer made this to use the actual terrain matrix in-game"


That makes sense. The focus is on the height map creator. What one does with the generated height map is up to them. Now I get it.

Enjoy your day.
Pharoseer
17
Years of Service
User Offline
Joined: 21st Feb 2007
Location: Right behind you
Posted: 9th Feb 2008 01:35
Yep, you guys are exactly right. I don't mess with DBC much, so I don't know if they have any alternatives to the matrix. That's why I chose to use it for showcasing the heightmap. Sort of a "lowest common denominator" deal.

Another tip is that if you modify the call to randomize (or dbRandomize() for the GDK) and specify a constant value (3, 4 whatever) you can make a terrain that should be the same on any computer every time the app is run.

-Frank
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 12th Feb 2008 19:48
That's excellent Pharoseer
Just the sort of thing I'm trying to learn
Doing a little search I found this page that explains some fractal algorithms and other procedural stuff
if anyone else is looking for that kind of thing here is the link
http://www.gameprogrammer.com/fractal.html

Tiomun
16
Years of Service
User Offline
Joined: 31st Jan 2008
Location:
Posted: 28th Feb 2008 02:01
hey nice pharoseer. its kinda like that little app i wrote but 1 mill times better lol. I like how natural the terrain looks. awesome work

Login to post a reply

Server time is: 2024-03-29 11:28:36
Your offset time is: 2024-03-29 11:28:36