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'm building a simple OpenGL game and I was looking for some simple collision detection library for objects like squares, triangles and circles. Any suggestions?

PS: Preferably a library that is very well documented and provide examples of 2D collision detections.

share|improve this question
add comment

3 Answers

up vote 4 down vote accepted

Box2D is very popular and well documented with lots of examples. Of course it's a full on physics library so it'll give you a good amount of flexibility for expanding later if you want. But you don't need to use those features if you don't want them.

For learning more about the algorithms and how to implement them yourself you can check this out.

Additionally this is a nice resource for showing how to detect intersections between various shapes. Which plays an important role in collision detection.

share|improve this answer
add comment

I think box2d is best 2d physic engine. Which can easily provide collision detection.

share|improve this answer
add comment

theoretically, you could store the position of the objects you want to detect collision with in an array.

then just have a simple Boolean(or even void if the game is simple enough) to detect whether a collision has taken place between the object your checking and your sprite/other object that could be doing the colliding.

ex:

int checkCollision()
{
for(int I=0; I<maxObjects; I++)
{
      if(object1_x >= object[I] && object1_x <= object[I] + object[I].width )
      {
           return 1;
      }
  return 0;
}
}

this is really messy, but if you want to come up with your own method of detecting collision, you could do something along the lines of that.

I do however recommend using Box2D, much easier.

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.