[ODE] nearCallback() question

David McClurg dmcclurg at pandemicstudios.com.au
Thu Aug 15 21:35:02 2002


Let me pose some simpler questions:

In the debugger, I see a sphere vs tri-list mesh collision where the nearCallback(o1,o2) parameters are reversed in the contact[] list.

	o1, o2 => contact[i].geom.g2, contact[i].geom.g1

Should this be possible?  Is it a bug?  Where does this happen?  Can it be fixed?

The reason this is important is because dGeomGetBody(contact[i].geom.g1) returns NULL if the geometry passed to nearCallback() was a geom 'transform' and dJointAttach() needs the body to work.  My current solution is ugly...

static void nearCallback (void *data, dGeomID o1, dGeomID o2)
{
 dGeomID g1Contact = o1;
 dGeomID g2Contact = o2;
 dBodyID b1Contact = dGeomGetBody(o1);
 dBodyID b2Contact = dGeomGetBody(o2);

  <snip>
  n = dCollide (o1,o2,N,&contact[0].geom,sizeof(dContact));
  for (i=0; i<n; i++) {
    <snip>

      dGeomID g1 = contacts[i].geom.g1;
      dGeomID g2 = contacts[i].geom.g2;
      dBodyID b1 = dGeomGetBody(g1);
      dBodyID b2 = dGeomGetBody(g2);

      // do the bodies match?
      if (!(b1 == b1Contact && b2 == b2Contact))
      {
        if (b1 == b2Contact && b2 == b1Contact)
        {
          // bodies are correct but reversed; do nothing.
        }
        else
        {
          // bodies are incorrect; use the original bodies
          b1 = b1Contact;
          b2 = b2Contact;
          
          // are the bodies reversed?
          // it's likely that we have a geom transform
          // which returns NULL for the body
          if ((dGeomGetClass(g1Contact) == dGeomTransformClass &&
            dGeomTransformGetGeom(g1Contact) == g2) ||
            (dGeomGetClass(g2Contact) == dGeomTransformClass &&
            dGeomTransformGetGeom(g2Contact) == g1))
          {
            // reverse the bodies
            b1 = b2Contact;
            b2 = b1Contact;
          }
        }
      }

      dJointAttach(c, b1, b2);
  }
}

-----Original Message-----
From: David McClurg 
Sent: Tuesday, 13 August 2002 4:37 PM
To: ode@q12.org
Subject: [ODE] nearCallback() question


I've noticed two methods of passing bodies to dJointAttach() in the test programs for ODE...

#1)
static void nearCallback (void *data, dGeomID o1, dGeomID o2)
{
  <snip>
  n = dCollide (o1,o2,N,&contact[0].geom,sizeof(dContact));
  for (i=0; i<n; i++) {
    <snip>
    dJointAttach (c,
                dGeomGetBody(contact[i].geom.g1),
                dGeomGetBody(contact[i].geom.g2));
  }
}

#2)
static void nearCallback (void *data, dGeomID o1, dGeomID o2)
{
 dBodyID b1 = dGeomGetBody(o1);
 dBodyID b2 = dGeomGetBody(o2);
  <snip>
  n = dCollide (o1,o2,N,&contact[0].geom,sizeof(dContact));
  for (i=0; i<n; i++) {
    <snip>
    dJointAttach (c, b1, b2);
  }
}


Method #2 fails in some cases because b1 & b2 are reversed and the joint subsequently gets reversed.  But in the case of a geom transform like in test_boxstack.cpp if you don't use method #2 then the body comes up NULL.

So my question is, how do I properly get the bodies to pass to dJointAttach() in all cases?

Ta
_______________________________________________
ODE mailing list
ODE@q12.org
http://q12.org/mailman/listinfo/ode