2D Polygon Collision
Hi guys,
Ok, I''m basically looking for a bit of math-y info/advice. I''m currently writing a little game where I use rotated sprites. The collision detection needs to be pretty accurate, and so I want to give each sprite a surrounding polygon, and then rotate this as I rotate the actual sprite.
Thus, I aim to perform the collision detection on the 2 (rotated) surrounding polygons.
Now I''m not a math head, and I was wondering if someone could explain the basic maths of this. If it helps, I''m pretty sure I won''t need any polygons of greater sides than 4.
A nice explanation would be very much appreciated
Thanks,
--
Russ
I haven''t done this before, but I''d imagine you''d take the current motion vector and predict ahead for the next frame, and if that point was within any of the other polygons, set motion to stop.
___________________________Freeware development:ruinedsoft.com
Hi,
Yes, I understand this... what I want info on is the actual maths in checking whether the two polygons collide.
Cheers
--
Russ
Yes, I understand this... what I want info on is the actual maths in checking whether the two polygons collide.
Cheers
--
Russ
May 31, 2000 02:08 PM
This is something that I''ve worked on for my project also, and is trivially easy or rather difficult depending on how far you want to go. Consider :
1) If you want your bounding polygon to be a rectange, things are easy. There are two variants, Axis-Aligned-Bounding-Boxes (AABB) that don''t rotate with your object, and OABBs, which you can imagine, are object-aligned bounding boxes, which rotate with your object. Sounds like you want the 2nd option.
2) If you want an arbitrary convex (or even concave) polygon for bounding, things get tough. This is the option I''m pursuing, and running into a great deal of math that I never really wanted to know doing so. Convex polygons seem to be easy, but concaves I haven''t found a simple solution for.
The other consideration is if you just want to know if they''re colliding, or if you want to know specifically WHERE they''re touching. The first is easy -- a point-in-poly test should do the trick. THe second is not easy.
I worked out the proper code for checking both cases before, but I''m at the uni now and don''t have it on me. Perhaps someone else could post their rectangle intersection code for you?
1) If you want your bounding polygon to be a rectange, things are easy. There are two variants, Axis-Aligned-Bounding-Boxes (AABB) that don''t rotate with your object, and OABBs, which you can imagine, are object-aligned bounding boxes, which rotate with your object. Sounds like you want the 2nd option.
2) If you want an arbitrary convex (or even concave) polygon for bounding, things get tough. This is the option I''m pursuing, and running into a great deal of math that I never really wanted to know doing so. Convex polygons seem to be easy, but concaves I haven''t found a simple solution for.
The other consideration is if you just want to know if they''re colliding, or if you want to know specifically WHERE they''re touching. The first is easy -- a point-in-poly test should do the trick. THe second is not easy.
I worked out the proper code for checking both cases before, but I''m at the uni now and don''t have it on me. Perhaps someone else could post their rectangle intersection code for you?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement