Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Not only there are two useful broad-phase algorithms and a lot of useful narrowphase algorithms, there are also multiple code styles.

Arrays vs. calling

  1. Make an array of broadphase checks, then filter them with narrowphase checks, then resolve them.

     function resolveCollisions(thingyStructure * a,thingyStructure * b,int index){
          possibleCollisions = getPossibleCollisions(b,a->get(index));
          for(i=0; i<possibleCollitionsNumber; i++){
               if(narrowphase(possibleCollisions[i],a[index])) {
          for(i=0; i<collitionsNumber; i++){
               //CODE FOR RESOLUTION
  2. Make the broadphase call the narrowphase, and the narrowphase call the resolution

     function resolveCollisions(thingyStructure * a,thingyStructure * b,int index){
     function broadphase(thingy * with, thingy * what){

Events vs. in-the-loop

  1. Fire an event. This abstracts the check away, but it's trickier to make an equal interaction.

    a[index] -> collisionEvent(eventdata);
    //much later
    int collisionEvent(eventdata){
         //resolution gets here
  2. Resolve the collision inside the loop. This glues narrowphase and resolution into one layer.

       if(narrowphase(possibleCollisions[i],a[index])) {
            //CODE GOES HERE

The questions are: Which of the first two is better, and how am I supposed to make a zero-sum Newtonian interaction under B1.

share|improve this question

closed as not constructive by Sean Middleditch, MichaelHouse 'Byte56', bummzack, Josh Petrie, Tetrad Dec 26 '12 at 4:07

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.If this question can be reworded to fit the rules in the help center, please edit the question.

Sounds subjective. Code style questions might be better suited for the Code Review beta site. – Anko Dec 9 '12 at 0:23
"Which is better" is subjective. Better in what sense? Is there a specific problem you're trying to solve? – Tetrad Dec 26 '12 at 4:06