1

I'm making my own simple 2D-Game's engine and I want to use Separating Axis Theorem to detect collisions but it requires objects to be convex polygons and I would really love to be able to create these polygons in an easy way because every physical object in my game will be required to have its own polygon mapped to it so it would be very painful to create these polygons by hand (by providing pixel coordinates of every vertex of a polygon) for every object.

Is there any better way to do this?

Android developer
  • 1,272
  • 1
  • 12
  • 17
  • 1
    There are many ways to do this. You need to access the pixel data, set some condition that marks a pixel as on the outside edge (ie is next to a transparent pixel) Once you have all the edge pixels trace around the outside edge saving pixel corners as a path. Each separate path will come back to where its started. Then reduce the vertex count by dropping verts that do not fit the convex rule. Or Start at the center, move out radially to find dist to edge. Do that for n times till you have completed 360 deg. Reduce for convex and optimise. – Blindman67 Jun 28 '16 at 19:22
  • Yes, thank you, but I'm not sure if it actually answers my question. Is it necessary to do this in run-time? I can provide mesh of convex polygons in a separate file (separated from .png file of a an actual object), I'm just looking for an easy elegant way to describe game objects' physical bounds that don't have to translate object's actual look in 1:1 proportions. – Android developer Jun 28 '16 at 23:41
  • 1
    Anything you can do at runtime can also be done in production. I don't know what level of details and what type of collisions you are after so hard to give any advice apart from don't over cook the collisions. This link details a fast method I developed http://stackoverflow.com/a/36026906/3877726 for collisions by creating a radial map of the objects allowing for very quick collision tests. It describes how to get the perimeter which might be of use to you, – Blindman67 Jun 29 '16 at 00:15

0 Answers0