Jump to content
  • Advertisement
Sign in to follow this  

2D Array to Polygon

This topic is 2754 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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 article 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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!