Sign in to follow this  

2D Array to Polygon

Recommended Posts

Hello everyone,

I am currently making a game, in which a map is randomly generated.
The map is just a common 2D array of integers. (0 if empty, 1 if dirt, rock, etc)
After the generation I would like to "polygonize" the map, so that I can have a list of vectors instead of the 2D array.
I have searched a bit and I found it was almost the same thing as making a vectorial image from a bitmap one.
Then I found an [url=""]article[/url] about this, but I didnt really get all of it, probably because my english is pretty poor as you might have noticed.

So, anyone who could give me some hints or explain me approximately what the article says would be welcome.

Thank you.

Share this post

Link to post
Share on other sites
Marching Squares may be a good algorithm for the job. It may not be precisely what you want, but it can easily take a 2D bitmap and convert it into what is basically a set of triangles.

Check this out:

See how it draws an isoline between the light and dark parts? Is this what you want? If so, then try Marching Squares. The isoline is basically just the edges that belong to only one triangle (ie. edges that aren't shared by two triangles).

I have a full code available if you want to look at it. It's ridiculously tedious, but also ridiculously simple to grasp.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this