I am working on writing a .NET application that will be used to generate a map. The idea is to create a bump map that can be used as a height field in a GIS application for fantasy worlds (for gaming).
What I want to be able to do, is to create a grid of X x Y proportions and then using the colour values of 000-000-000 through to 255-255-255 to set the altitude at any of the cells within the grid.
The grid starts out with all values at 125-125-125 and then through a process of randomly changing the altitude, I hope to end up with a height field that is “realistic”.
One of the challenges here, is that to change the altitude of a single cell, I need to know what is going on with it’s neighbours (North, North East, East, South East, South, South West and West), so that the change in altitude reflects the neighbouring cells altitude.
To work out the neighbouring cells, I made this spread-sheet in MS Excel:
The grid is simply a 10 x 10 grid of incrementing numbers. The cells have a bunch of conditional formats applied to them so that I can see what is being picked.
P1 is just a simple equality formula, where I pick the cell that I want as the reference cell. In the above example, it is F6.
I also want the grid to wrap on the X axis but not the Y axis, so that it is a cylinder, rather than a sphere. When the reference cell is < 10 the North values are –1 and when it is > 90, the South values are also –1.
North West
North
North East
East
South East
South
South West
West
So when I change the reference cell to, say B2 I get:
and when I change it to K2, the grid looks like:
So, it wraps the way that I planned. The formulae are probably not as elegant as they could be … but they will do for now.
When I tell my program to increase the altitude of a given cell, the formula will take the average of the surrounding cells and then add the increasing value to the reference cell.
I also want to have the program increase altitude in a radiating way. That is … poke the surface. If the increase in value is going to be, say, 10, then the reference cell has 10 added to it, while the surrounding 8 cells will have 5 added to them. If the program repeats this operation on random cells and with random altitude changes, then I should end up with a bumpy map. The same will happen for reductions in altitude: –10 for the reference cell and –5 for the surrounding cells.
So far, the tool generates the height field and does the initial random altitude change:
At the moment, everything averages down. It seems that the process is currently only reducing the cell values, rather than increasing them. I will have to work out why that is happening … it could be my calculation of the average values … not sure yet. Also, the GUI that I’ve built for this allows me to turn the major and minor grid lines off, so that it looks less like a shower recess.
Anyway, that’s where I am with the terrain generator for now.
No comments:
Post a Comment