Jump to content
  • Advertisement
Sign in to follow this  
Roldak

2D Array to Polygon

This topic is 2290 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
Advertisement
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:
https://commons.wiki...res_Isoline.svg

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!