I am assuming this is a reasonably common problem and am asking for a solution which might be more academic in nature or a general equation used for general problems like this, as apposed to me hacking out what looks to be a very big spaghetti mess.
I want to generate the edges of my tiled world. I have a basic 8 edges. I have an array of ints which represent my tiles. 0 is water and 1 is grass. I would like to add my edges which transition between water and grass. My edges are from 10 to 17.
int edges[3][3] =
{
{10, 11, 12},
{13, 0, 14},
{15, 16, 17}
};
The first thing I think is that this resembles matrices. I know that I have a 3 by 3 matrices object with my graphics library. Are there any standard operations with matrices or with masks to cleverly apply my edges to my tiles?
Is there a standard formula for merging edges? For example if bottom right overlaps with a grass tile perhaps I would just not change its value, however if bottom right overlaps with a top left I want to change that one tile to a grass(0). There are many more individual scenarios and the problem becomes complex.
Since it would require look ahead functionality to add the edges when I generate the grass tiles, I have my edges generate as an additional parse of my tile array. So I am looking for a solution where I can add the edges on to the edges of my grass patches.
This also reminds me of anti-aliasing, I wonder if there is relevant formula in that field.
Ideally the solution would be optimal. For example I would have some kind of mask like the one above and by adding it on to every grass tile in the array I would then get unique values for corners and sides such that I could translate them to edge images.