View Full Version : How to test for collisions?

25-06-2003, 10:04 AM
I just started learning OpenGL and it doesn?_Tt seem too hard. One thing that I have absolutely no idea how to properly do is collision detection in 3D, the only half decent way I can think of is using a load of bounding boxes grouped in larger and larger boxes, but that way the form of the world would be very limited. Maybe someone has some ideas for a universal method of testing collisions?

31-07-2003, 01:36 PM
There are several ways of doing this. Of course bounding boxes and bounding spheres are the most important elemts of collision detection. They are fairly fast, easy and usefull. For example it is usefull to pre-check. Use a big sphere to check, if the object had been hit, use smaller spheres or boxes to check the exact part that had been hitting. I also can point to a piece of code that was contribute for our site:
http://www.phobeus.de/hosting/dgl/main.php?page=downloadinfo&f=3051 The source
http://www.phobeus.de/hosting/dgl/main.php?id=2&page=tutorial&tut=obbtetris&print=1The Description to it, two links are at the bottom.

Maybe you can find something usefull ;)


31-07-2003, 07:25 PM
Funny you mention this,.. I'm currently teasing my brains with a 2D pixelperfect collision detection routine (in opengl), for about an entire day now. It's harder than I thought. http://www.gameprogrammer.net/pics/outside/banghead.gif

Anyway, perhaps lesson 30 on nehe's (http://nehe.gamedev.net) site, might be useful to you.

19-06-2004, 08:31 AM

How did your PixelCorrect Collision Detection work out??

Can you give me some code?

19-06-2004, 11:04 AM
It didn't :(

The collision detection routine was supposed to be for my entry for the 2003 remakers competition. However i did not finish it on time and the project was abandoned.

After that I never laid eyes on the code again. But I will in a few weeks as I'm going to need it for my current project.

19-06-2004, 12:58 PM
I think that pixel perfect 2D collision detection is useless, a much better approach speed wise would be to hierarchically approximate images with many circles.

19-06-2004, 04:02 PM
I think for my needs, pixel perfect collision is the best way.

Can you get hold of the pixels in openGL?
Like .pixels(x,y) -> color of the pixel

19-06-2004, 04:39 PM
Can you get hold of the pixels in openGL?
Huh? You can read back from the frame buffer, but it is horribly slow and what would you do with that? OpenGl is a rendering API and it won't help you with collision detection. To do pixel level collision detection you would need to keep all you're images pixels(or just their corresponding IsCollidable values) in system memory, transform one images edge coordinates to the other ones local space and go through both images looking for IsCollidable values. The only situation in which this method wouldn't have to perform billion's of operations is if you're images would have constant orientation, but since you're using OpenGl it is very unlikely that you wont want to do rotations and such.