Jump to content
  • Advertisement
Sign in to follow this  
dmitsuki

Collision Detection Model

This topic is 2890 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

Hi, I was wondering what some peoples takes on a collision detection model were.


I was thinking of implementing a class called CollisionController where I would pass a list of my entities there and handle all collision code, but there was something is something I can't decide.

Where should I handle the collision events? Would it be a bad model to have a collision method in the entity base class and then specify it for each class that it would be called from?

I am leaning toward doing it this way, but if somebody has a better model to tell me about or give me to read about I'm all open for anything.

Share this post


Link to post
Share on other sites
Advertisement
I see it more logically to have some kind of a World class that processes the collisions.
Also, I guess that in most applications most objects react similarly to collisions (but different parameters like friction etc..).
It wouldn't be bad since I don't think there is right or wrong here just what makes sense to you as both solutions would work.

Share this post


Link to post
Share on other sites
You may have a dedicated class for collisions with methods like:

-checkCollision(obj1, obj2) : collisionType

and many others. You may also have other attributes or parameters as CableGuy suggested.

That way, whenever you need to modify your collision system you know where to touch & u won't mess up your main program. Collisions would be isolated & it would be easy to debug.
Rembember not to give any other responsibilities to this class than checking collisions!
Hope it helps.

Synth

Share this post


Link to post
Share on other sites
One method of collision handling is to have a single collision handler (class, object, engine.).

During initialization, geometry information* for all collision objects of interest are passed to (registered-with, stored-by) the collision handler, with a callback function for each collision object if desired. EDIT: an entity can "register" itself along with a separate or class-based callback.

*"Geometry" is often separate from rendering information as collision detection is simpler and quicker for, example, a "box" (versus 12 triangles forming a box), sphere-sphere, ray-plane, etc..

During the "collision phase" of the game loop, the collision handler detects all collisions between collision objects (sphere-sphere, ray-box, etc.) and stores that information.

Following that phase, the collision handler "sorts" through the collisions and the callback function for each object is called with a list (std::vector works nicely) of collision information for that object. Each object processes the collisions in that list, determining the forces/torques on the object, etc. If an object has no callback function registered, either the collision engine resolves the collisions or no resolution is performed.

That phase is often followed by a "physics" phase, in which gravity and the forces/torques on each object** are applied to determine new positions, velocities. etc.

**Some collision/physics engines maintain a collision object associated with (but separate from) a body object. The collision object determines if/when/where collisions take place. The body object determines how the object reacts to collisions (restitution, moments of inertia (responding to torque), mass, softness, bounciness, etc.). How the body "reacts" to the various forces can be done in the physics engine or via a body callback function. EDIT: similar to the collision information, entities can "register" body parameters and either let the physics engine apply the forces/torques or process the physics via a separate or class-based callback.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!