Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I've already programmed a 2d based collision system for a previous game. It was my first collision system and it was ugly. I was looking for collision between objects by checking all objects with all objects. I've already heard about a grid system with cells where an object will only look the collision with other objects from its current cell(s). Is it really a good way to check collision?

I'd like to have a good technique to loop trough all my items in a 3d world.

share|improve this question

2 Answers 2

up vote 11 down vote accepted

You're going to need a good space-partitioning algorithm, commonly used in 3D are octrees.

After that you could surround models etc with bounding spheres in which they fit neatly because a collision between bounding spheres is very easy to calculate. After you know that two bounding spheres collide you can either iteratively make the bounding spheres smaller and adding bounding spheres to keep the object covered in them, or us another smart algorithm to calculate collisions between two complex objects.

See this image: multiple bounding spheres

share|improve this answer

Ultimately I think the answer to your question is going to depend upon the needs of your particular application, as there isn't a one-size-fits all solution. Although there are a number of decent resources on the web, you'll save yourself a lot of time and frustration by picking up Christer Ericson's Real-time Collision Detection, which lays out in great detail a wide variety of techniques and algorithms, with example C++ code.

It helped me to take baby steps before jumping into trying to build a grand system. Writing a function to determine if a point is in a plane, then if a point is in a triangle, if a ray is in a triangle, etc. Then moving onto static tests of various convex solids: AABB vs. Triangle, etc. With time things that seemed impenetrable (forgive the pun) at first became less daunting. Here is a listing of a good number of tests, with example code:

http://www.realtimerendering.com/intersections.html

In the meantime, since I know not everyone can just fork out 70-80$ for a book at will, here are some terms you might want to look into:

  • Spatial Partitioning, Octrees, Quadtrees, BSP trees
  • BIH Trees
  • Bounding Volumes and Bounding Volume Hierarchies
  • Discrete vs. Continuous Collision Detection
  • Separating Axis Theorem
  • GJK Algorithm
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.