• entries
67
89
• views
51835

340 views

# Playing with the random values.

Okay, so I didn't get onto displaying the heightmap in a 3d view yet. I've been messing around with my class structure and the random offset generator I use for the height displacements. Mainly this is because I realized that I haven't set it out very well for generating portions of the map at a time. My ideal is to be able to generate the top few subdivisions at map-load and be able to "page" in higher-detail sections for when the player zooms in on particular spots.

I wasn't particularly happy with the method I was using for the random displacements. What I have now I feel is much better. Before I was working with a hard-coded height offset that would be multiplied by a dampening weight on each subdivision iteration. I found this to be too fiddly, so I came up with a much simpler setting. The algo I'm using for setting the midpoint height is:
1) Get average (A) of surrounding height values (shape depends on whether we're in the diamond or the square step of the algo).
2) Get maximum difference (D) between the average and the surrounding height values.
3) Get pseudo-random number (P) between -1.0 and 1.0 for the heightmap coordinate.
4) Height value = A + (D * P * R) where R is a "roughness" constant.

Different values of R give (you guessed it) varying degrees of roughness to the terrain. I could use a particular constant for an entire map, but I also plan on allowing the user to set the constant on a per-seed-cell basis (so you can make some spots on the map rougher and some smoother). Here is the output of 3 iterations, using different values for R:

R = 0.4F

R = 0.6F

R = 0.8F

R = 1.0F

R = 1.5F

There are no comments to display.

## Create an account

Register a new account