[ODE] Only setting surface params for contacts actually generated

Marty Rabens marty at rabens.com
Fri Feb 6 11:21:36 MST 2004


In the ODE sample apps, the collision callback generally does something
like this:

  dContact contact[MAX_CONTACTS];
  for (i=0; i<MAX_CONTACTS; i++)
  {
      contact[i].surface.mode = dContactBounce | dContactSoftCFM;
      contact[i].surface.mu = dInfinity;
      contact[i].surface.mu2 = 0;
      contact[i].surface.bounce = 0.1;
      contact[i].surface.bounce_vel = 0.1;
      contact[i].surface.soft_cfm = 0.01;
  }
  int numc = dCollide (o1,o2,MAX_CONTACTS,&contact[0].geom,
sizeof(dContact));
  for (i=0; i<numc; i++)
  {
      dJointID c = dJointCreateContact (world,contactgroup,contact+i);
      dJointAttach (c,b1,b2);
  }
  
So it's setting the surface properties for MAX_CONTACTS every time, even
if only some (or none) of those contacts is actually generated by
dCollide().

Could you do this instead?

  dContact contact[MAX_CONTACTS];
  int numc = dCollide (o1,o2,MAX_CONTACTS,&contact[0].geom,
sizeof(dContact));
  for (i=0; i<numc; i++)
  {
      contact[i].surface.mode = dContactBounce | dContactSoftCFM;
      contact[i].surface.mu = dInfinity;
      contact[i].surface.mu2 = 0;
      contact[i].surface.bounce = 0.1;
      contact[i].surface.bounce_vel = 0.1;
      contact[i].surface.soft_cfm = 0.01;
      dJointID c = dJointCreateContact (world,contactgroup,contact+i);
      dJointAttach (c,b1,b2);
  }

The question is, does dCollide() use any of the data that you set?  If
not, the second method should work, and saves a little overhead (as well
as being less code).  I've tried it this way, and it seems to behave
identically.  I just don't know if it's because dCollide() doesn't use
any of the surface data, or if I'm just getting lucky (due to old memory
contents, etc.)

Marty Rabens
  



More information about the ODE mailing list