[ODE] Likely bug: variable test size -- test program

Adam Rotaru adam_rotaru at yahoo.com
Fri Jan 11 13:15:02 2002


  I forgot the test program!
Here it goes.
Adam.

#include <ode/ode.h>

// some constants
#define ORIG_Z 1.5
#define ORIG_MASS 8000000

static dWorldID world;
static dBodyID body;    //the body is assumed to be a
sphere, with radius of 1.
static dJointGroupID contactgroup;


static const dReal* bpos;

static float tnow;
static float tlast;
static const float constDeltaTime=0.001;
static const float bigDeltaTime = 100.0 *
constDeltaTime;
static float deltaTime;
static long timeCount = 0;

//very simplist collide function:
//test if the body (sphere radius=1) touch the ground
(z=0)
static void collide()
{

  if (bpos[2]<=1.0)
  {
      printf("\tTouch!");
      dContact contact;
      contact.surface.mode = dContactSoftERP |
dContactSoftCFM;
      contact.surface.mu = dInfinity;
      contact.surface.soft_erp = 0.1;
      contact.surface.soft_cfm = 0.0;

      //depth of intrusion
      contact.geom.depth=-(bpos[2]-1.0);

      //contact is at body's position, z-=1, (body is
a sphere radius=1)
      contact.geom.pos[0]=bpos[0];
      contact.geom.pos[1]=bpos[1];
      contact.geom.pos[2]=bpos[2]-1.0;

      //the ground is the plan z=0
      contact.geom.normal[0]=0.0;
      contact.geom.normal[1]=0.0;
      contact.geom.normal[2]=1.0;

      dJointID c = dJointCreateContact
(world,contactgroup,&contact);
      //printf("\ndepth=%f",contact[i].geom.depth);
      //contact between body and the ground(static)
      dJointAttach (c,body,0);
 }
}


//basic motion
static void motion ()
{
  deltaTime = constDeltaTime;
  // occasionally do a longer timestep
  if ( (timeCount % 10) == 0)
    deltaTime = bigDeltaTime;

  printf("\ndeltaTime=%.10lf",deltaTime);
      printf("\ttimeCount=%ld", timeCount % 10);
      printf("\tPos=%.10lf", bpos[2]);

  collide ();

  // occasionally do a longer timestep
  dWorldStep (world,deltaTime);

  // remove all contact joints
  dJointGroupEmpty (contactgroup);

  timeCount++;
}


int main (int argc, char **argv)
{
  dMass m;


  // create world
  world = dWorldCreate();
  contactgroup = dJointGroupCreate (0);
  dWorldSetGravity (world,0,0,-9.81);

  // create body
  body = dBodyCreate (world);
  dBodySetPosition (body,0,0,ORIG_Z);
  dMassSetSphere (&m,1,1.0);
  dMassAdjust (&m,ORIG_MASS);
  dBodySetMass (body,&m);


  while (true)
  {
        bpos=dBodyGetPosition(body);

        motion();
  }

  dJointGroupDestroy (contactgroup);
  dWorldDestroy (world);

  return 0;
}



__________________________________________________
Do You Yahoo!?
Send FREE video emails in Yahoo! Mail!
http://promo.yahoo.com/videomail/