Sign in to follow this  
Roldak

2D Array to Polygon

Recommended Posts

Roldak    106
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="http://cardhouse.com/computer/vector.htm"]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
taby    1265
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:
[url="https://commons.wikimedia.org/wiki/File:Marching_Squares_Isoline.svg"]https://commons.wiki...res_Isoline.svg[/url]

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