Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I know this is a very typical problem and that there area a lot of similar questions, but I have been looking for a while and I have not found anything that fits what I want.

I am developing a 2D game in which I need to perform collisions between a ball and simple polygons. The polygons are defined as an array of vertices.

I have implemented the collisions with the bounding boxes of the polygons (that was easy) and I need to refine that collision in the cases where the ball collides with the bounding box. The ball can move quite fast and the polygons are not too big so I need to perform continuous collisions.

I am looking for a method that allows me to detect if the ball collides with a polygon and, at the same time, calculate the new direction for the ball after bouncing in the polygon.

(I am using XNA, in case that helps)

share|improve this question
2  
    
That is, the key thing you're probably missing is that "polygons" are just collections of line segments. –  Tetrad May 1 '12 at 15:42
    
what do you mean by polygon that can be a rather broad term considering that a polygon can have anywhere from 3 to infinity sides? what is the concavity of the polygon. are all faces convex, or are some concave? do you want pixel perfect collisions? is the structure of the polygon know to the graphics system (are you using the directX portion, or the XNA portion) –  gardian06 May 1 '12 at 18:32
    
I am concerned about the ball moving too fast. The algorithm you are linking is very good but it covers the case when the ball is moving. –  miguelSantirso May 2 '12 at 9:08
    
I used a sphere tree for this. Very straightforward and works well without having to test the real geometry. –  David Lively Sep 5 '12 at 19:27
show 2 more comments

2 Answers

up vote 2 down vote accepted

The sounds similar to something I was working with and there is no simple answer that could be confined to one post that covers everything. In my opinion you should look into something called separate axis theorem (SAT).

When I was trying to implement it the best walk through I could across was this: http://dl.dropbox.com/u/22121701/Polygon%20collision.rar

It starts with first principles and eventually works it's way up to a full blown rigid body simulator. I only followed it as far as having it accommodate fast movements. It's written for C++, so it would help if you knew C++ however I didn't know it and still don't know it when I implemented it in XNA.

If you can't make heads or tails of it then you may want to look for something a bit more specialised for your case (this is a VERY general approach and will work for most things). If you're REALLY struggling I would be happy to give you MY implementation of it, but there are few comments and it was done when I was learning C#/XNA so it may not be efficient.

share|improve this answer
add comment

Why not simply use the edges and use line to line collision? One line is the distance traversed by you and one is an edge of the poly. Extend each poly line by the width of your sphere in each direction to account for the size of the sphere. Also after a collision has occurred you have all the angle info you'll need to determine the angle of reflection.

Line/Line Collision

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.