As seen in the image above, I have a 2D array of tiles, each with 4 points in my game world. I'm looking for a method to convert these shapes constructed from individual tiles into simplified (no unnecessary vertices, only those needed to form the outline) polygon shapes.
I have been looking around, here and elsewhere and have had very little luck. But maybe I don't know the correct terminology to search for. Any help is appreciated.
Extra Info: I'm looking to use this to optimize dynamic lighting. If someone has a different approach for accomplishing fast dynamic shadows in a tile based world, that will also answer the question.
I suggest next algorithm:
For more intuitive representation of algorithm, I posted an image below.
The naive approach would be to simply step through every single tile and mark any transition edges into a polygon but you could reuse a common edge detection routine for better performance.
After that you'd probably be interested in tessellating those polygons so as to convert them into collections of triangles (making the later shadow/lighting/intersection math a lot simpler), the only problem in this case is if you end up with a concave polygon, but a decent tessellator should allow you to break it up into convex polygons. I don't think XNA has anything built in for tessellation so you might need to find a utility library to do it for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With