[ODE] Trimesh - box collision problem!

jojo20@mail.goo.ne.jp jojo20 at mail.goo.ne.jp
Fri Jan 20 11:02:38 MST 2006



Hi , everyone.

I study ODE for about three months.
But I can't simulate trimesh-box collision.

I can simulate box-box collision and ground(plane)-box collision and so on.

Then I try (trimesh and box(connect by joint)) - box collision.
And trimesh go though the box.
(connected box can COLLIDE the below box)

Any help please. 

I use following nearCallback and Simloop as shown below.


--------------------------------------------------------------------
/* this is nearCallback like "test_buggy.cpp"
   I made gound_box and ground similar "test_buggy.cpp"
   I want collide (trimesh and box(connect by joint)) on it.
*/

static void nearCallback (void *data, dGeomID o1, dGeomID o2)
{

  int i,n;

  // only collide things with the ground
  int g1 = (o1 == ground || o1 == ground_box);
  int g2 = (o2 == ground || o2 == ground_box);
  if (!(g1 ^ g2)) return;

  const int N = 10;
  dContact contact[N];
  n = dCollide (o1,o2,N,&contact[0].geom,sizeof(dContact));
  if (n > 0) {
    for (i=0; i<n; i++) {
      contact[i].surface.mode = dContactSlip1 | dContactSlip2 |
	dContactSoftERP | dContactSoftCFM | dContactApprox1;
      contact[i].surface.mu = dInfinity;
      contact[i].surface.slip1 = 0.1;
      contact[i].surface.slip2 = 0.1;
      contact[i].surface.soft_erp = 0.5;
      contact[i].surface.soft_cfm = 0.3;
      dJointID c = dJointCreateContact (world,contactgroup,&contact[i]);
      dJointAttach (c,
		    dGeomGetBody(contact[i].geom.g1),
		    dGeomGetBody(contact[i].geom.g2));
    }
  }
}
-------------------------------------------------------------------------
-------------------------------------------------------------------------

static void simLoop (int pause)
{
  dsSetColor (0,0,2);
  
  
  const dReal *pos1,*R1 ;
  
  
  dSpaceCollide (space,0,&nearCallback);
  if (!pause) dWorldStepFast1 (world,0.05, 5);

  for (int j = 0; j < dSpaceGetNumGeoms(space); j++){
	  dSpaceGetGeom(space, j);
  }

  dJointGroupEmpty (contactgroup);

  dsSetColor (1,1,0);
  dsSetTexture (DS_WOOD);

  
  pos1 = dBodyGetPosition(box1.body);
  R1   = dBodyGetRotation(box1.body);
  dsDrawBox(pos1,R1,sides1);

  dsSetColor(0.0,0.0,1.0);
  
  dVector3 ss;
  dGeomBoxGetLengths (ground_box,ss);
  dsDrawBox (dGeomGetPosition(ground_box),dGeomGetRotation(ground_box),ss);

        dsSetColor (1,1,0);
        
	     {
          int* Indices = (int*)::Indices;

          const dReal* Pos1 = dGeomGetPosition(obj[0].geom[0]);
          const dReal* Rot1 = dGeomGetRotation(obj[0].geom[0]);
       
          for (int ii = 0; ii < IndexCount / 3; ii++) {
            const dReal v[9] = { // explicit conversion from float to dReal
              Vertices[Indices[ii * 3 + 0] * 3 + 0],
              Vertices[Indices[ii * 3 + 0] * 3 + 1],
              Vertices[Indices[ii * 3 + 0] * 3 + 2],
              Vertices[Indices[ii * 3 + 1] * 3 + 0],
              Vertices[Indices[ii * 3 + 1] * 3 + 1],
              Vertices[Indices[ii * 3 + 1] * 3 + 2],
              Vertices[Indices[ii * 3 + 2] * 3 + 0],
              Vertices[Indices[ii * 3 + 2] * 3 + 1],
              Vertices[Indices[ii * 3 + 2] * 3 + 2]
            };
            dsDrawTriangle(Pos1, Rot1, &v[0], &v[3], &v[6], 1);
       }
  } 
}

-------------------------------------------------------------------

When trimesh-box collide , need different function??


Thanks for watching.


More information about the ODE mailing list