If you had the polygons all convex, you could do GJK for collision detection or Minkowski portal refinement: http://xenocollide.snethen.com/mpr2d.html. Even so, these are somewhat complex algorithms and they're limited to convex polygons.

If you want concave polygons (as you show in the screenshot), you're best bet is to decompose them into sets of convex polygons (such as triangles).

This is a HARD problem. My best bet is for you to use some physics engine (like JBox2D) and use the collision detection code from that. You can use collision detection from a physics engine without using it for movement usually fairly easy.

I'm wondering about treating the polygon a series of Line2D.Float objects. There is a function on Line2D that returns a boolean if the line intersects any any part of the interior of a Rectangle (your ship, presumably). Or would this be too slow? (I'm noticing you have a really fast FPS going!)

Also, when you mention false positives due to being off by +50, I wonder if the rotation is happening exactly like you think it is. It is easy to mix up whether the rotation is occurring from a midpoint or topleft corner or whatever. An error that is off on only one side and similar in size to the object being rotated is kind of suspicious in this regard.

So, I'm having trouble understanding how you are representing the enemy object. It's a series of vectors that are subject to rotation, rather than an actual Polygon object? How are they drawn? Are lines extracted at the point of drawing? If so, perhaps the same lines can be used for collision detection.

I'm wondering about treating the polygon a series of Line2D.Float objects. There is a function on Line2D that returns a boolean if the line intersects any any part of the interior of a Rectangle (your ship, presumably). Or would this be too slow? (I'm noticing you have a really fast FPS going!)

Go the whole hog: Path2D.Float.intersects. It would need profiling, but if it performs well enough then getting the standard library to do the work is always a good plan.

If collision detection is what you want, line-line collision tests are cheap. I posted some code in shared code about the quickest method. This is not the same as the distance until collision though.

You can also calc the centroid of the polygon and cache it, as well as a circular bound or radius, then just do distance checks of each poly's centroid to the other's and see if it's less than the sum of the radii. In my straightedge project there's a KPolygon class for this.

I hope you only want discrete collision detection.Continuous CD and/or collision response will make your ears bleed. (though CCD does make CR a little easier)

I recall an excellent tutorial on the algorithms for detecting collisions between various primitive types(based around Separating Axis Theorem); let me see if Google can find it.....Hmm, THIS isn't what I was looking for - but it might very well come in handy to you.

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org