Collision Detection

Started by
7 comments, last by cxi 24 years ago
AnyOne know of good OPENGL code for COllision Detection i can get? I can not seem to get mine to work, and i woudl love to see some good examples. please email me dan@pjcc.com thanks The Code is a Living breathing entity, and will move in accordance with you, therefore, be one with the Tao of the Code..
The Code is a Living breathing entity, and will move in accordance with you, therefore, be one with the Tao of the Code..
Advertisement
Well, I dont quite have openGL code, but this site has some good explanations on different types of collision detection, the pros and cons of each, what to avoid, etc. It does have some pseudo code, which shouldnt be that hard to convert. Good luck!

http://www.gamedev.net/reference/docs/refarticlelistuser.asp?catid=45

(BTW, the first few links are mainly 2d related, but the last one is 3d)

-Fuzz
quote:Original post by cxi

AnyOne know of good OPENGL code for COllision Detection i can get? I can not seem to get mine to work, and i woudl love to see some good examples. please email me dan@pjcc.com


thanks

It strikes me that the easiest way to detect collision along a path (Ie where I am now to where I am after I bang
along this here path a few notches, would be essentially
to go through ones list of polygons, and see if the line between the two points intersects, a b-tree or somethin''
might be usefull to break down the poly''s to be tested.

I''d figure that''d be the easiest.
The Code is a Living breathing entity, and will move in accordance with you, therefore, be one with the Tao of the Code..


Hi cxi!

Collision detection does not depend on what 3d - interface (OpenGL, D3D, ...) you''re using so you don''t need OpenGL - specific code.

Visit our site: www.rarebyte.de.st

GA
Visit our homepage: www.rarebyte.de.stGA
cool thanks guys.
>>would be essentially
>>to go through ones list of polygons, and see if the line >>between the two points intersects, a b-tree or somethin''
>>might be usefull to break down the poly''s to be tested.

that would work well < and i have thought about that idea as well> for just simple camera movement, but would it work for things coming in from behind < like a bullet> or things falling form the ceiling, and the other characters in the game? i want to make sure that none of the polygons within a certain sector < the viewing frustrum probably> are not going through each other.

Here is my idea: I build a viewing frustrum about 50 units in radius around the character, do a check to see which objects are in that radius < and stuff that list into an array> then do a check to see if their path of motion < where the next frame would put them> is heading my way. Then i need to check for a collision. That would work for the camera collisioncomingfrom 360 degrees around me. but not from above, and it would be tough to implement that for all objects within the frustrum from pounding on each other.

or am i simply making it too complicated????
The Code is a Living breathing entity, and will move in accordance with you, therefore, be one with the Tao of the Code..
Hi cxi,

You''re heading in the general direction, but not quite right. There are heaps of articles aroung on collision detection (although, I must admit some are pretty full-on), but to get you started I''ll quickly explain the bounding sphere techique.

Nominate a central point inside each of your objects, and figure out what size radius a sphere would need to have to (only just) completely enclose the object. This is your bounding sphere. Now, when your objects move (but before drawing the a frame, so you can change stuff like object positions etc after collision if you need to), test the distance between the centre of each object. If it is less than the sum of the radii of their respective bounding spheres, they have ''collided'' (as you may have guessed, this method is not very accurate, but it is fast, and is good as a first level of collision detection).

You can refine this in many ways. One is to not bother testing collision between static objects (as they will never collide), and make sure you don''t test for collision between two object twice (ie test all objects against one object for collision, then iterate to the next object and test for collision with the previous object... you already did that ).

This method is a good first layer. You can then refine your detection by testing for collision with a heirarchy of bounding boxes if a ''collision'' is detected using the bounding sphere (to detect if there actually was a collision).

Hope this was helpful in some small way... I''d hate to think I was wasting my time, being at work and all

-------------
squirrels are a remarkable source of protein...
Great!

No you havent wasted your time. I have been trying to figure out how to create a bounding sphere in opengl. I have also been attempting to use the RAPID collision detection library. but due to the severe lack of documentation on the class its extremely difficult to implement.

anyone have any info on that? Anyone have any info on making a bounding box or bounding sphere in opengl? < i am assuming of course, that this is an actual shape drawn by the system, but with a transparent color, or am i wrong? god i hate being so new to this! haha

thanks for all your help.

p.s. i am at work as well, suppsoed to be coding a e-commerce system in ASP, but would rather play at the moment


CXI

The Code is a Living breathing entity, and will move in accordance with you, therefore, be one with the Tao of the Code..
The Code is a Living breathing entity, and will move in accordance with you, therefore, be one with the Tao of the Code..
Hi again cxi,

Glad I could be of some use to someone for a change

With the bounding sphere, you don''t actually draw it, its just a conceptual thing that surrounds the object. It is simply an imaginary sphere with a radius from the centre of the object to the vertex furthest from that centre. You are just using it to define a distance (i any direction) from the object centre that, if another object''s sphere comes closer than this distance, a collision may have occurred (as the object resides somewhere within this imaginary sphere).

Am I making sense? Sorry if I''ve confused you... the main point I''m trying to make is that you don''t need to draw bounding spheres/boxes/etc, they are simply (approximate)mathematical definitions of the space that your object takes up.

Let me know if you want me to clarify anything (just don''t expect too much, as I''ve only just started in this type of thing recently too)

Well, back to punching out crappy database accessing code with VB... the joy just never stops

-------------
squirrels are a remarkable source of protein...
Thanks Bad Monkey,


One other algorhythm i liked was to create a bounding box, and grab a plane that is not intersecting. then test to make sure all of the vertices for the right object are not on the other side of the plane from the bounding box. although i dont have any code for that check. i am new to the more advanced geometry.

thanks again guys!


The Code is a Living breathing entity, and will move in accordance with you, therefore, be one with the Tao of the Code..
The Code is a Living breathing entity, and will move in accordance with you, therefore, be one with the Tao of the Code..

This topic is closed to new replies.

Advertisement