collision detection

AlNom

Moderator
Moderator
Legend
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...

:?:
 
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?
 
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.
 
whoa :oops: 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 ;)
 
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.
 
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.
 
Back
Top