Is this the right way to....

lo,
Is this the right way to iterate the contacts and set the friction and bounce factors?

here is the code, please ignore all the PhysicsObject…etc code, its just a holding place for data.


      private void iterateContacts() {
            for (int i = 0; i < collision.getContactCount() - 1; i++) {
                  // obtain the names of the contacts that
                  // have collided
                  String nameOfGeom1 = contact.getGeom1().getName();
                  String nameOfGeom2 = contact.getGeom2().getName();

                  // set the index
                  contact.setIndex(i);
                  if (nameOfGeom1 != null) {
                        // get the PhysicsObject
                        PhysicsObject obj = (PhysicsObject) physicsObjects
                                    .get(nameOfGeom1);
                        // apply the contact information
                        contact.setMode(Ode.dContactBounce | Ode.dContactApprox1);
                        contact.setBounce(obj.getBounce());
                        contact.setBounceVel(obj.getBounceVelocity());
                        contact.setMu(Float.MAX_VALUE);
                  }

                  // set the index
                  contact.setIndex(i + 1);
                  if (nameOfGeom2 != null) {
                        // get the PhysicsObject
                        PhysicsObject obj = (PhysicsObject) physicsObjects
                                    .get(nameOfGeom2);
                        // apply the contact information
                        contact.setMode(Ode.dContactBounce | Ode.dContactApprox1);
                        contact.setBounce(obj.getBounce());
                        contact.setBounceVel(obj.getBounceVelocity());
                        contact.setMu(Float.MAX_VALUE);
                  }
            }
      }

Thx, DP

I think contact.setIndex() should be the first line. Otherwise the geoms you are getting are from the previous contact (which could cause problems if there is no previous contact).

Also - Geoms and Bodies can store a miscellaneous Object using the set/getUserData methods. I find this very useful when iterating over the contacts as I can match up the geom to my game object without needing an extra lookup map.

Will.