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.

DarkBASIC Professional Discussion / Simple terrain gen problems

Author
Message
Satchmo
21
Years of Service
User Offline
Joined: 29th May 2005
Location:
Posted: 31st Jan 2011 20:51 Edited at: 31st Jan 2011 20:52
So I came across this easy method of generating terrain through code, here, and have spent a bit of time putting it into dbp. I've been having some erratic behaviour with it however, and I can't seem to get it functioning properly. No matter what I set the terrain height min/max "Rlimit" to, all the values end up being very close to zero, with the odd outlier being around 10 or 15 or so, even if all the values around it are near zero. I'm also having some issues with all the values right on the bottom being exactly zero. One again the site I'm using is http://www.gameprogrammer.com/fractal.html.



Should compile right away, but watch the screen resolution. Anyone is welcome to use this code if we can figure it out btw.

Ty in advanced,
Satchmo

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 31st Jan 2011 23:58
I'm not sure whether this is relevant but it would be safer to ensure that all your types match. For example, you have things like rnd(rlimit#) - but the rnd() command requires an integer argument not a float. The float might be correctly cast to an integer first but it's good practice to be safe.

Have you tried outputting intermediate values, or perhaps a smaller grid, to see where things first go wrong? Shouldn't take too long find the error yourself. For example, have you checked that you are using the correct locations in the array when you do the two main steps?
Satchmo
21
Years of Service
User Offline
Joined: 29th May 2005
Location:
Posted: 1st Feb 2011 00:14
I've gone through the locations a few times but it's possible I missed something, I'll try some experimenting on a smaller grid. Ty for the info about the rnd command I'll test that out.

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 1st Feb 2011 12:24 Edited at: 1st Feb 2011 13:02
Post back if you're still stuck and I'll take a look.

I've successfully coded the diamond-square algorithm before so I ought to be able to spot the problem when I delve into it properly.

But you'll find it more satisfying if you fix it yourself - especially since you've done the main part of the code already.

Edit Couldn't resist taking a quick look.

I suggest you take a close look at your logic. Work carefully through your code for the case n = 1. Does it do what it's supposed to do? I believe it doesn't.
Satchmo
21
Years of Service
User Offline
Joined: 29th May 2005
Location:
Posted: 1st Feb 2011 22:36 Edited at: 1st Feb 2011 22:39
Ty for the support, I managed to "kind of" fix it and it is indeed very satisfying. But I'm still having a problem... I'm not sure whether it's a side effect of the diamond square algorithm or a problem in my code, but I'm getting this artifacts, odd bumps appearing in a pattern across my map. It's using minecraft-style blocks, and while the general terrain shape is there, something is a bit off.



Are these just a result of going from doubles to integers? Or a natural side effect of the algorithm? Or is my code off



This is just the terrain gen code with print out. I'll post the visualizer code if it makes it easier.

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 2nd Feb 2011 20:58 Edited at: 2nd Feb 2011 21:08
Quote: "Are these just a result of going from doubles to integers? Or a natural side effect of the algorithm?"


I doubt it. I suspect a bug in the code but haven't found it yet. I'll keep looking.

Edit May have found it. I suspect you've converted to integers in the wrong place. The following code is a quick fix to your code and works with floats rather than integers:



The above code produces a 256x256 red scale image of your terrain. If you change the type of the "land" array to integer you'll see what goes wrong. That may be part of your problem.

You'll probably notice some strange peaks and hollows. That may be a feature of the basic diamond-square algorithm but could also be the scaling I've used. I didn't try to improve that.
Satchmo
21
Years of Service
User Offline
Joined: 29th May 2005
Location:
Posted: 3rd Feb 2011 02:12
Yup you were right and it works perfectly if I convert it to integers afterwards. Though my problem is fixed I couldn't get your code running, some sort of problem with min max. Are they variables or functions or commands?

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 3rd Feb 2011 02:55
Quote: "some sort of problem with min max"


Oops. Sorry. They are two functions from IanM's indispensible Matrix1 plug-ins. They just return the max and min of their arguments so max(0, -1) is just 0, etc. I've used them to keep the colour values in the range 0 to 255.
omegafold
15
Years of Service
User Offline
Joined: 12th Jan 2011
Location:
Posted: 3rd Feb 2011 06:37
Random terrain?
I just saw this post and thought I might suggest one possibility;
instead of using a fractal/ rnd generator, I have made random landscapes using blender 2.49b; you just make a plane or cube or whatever and then hotkey w to subdivide then move just 2 or 3 points around then subdivide multiple. I found it handy since you can also use the hotkey 'K' to cut sections any way you like, even drawing a line by hand through lots of points. If you click on the mesh tab you can also cut down the polygons using a mesh reducer or something. Tons of landscapes are possible. My fav trick is to make a sharp overhanding cliff or 2 and then hit W then 'smooth' option a few times.
I'm still waiting to see direct x 11 export ability for blender b4 I get this dark basic pro.
Satchmo
21
Years of Service
User Offline
Joined: 29th May 2005
Location:
Posted: 4th Feb 2011 03:52 Edited at: 4th Feb 2011 03:53
New problem! Okay so to reduce lag I've been combining the objects into 9x9 chunks, and laying them out as such. The chunks come out alright but I cant seem to get the height working. I think it's something to do with the positioning being screwed up when I convert from mesh to object.





Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 4th Feb 2011 13:05
I think we need more details.

At first sight your code seems to be making a 16x16 array of objects with each object consisting of up to 8x8x128 = 8192 limbs. Reading between the lines these limbs are cubes stacked on top of each other subject to the value of terrain(h*8-8+x,n*8-8+z,y).otype. However you give no details about that array so it's hard for us to comment.

In this sort of situation I'd work carefully through a much smaller array and see where exactly things go wrong.

Am I right in thinking that it's just the y offset that's wrong?

Actually, the usual order is x, y, z. Is that change deliberate in the terrain array, i.e. x, z, y?
markostalin
15
Years of Service
User Offline
Joined: 4th Feb 2011
Location:
Posted: 4th Feb 2011 13:18
Where have you get these photos from these are huge

Satchmo
21
Years of Service
User Offline
Joined: 29th May 2005
Location:
Posted: 4th Feb 2011 22:13
I am splitting the terrain into a 16x16 grid with each chunk consisting of 8x8 cubes. The physical appearance of the terrain isn't supposed to be any different than before, it's just less objects. The xzy thing is indeed deliberate because I wanted to have x,z,height it just seemed a bit easier but you;re right it's confusing.

The y offset should not be wrong, because for each chunk I create a plain object and offset the cubes from that plain by their height. So each chunk by itself is correct but something seems to happen



right there, almost as if some object info is changed or the pivot point is changed or something, which is what makes this problem so confusing.

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 4th Feb 2011 22:40
Are you sure it's the heights that are wrong? Also, are they consistently wrong in some way?

Are you using the correct vertical scale? Could that be the problem?
Satchmo
21
Years of Service
User Offline
Joined: 29th May 2005
Location:
Posted: 4th Feb 2011 23:58
The height of the chunks seems to be wrong consistently, in that the height of the chunks itself seems to be the opposite of where it should be, (I.e) two pieces of a hill would be at 2 4 instead of 4 2) so you see the hill break in half and go lower even while the chunks themselves show the hill should be going upwards). I'm trying to see if the offsetting has anything to do with this or not.

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 5th Feb 2011 00:28 Edited at: 5th Feb 2011 00:45
That sounds like it's nothing to do with the heights or the offsets as such.

Have you checked that you've been consistent with your use of the x and z coordinates?

Edit As a guess I'd look at the way z varies in your terrain array. Does increasing the z index correspond to decreasing the world z coordinate? That would happen if x and z match the U and V coordinates of a bitmap for example. If so then that would cause your problem. Just change the direction of the z offsets to fix this.
Satchmo
21
Years of Service
User Offline
Joined: 29th May 2005
Location:
Posted: 5th Feb 2011 04:37
Thanks for the help. Turned out not to be a height issue at all I simply was mis using the offset limb command, just needed to invert the offset value.

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 5th Feb 2011 13:26
Yes.

Login to post a reply

Server time is: 2026-07-17 20:39:44
Your offset time is: 2026-07-17 20:39:44