I was thinking about writing an algorithm that would convert a a strictly black and white .gif image into a b2Poly (or rather, several). I was happily coding away for a few minutes until I realized my naive algorithm would never work.
The idea was to find the first black pixel (moving from left to right, top to bottom) and then call a recursive function that would trace around the black blob. I was going to simply move left until I hit a white pixel, and if I couldn't move left, I'd move down, then right, then up... and hopefully it would eventually get back to the start. However, there are two problems with this... (1) It would end up filling in the shape, which we don't want to do, and (2) Box2D only excepts convex shapes (for now).
If I were to only draw convex shapes... does anyone know how we might trace them? I'm sure other people would find this useful. Would be an easy way to create maps for games.
The idea was to find the first black pixel (moving from left to right, top to bottom) and then call a recursive function that would trace around the black blob. I was going to simply move left until I hit a white pixel, and if I couldn't move left, I'd move down, then right, then up... and hopefully it would eventually get back to the start. However, there are two problems with this... (1) It would end up filling in the shape, which we don't want to do, and (2) Box2D only excepts convex shapes (for now).
If I were to only draw convex shapes... does anyone know how we might trace them? I'm sure other people would find this useful. Would be an easy way to create maps for games.
