Jump to content
  • Advertisement
Sign in to follow this  
bluemonkey

Collision Detection - Is this how it works?

This topic is 4825 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I was wondering if someone could explain to me (if you would be so kind : ) how collision detection works (specifically in OpenGL, but any example would do). When I think of collision detection I think of knowing everything about a certain object (ie. the player object) and not knowing anything about another object (ie. a wall). For instance, say I create a wall every frame but I don't keep track of its position. But I want my player to be able to have a collision with the object and not pass through it, is that possible? The books and tutorials I've read thus far assume that I will be colliding 2 objects which I know the exact position of at all times, and with a little math it is possible to determine if they collided. And I understand that type of collision, but how would my above scenario work out? If at all. Thanks in advance, this has really been bothering me : )

Share this post


Link to post
Share on other sites
Advertisement
I think there is no point not to know where a given object is, because it isn't too much strain to keep track of it. Why make lif harder for yourself, when it might make it easier to have a variable storing that information.

Share this post


Link to post
Share on other sites
Let me clarify, say I create a game map format. When I load the map I have walls, stairs, ladders. For all of those object I need to detect a collision in order to handle the subsequent action, should I store every quad/triangle in the map inside a variable so I can detect collision? (Honest question)

EDIT: Also, do I check every frame to see if I have collided with all of the quad/triangles I have in my variable? It would seem a very slow process to me.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
let me prove to you why your desires are NOT possible, follow the example:

Person A is located at the origin of a playing field (0, 0). Obstacle B is somewhere on the field. If A moves across the field in some direction, does Person A intersect the obstacle, and if so at what point?

Point is, there is not enough information to solve the problem. We need to know the walls extents and a reference point to place and orient the wall. In programing you would HAVE to maintain the two objects orientation and bounds to determine a collision. So your scenario would not work out, you are providing insufficient information for solving the problem.

In addition, why would you 'create' the wall every frame, I would think it smarter to create it once and then reference the instance every frame, wouldnt; you?

Share this post


Link to post
Share on other sites
One thing to keep in mind is that OpenGL is a graphics API and aside perhaps from GPU-assisted techniques has little if anything to do with collision detection. So your collision detection methods will probably be independent of whatever API you are using.

I'm not sure what you mean by 'not keeping track of your objects'. Whether you have it stored somewhere or figure it out on the fly, one way or another you're probably going to have to know where your objects are in order to test for a collision between them.

As for how to perform the collision detection, there are countless methods; which is best for you depends entirely on your circumstances.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
no you would normally start with a larger bounding volume if it collides, then perform a refined collision detection. So a human model would first have an OOBB or AABB or a sphere the has the whole set of faces inside of its interior. If the sphere collides with the walls bounding box, then the next step is to determine if any of the sphere bounds assigned to the various parts (arms, legs, torso, head, etc.) intersect. The the sphere that intersects, say it is the left leg, checks each of the polys in it. So you do a repetitive search to determine an absolute collision if you need to particular poly.

enjoi

Share this post


Link to post
Share on other sites
Quote:
Also, do I check every frame to see if I have collided with all of the quad/triangles I have in my variable? It would seem a very slow process to me.
Checking for every possible intersection can be slow and is usually to be avoided. The solutions to this problem fall into the category of spatial partitioning and broad-phase culling, but if you're new to collision detection I'd work on getting some narrow-phase (object-to-object) tests working first and worry about broad-phase later.

Share this post


Link to post
Share on other sites
Okie doke. It is much more clear in my mind now. My first project was to make a game of Pool (have a ball bounce around off walls) and I was successful in doing that, but was wondering if I had to keep track of the walls in order to do collision testing.

Thanks all : )

Share this post


Link to post
Share on other sites
Quote:
Original post by Anonymous Poster
let me prove to you why your desires are NOT possible, follow the example:

Person A is located at the origin of a playing field (0, 0). Obstacle B is somewhere on the field. If A moves across the field in some direction, does Person A intersect the obstacle, and if so at what point?

Point is, there is not enough information to solve the problem. We need to know the walls extents and a reference point to place and orient the wall. In programing you would HAVE to maintain the two objects orientation and bounds to determine a collision. So your scenario would not work out, you are providing insufficient information for solving the problem.

In addition, why would you 'create' the wall every frame, I would think it smarter to create it once and then reference the instance every frame, wouldnt; you?


When I said create, I meant render the quad every frame, I've not created an object to house the wall yet, just a raw glBegin(GL_QUADS), hence my curiosity of whether I need to create an object to house the wall or not (thus providing storage for its position, and collision detection).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!