Collision detection how to start ?

Started by
7 comments, last by Gaticus 13 years, 3 months ago
hello,
I have a problem because I have to implement a small demo with collision detection. I know A LOT about how it works, I think I would use AABB (axis aligned bounding box) BUT how should it look like in code ?

For example so that you will understand me(I use c++ + OpenGL):
I have and object and I want to check if it's colliding with anything I can check if something is in my defined box volume but how ? I have my object's coords and all the others objects' coords but how to check which of them are colliding?
Can you show me some practical example ?
Advertisement
could you explain in detail what you DO know? I have implemented it myself, but what exactly DONT you know?

edit (sorry, a few edits here, not quite in my best shape):
I guess I can add some info instead of just asking...
//for horizontal check
if(a.left>b.right || a.right<b.left)return;//no collision
-----------take part in the AI challenge on http://cyberlympics.com
If you google for "aabb collision c++" you'll find many examples to look at.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

I just know a lot about it in theory but I don't know how to implement it in practice. btw I have found very interesting site about collision detection (theory)
http://www.metanetsoftware.com/technique/tutorialA.html

I don't even know how to start.
added some info in my earlier post. got it wrong the first time, should not post while half asleep....
-----------take part in the AI challenge on http://cyberlympics.com
heh... ok I know things like that :) but I am asking as for high level design :)
that's what I mean, you haven't really asked a question. it's just a random request for information. what is it you do not know. are you looking for performance improvements? it did not sound like it. have you implemented anything yet? it did not sound like it. give us more information, or you will end up with random information to that random question.

what is high level design?
-----------take part in the AI challenge on http://cyberlympics.com
Ok, sooo... I haven't yet implemented anything regarding collision detection. What I am asking is how to structurise objects, how to organize them so that they will detect collisions.

For example I have came to idea like this :
I will have abstract class sprite from which all objects will derive from, then on constructor all of the objects will be pushed on the let's say vector, deque or STL list and then the collision detection funciton will first check which of the other object is in the particular checked object's range (aabb) and do the test.

Is it the right approach ? Or how does the industry standard look like ?
The metanet N tutorials are excellent. That's how I got started with vector math and collision detection. The little ragdoll physics in N is really cool :)

It's still not clear what you are asking about though. You seem to have a good grasp already.

Yes, you would need an array or some other form of list for your sprites so that you could iterate them all. It depends on your own implementation. It could be a basic, linear array or it could be some form of hierarchical list, like a binary, quad or octree. It could be a linked list. Or some combination of.

This topic is closed to new replies.

Advertisement