0

I'm trying to make a collision detection routine between circles (that coagulate), being very new to this I firstly made a detection that checked every single circle. Now I had the idea to create some sort of bounding boxes in order to only check more precisely the circle that are close enough (more efficient when there is a group of coagulated circles).

Now for a more precise detection after I selected the objects to take a closer look at is there someway that openGL can see if two objects are overlapping by detecting pixel overlapping ?

Other tips for making a bit more optimized collision detection are welcome :)

Thank you.

2 Answers 2

3

OpenGL has no such built-in functionality, though you might be able to bastardize the "Feedback" render mode in older (<= 2.1) versions of OpenGL.

That said, for the special case of circles, there's a much quicker way to look for collisions. For a candidate pair of circles, if the distance between their centers is less than the sum of their radii, they overlap. Even quicker, you can use squared distances & avoid a sqrt().

1
  • Yes, I'm using that but because the circles coagulate I'm going to compute the distance from the center of the group to the furthest circle, and then as if the group is a big circle (distance from center to furthest circle) and if it's overlapping with another group or circle I'm checking more precisely.
    – DennisVDB
    Apr 26, 2012 at 21:38
0

there someway that openGL can see if two objects are overlapping by detecting pixel overlapping ?

OpenGL has no collision detection routines.

OpenGL has selection buffer that could be used to get list of object rendered in certain region, but that won't be useful, because to detect overlap, you'll need to know region in which overlap can occur.

By abusing stencil buffer you could get a list of pixels that overlap (and how many objects were drawn over certain pixel), but for that you'd have to read data from stencil buffer and iterate through every pixel manually. It'll be faster (10..100x times) to simply check for circle collision manually. Unless you use 8 objects or less, you won't be able to use stencil buffer to determine which objects were drawn over a pixel.

Other tips for making a bit more optimized collision detection are welcome

Use trees or "sweep and prune" algorithm.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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