Collision on rotated Shapes

Hello,

for my JOGL based 2D game (2d sprite textures) I’m going to use some Shape objects (Ellipses, Polygons, etc) for the collision checking. Many of the objects to be tested per frame are non rectangular.
Several classes of the extensive Java2D infrastructure looks attractive for my purpose: they provide ways to check for intersection(), contains(), etc.

Since I’m new to Java2D, three questions please:

1.) Is this approach a good idea?
Or is heavy collision checking with Java2D too expensive/overkill for my non visible purpose, because basically the Java2D classes are tuned for visible objects? (Btw. all my colliding sprites have got an 8bpp alpha channel.)

Since my sprites are being rotated, scaled, and so on, I also need to do this for the collision checking.
2.) Is the correct Java2D approach to use the Area class, feed your Shape to it, apply a transform(AffineTransformation) on it and check it against other area object(s)?
Or is there a (even) simpler way?

IIRC the AffineTransform (AT) is being HW accelarated when the OpenGL pipeline is enabled.
3.) Does this only apply for drawing ATs (to Graphics2D)?
If it does also apply to non visible ATs, it there a way to use it whilst using JOGL at the same time? (I read in the forum that currently using JOGL with the Java2D’s OpenGL pipeline doesn’t work.)

Thanks!

Before I posted, I’ve read the older threads on the topic, of course:

My pixel-perfect collision detection method.
Rotating AABB (algorithm question)
Collision detection for 2d/planar textured polys

External Collision tutorial (from the makers of the funny game “N”, kind of Lode Runer).

Still, I think Java2D could help me with the pre-selection (of what has to be pixel collision tested). Could it? :slight_smile:

I’ve used AWT shapes for collision detection in a both GB1 and GB2. The performance isn’t too bad for limited number of checks (I used a bit of spatial pruning first). Ensure you decouple the collision routines from the rest of the code and you can always swap out later.

Kev

Sounds well, thanks for the answer.
Like you, I intend to do some simple grid based pruning, then bounding sphere intersection tests, then bounding rectangle/shape intersection test, then (maybe) pixel collision.
Do you think my previously mentioned way (2.) to use Java2d’s Area is the correct approach to rotated AWT shapes?

For normal sized sprites, it should work well. For the many large (half screen sized) objects which rotate occasionally, I’m still unsure how to check them. For example {snip; served well}.

I hate you and your lovely graphics :slight_smile:

Kev

:slight_smile: Well, that’s just the talented artist of my project, but you’re a smart programer!

A pity you move across the big ocean! We need guys like you in Europe.

Using Area is the right approach in this case, however,

Tbh, the easiest way is probably to just look up some code to do simple triangle to triangle collision detection. It’ll probably take you all of a few hours to get up and running. Then construct all your collision shapes out of just triangles. In the end you’re going to end up wanting to push the performance to the limits (simply because you’ll want to be able to run on low end machines), your own specified code is bound to be considerably quicker.

I’m still pondering using OpenGL in some way to do the collisions for you, but I think we’ve been round that loop before.

Kev

Thanks.

[quote]however, Tbh, the easiest way is probably to just look up some code to do simple triangle to triangle collision detection. It’ll probably take you all of a few hours to get up and running. Then construct all your collision shapes out of just triangles.
[/quote]
Well, this would be fast and tailor made, indeed.
However… means much additional work for the tons of pixel graphics. I’ll have to argue with the graphic guy (whose spare time hobby project limit’s reached by far).

[quote]I’m still pondering using OpenGL in some way to do the collisions for you,
[/quote]
That would be top. After all, OpenGL touches all pixels anway, rotates them, and so on…

[quote]but I think we’ve been round that loop before.
[/quote]
Yes, indeed, it’s been the previous linked “Collision detection for 2d/planar textured polys” thread, and unfortunately I’ve not found any solution so far.

More points on the growing “to do list”.

Area collision has worked for me in Robo and Rimscape, and it’s never been a bottleneck for me. Of cource I also use a couple of prior collision checking methods before it’s necessary to use. But my polygons sometimes are 8 sided in my checks.