[ODE] implicit collision?

Anselm Hook anselm at hook.org
Mon Aug 26 22:49:01 2002


Is there implicit collision support such that one doesn't have to write a
nearcallback handler?  It is a bit harder to make a C# binding otherwise.

I ended up writing a bit of code as appended below, or at this link:

http://p2pmap.org/cgi-bin/cvsweb.cgi/p2pmap/src/ode/ode/src/glue.cpp?rev=1.1&content-type=text/x-cvsweb-markup

Perhaps if I use one of the other collision libs this would be implicit?

Also - has anybody ever been able to build a windows dll using cygwin?

 - a

#include "objects.h"
#include <ode/ode.h>
#include "joint.h"
#include <ode/odemath.h>
#include <ode/matrix.h>
#include "step.h"
#include <ode/memory.h>
#include <ode/error.h>
#include "glue.h"

static dWorldID worldid;
static dJointGroupID contactsid;

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

  int i;

  dBodyID b1 = dGeomGetBody(o1);
  dBodyID b2 = dGeomGetBody(o2);

  if( b1 && b2 && dAreConnected(b1,b2) ) {
    return;
  }

  if( !b1 && !b2) {
    return;
  }

  if( b1 == b2 ) {
	  return;
  }

  int collision_bits_a = (int)dGeomGetData(o1);
  int collision_bits_b = (int)dGeomGetData(o2);

  // If no overlap then bail
//  if( !((collision_bits_a&255) & (collision_bits_b&255)) ) return;

  // Ball versus ball/plane style collision with one contact and slip
  if( ( collision_bits_a & 32768 ) || (collision_bits_b & 32768 ) ) {
    dContact contact;
    contact.surface.mode = dContactSlip1 | dContactSlip2 | dContactBounce;
    contact.surface.mu = dInfinity;
    contact.surface.slip1 = 0.1f;
    contact.surface.slip2 = 0.1f;
    contact.surface.soft_erp = 0.5f;
    contact.surface.soft_cfm = 0.3f;
    contact.surface.bounce = 1.0f;
    contact.surface.bounce_vel = 0.0f;
    if (dCollide (o1,o2,0,&contact.geom,sizeof(dContactGeom))) {
      dJointID c = dJointCreateContact (worldid,contactsid,&contact);
      dJointAttach (c,b1,b2);
    }
    return;
  }
  // support a box versus plane style collision with 3 contacts, no slip
  else {
    dContact contact[3];
    for(i=0;i<3;i++) {
      contact[i].surface.mode = 0;
      contact[i].surface.mu = 9999999;
      contact[i].surface.mu2 = 0;
    }
    int numc = dCollide(o1,o2,3,&contact[0].geom,sizeof(dContact));
    for(i = 0;i<numc;i++) {
      dJointID c = dJointCreateContact(worldid,contactsid,contact+i);
      dJointAttach(c,b1,b2);
    }
  }
}

void collision(dSpaceID space, dWorldID _world, dJointGroupID _contacts) {
	worldid = _world;
	contactsid = _contacts;
	dSpaceCollide(space,0,&nearCallback);
}