Collision Detection?

Started by
11 comments, last by b34r 18 years, 8 months ago
I'm looking for a way to detect when a vector collides with an object in my program. I could build lower polygon collision meshes, but i am not sure if there is an opengl mesh that supports collision detection (im only a week or so into opengl). i thought i could also just do box collision but i dont know how to do that when using vectors or rays, let alone having the box and the vector translated and rotated to their respected positions. What do you guys use for collision detection? A point in the right direction would really help. Cheers, Chris
Bow before me... for i am l33t!
Advertisement
Hello Pirosan,
The only thing that OpenGL does is rendering, nothing more, nothing less.
It does not provide things such as collison detection.
And I can't help you with your questions about collison detection, because I just don't know.
Hylke
There's actually some good info on this site:

http://www.gamedev.net/reference/articles/article736.asp

But, there are also some great commercial/open source libraries out there to do collision detection if you want to go that route. Most of the algorithms are very simple, they just have more complicated things that go on top of it (elasticity, angle of reflection, deformation, etc, force vectors, etc), but the gamedev link goes over the basics pretty well. Grab a college physics book and go over reflection and refraction; collisions follow a lot of the same rules, even if the percentages and such are different.

Hope that steers you in the right direction, ask if you need more help.
Colision between a vector and a plane is pretty simple:
plane ABC is define by
A+uAB+B+vBC
a vector OP by
O+wOP
then intersection is given by resolving equation
A+uAB+B+vBC=O+wOP == A+uAB+B+vBC-O-wOP=0 or the system
uxAB+vxBC-wxOP=xO-xA-xB
uyAB+vyBC-wyOP=yO-yA-yB
uzAB+vzBC-wzOP=zO-zA-zB


put it in matrix form and you just have to resolve a simple
3*3 matrix M
MX=B
if plane is bounded ( triangle ) put constraint on u and v (0<u<1 and 0<v<1 )(and then u+v<1(I've forgotten that:)...this isn't a parallelogram) )
if vector is bounded ( segment ) put constraint on w ( 0<w<1 )

you'll notice you'll must give a tolerance on collision on the edge with a TETA(tiny float) in your constraints cause ther'are lake of precision due to approximations in computations


For more theory infos=> http://www.geometrictools.com/Books.html (see Books samples)

Sorry i will complete that post later when i will have more time

[Edited by - mp3butcher on July 26, 2005 2:45:08 PM]
Quote:Original post by mp3butcher
Colision between a vector and a plane is pretty simple:
plane ABC is define by
A+uAB+B+vBC
a vector OP by
O+wOP
then intersection is given by resolving equation
A+uAB+B+vBC=O+wOP == A+uAB+B+vBC-O-wOP=0 or the system
uxAB+vxBC-wxOP=xO-xA-xB
uyAB+vyBC-wyOP=yO-yA-yB
uzAB+vzBC-wzOP=zO-zA-zB


put it in matrix form and you just have to resolve a simple
3*3 matrix M
MX=B
if plane is bounded ( triangle ) put constraint on u and v (0<u<1 and 0<v<1)
if vector is bounded ( segment ) put constraint on w ( 0<w<1 )

you'll notice you'll must give a tolerance on collision on the edge with a TETA(tiny float) in your constraints cause ther'are lake of precision due to approximations in computations


For more theory infos=> http://www.geometrictools.com/Books.html (see Books samples)

Sorry i will complete that post later when i will have more time


Don't you need an extra constraint u + v < 1 to ensure that the point of intersection lies inside the triangle? Also, I never work using matrice like this, so I'm very interested in how good this method would perform against a traditional 'intersect plane', 'point-in-poly', etc method performance-wise... My first impression is that it hardly benefits from early exit but if all tests were to pass, wich would be faster?

[Edited by - b34r on July 25, 2005 10:32:06 AM]
Praise the alternative.
good thing i asked rather than looking around in opengl references for a collision detection function. This has saved me a lot of time.

I will look into that website and/or try out that technique.

One of my thoughts was to use the vector in box technique because it would allow me to create collision boxes on the fly, but if that box rotates its no longer that simple... Any ideas?

Thanks for your input so far!



Chris
Bow before me... for i am l33t!
Quote:Original post by Pirosan
good thing i asked rather than looking around in opengl references for a collision detection function. This has saved me a lot of time.


Not intended as flame, but you would have saved even more time by looking in the forum FAQ rather than posting and waiting for a reply ;)
Anyway, hope you get it working :)

Regards,
/Omid
Best regards, Omid
Quote:Original post by b34r
Quote:Original post by mp3butcher
Colision between a vector and a plane is pretty simple:
plane ABC is define by
A+uAB+B+vBC
a vector OP by
O+wOP
then intersection is given by resolving equation
A+uAB+B+vBC=O+wOP == A+uAB+B+vBC-O-wOP=0 or the system
uxAB+vxBC-wxOP=xO-xA-xB
uyAB+vyBC-wyOP=yO-yA-yB
uzAB+vzBC-wzOP=zO-zA-zB


put it in matrix form and you just have to resolve a simple
3*3 matrix M
MX=B
if plane is bounded ( triangle ) put constraint on u and v (0<u<1 and 0<v<1)
if vector is bounded ( segment ) put constraint on w ( 0<w<1 )

you'll notice you'll must give a tolerance on collision on the edge with a TETA(tiny float) in your constraints cause ther'are lake of precision due to approximations in computations


For more theory infos=> http://www.geometrictools.com/Books.html (see Books samples)

Sorry i will complete that post later when i will have more time


Don't you need an extra constraint u + v < 1 to ensure that the point of intersection lies inside the triangle? Also, I never work using matrice like this, so I'm very interested in how good this method would perform against a traditional 'intersect plane', 'point-in-poly', etc method performance-wise... My first impression is that it hardly benefits from early exit but if all tests were to pass, wich would be faster?


which early exit would can be??
I wrote that algo without reading anything before...
There are techniques to exit earlier?!
I'm going to read about this...
can you give me references...
Quote:Original post by mp3butcher
which early exit would can be??
I wrote that algo without reading anything before...
There are techniques to exit earlier?!
I'm going to read about this...
can you give me references...


Well, what you describe is like an all-in-one method to intersect the triangle plane, get the point of intersection and verify that it lies inside the triangle.
Since you solve everything at once in a matrix you cannot reject rays going away from the triangle or rays that would stop before hitting the plane unless you make extras tests for it (since the matrix solve that as well).

One more thing, as I said I never work this way. But I'm very interested in learning it so that's the reason for my question. This was not an affirmative statement, really just a question. :)

However I'm still pretty sure that you need an extra u + v < 1 constraint in order to make sure the point of intersection lies inside the triangle.
Praise the alternative.
Quote:Original post by b34r
Quote:Original post by mp3butcher
which early exit would can be??
I wrote that algo without reading anything before...
There are techniques to exit earlier?!
I'm going to read about this...
can you give me references...


Well, what you describe is like an all-in-one method to intersect the triangle plane, get the point of intersection and verify that it lies inside the triangle.
Since you solve everything at once in a matrix you cannot reject rays going away from the triangle or rays that would stop before hitting the plane unless you make extras tests for it (since the matrix solve that as well).

One more thing, as I said I never work this way. But I'm very interested in learning it so that's the reason for my question. This was not an affirmative statement, really just a question. :)

However I'm still pretty sure that you need an extra u + v < 1 constraint in order to make sure the point of intersection lies inside the triangle.


I have wrote that in the hurry I have modified my post...
The only way i found to speed up that algo is space partitionning ( modified octree with neighbourhood relationship ) + bounding boxes
But as i said i need more infozz.........

This topic is closed to new replies.

Advertisement