PDA

View Full Version : collision detection

AlStrong
22-Jul-2004, 23:00
Yeah, I know it's something a little odd to ask, but anyhoo...

I'm doing a mini program in openGL, and I want to implement collision detection between a box, 3 walls and a floor...

Anyone know of a good tutorial to implement this? The one I've found (NeHe's lesson 30 ) are somewhat specific to what those programs are doing. I was wondering if there's some general format I can follow...

:?:

Ostsol
22-Jul-2004, 23:07
I have yet to write a collision system consisting of more than just bounding spheres and cylinders, but here's a list of articles on the subject:

http://www.gamedev.net/reference/list.asp?categoryid=45#99

AlStrong
23-Jul-2004, 16:21
thanks, I'll go through those. :)

Simon F
23-Jul-2004, 16:40

It is awesome.

AlStrong
23-Jul-2004, 18:01
oooo..... :D

hm.... not understanding :( well, actually... see I'm just starting out, so right now I've got this cube and walls setup through GL_QUADS. I don't get how I might access the objects for use in the collision detection equations. Am I even making sense?

Infinisearch
23-Jul-2004, 19:42
Think of it like this any movable object in your game world exists in four distinct 'spaces', collision, physics, geometry, and the world. The world is your objects position and orientation, the geometry is the mesh that is associated with the object, mass/inertia tensor velocity/acceleration (linear and angular) all are properties of your object in relation to the physics 'space'. When it comes to collision you have a variety of different ways to implement your object representation in that 'space'.

The choice of representation is usually a tradeoff between speed and accuracy. For example a bounding sphere is a common collision primitive, a sphere that encloses all of the object is associated with the object and is used for collision purposes. Why a sphere? because imagine testing to see if two spheres collide, if the sum of the radius's of the two spheres is greater than the distance between there centers the spheres are colliding. This can be done lightning quick. The obvious drawbacks are that spheres will give you alot of faulty collisions depending on the actually shape of said object. So look up things like sphere trees, AABB, OBB, line swept spheres, bounding volume hierarchies. There are many papers out there for you to read, as well as libraries for you to look into DEEP, SWIFT++, PIVOT, SWIFT, H-COLLIDE, RAPID, PQP, V-COLLIDE, I-COLLIDE, IMPACT.
(the previous all can be found here: http://www.cs.unc.edu/~geom/collide/packages.html) There are many more like the one thats integrated into ODE (a physics engine), i forget its name at the moment. Oh and there is a website by the name of magic-software, somewhere on there site is a table on the math of colliding various type of primitives with each other i.e. triangles and lines.

For you I would advise using a bounding sphere for the object and the plane equations for the walls and floor/ceiling (assuming they are flat). The plane equation is fast easy to understand and well documented.

AlStrong
23-Jul-2004, 19:53
whoa :shock: Okay, lots of reading to do, thanks :D

Yes, everything is flat, there's just a cube in the room which I can move or rotate in the x,y,z at the press of keys.

I was looking at the planes stuff, but it kind of flew right past me (implementation).

off to some reading, and perhaps back on monday for this thread (update).

edit: just to note.. there's a right parenthese in your link :wink:

Infinisearch
24-Jul-2004, 22:04
Plane stuff is pretty simple. This is from memory just so you get the concept don't mind the memory lapses I made note of what i can't remember at the moment. The plane equation is Ax+By+Cz(-/+)D=0 so you have a four vector of floats defining your plane. The normal or the whole thing including D must be normalized (forgot which) when you plug a point into the equation, the output is zero if the point is on the plane. If not its the shortest (line perpendicular from plane to point) distance to the plane, a negative distance means its distance D away from the plane on the other side of the normal. Long story short, if you use a bounding sphere and plug the current location of the center of said sphere into the plane equation, compare distance returned with radius of sphere... which will bring you to collision response which is another topic entirely. Just remember you need to stores collisions you can't just respond to them immediately, think collision in corner with two walls at same time.

AlStrong
26-Jul-2004, 15:25
ah.... I think I understand it better now. Thanks :)

*still working on code*

dborca
29-Jul-2004, 08:16
If you're a fan of Minkovsky sums, here is one fast collision detection for arbitrary polytopes. Really easy to implement/understand. Also, pseudo-code provided.

Kelvin Chung Tat Leung's thesis (http://www.geocities.com/kelchung220/thesis.html).