Jump to content

  • Log In with Google      Sign In   
  • Create Account


Cannot run ODE code (open dynamics engine)


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 Noah2033   Members   -  Reputation: 161

Like
0Likes
Like

Posted 25 February 2013 - 07:39 PM

so a while back I messed with ode because i was going to impliment it in my engine, its been about a month so i dont have the compile command in my terminal history and i forgot specificly what i used to compile it but here is the code

 

#include <ode/ode.h>
#include <drawstuff/drawstuff.h>
#include <string.h>
#include <iostream>

#ifdef dDOUBLE
#define dsDrawSphere dsDrawSphereD
#endif

using namespace std;
const int VertexCount = 5;
const int IndexCount = 12;

static dVector3 Size;
static float Vertices[VertexCount][3];
static dTriIndex Indices[IndexCount];

static dJointGroupID contactgroup;
//static int flag = 0;
dsFunctions fn;


const double   radius = 0.2;
const double   mass   = 1.0;

struct cworld
{
 int numobjects;
 dSpaceID space;
 dWorldID world;
};

struct object
{
 string name;
 string type;
 const double *position;
 const double *rotation;
 dBodyID body;
 dGeomID geom;
 dMass mass;
};
cworld world;

object objects[10];
//object objects[0];
//object objects[1];
//object objects[3];

static void nearCallback(void *data, dGeomID o1, dGeomID o2)
{
  const int N = 10;
  dContact contact[N];
  int n;

  for(int i = 0; i <= world.numobjects; i++)
     {
      n =  dCollide(o1,o2,N,&contact[0].geom,sizeof(dContact));
      if(n >= 1)                                   //object hit somthing
        {
         if(objects[i].geom == o1)
           {
            //cout << objects[i].type << endl;
            for(int j = 0; j <= world.numobjects; j++)
               {
                if(objects[j].geom == o2)
                  {
                   cout << objects[j].name << " is hitting a " << objects[j].name << endl;
                  }  
               }
           }
         }
     }

    for(int i = 0; i < n; i++) 
       {
        contact[i].surface.mode = dContactBounce;
        contact[i].surface.mu   = dInfinity;
        contact[i].surface.bounce     = 0.0; // (0.0~1.0) restitution parameter
        contact[i].surface.bounce_vel = 0.0; // minimum incoming velocity for bounce
        dJointID c = dJointCreateContact(world.world,contactgroup,&contact[i]);
        dJointAttach (c,dGeomGetBody(contact[i].geom.g1),dGeomGetBody(contact[i].geom.g2));
       }

}


static void simLoop (int pause)
{
  //flag = 0;
  dSpaceCollide(world.space,0,&nearCallback);

  dWorldStep(world.world,0.01);

  dJointGroupEmpty(contactgroup);

  /*if(flag == 0) 
    dsSetColor(1.0, 0.0, 0.0);
  else           
      dsSetColor(0.0, 0.0, 1.0);*/
                                   
  objects[0].position = dBodyGetPosition(objects[0].body);
  objects[0].rotation   = dBodyGetRotation(objects[0].body);
  dsDrawSphere(objects[0].position,objects[0].rotation,radius);

  objects[1].position = dBodyGetPosition(objects[1].body);
  objects[1].rotation   = dBodyGetRotation(objects[1].body);
  dsDrawSphere(objects[1].position,objects[1].rotation,radius);
}

void start()
{
  static float xyz[3] = {0.0,-3.0,1.0};
  static float hpr[3] = {90.0,0.0,0.0};
  dsSetViewpoint (xyz,hpr);
}

void  prepDrawStuff() {
  fn.version = DS_VERSION;
  fn.start   = &start;
  fn.step    = &simLoop;
  fn.command = NULL;
  fn.stop    = NULL;
  fn.path_to_textures = "../../drawstuff/textures";
}

int main (int argc, char *argv[])
{
  double x0 = 0.0, y0 = 0.0, z0 = 2.0;


  prepDrawStuff();

  dInitODE();
  world.world = dWorldCreate();
  world.space = dHashSpaceCreate(0);
  contactgroup = dJointGroupCreate(0);

  dWorldSetGravity(world.world,0,0,-0.5);
  //Create a trimesh
  Size[0] = 5.0f;
  Size[1] = 5.0f;
  Size[2] = 2.5f;
  
  Vertices[0][0] = -Size[0];
  Vertices[0][1] = -Size[1];
  Vertices[0][2] = Size[2];
  
  Vertices[1][0] = Size[0];
  Vertices[1][1] = -Size[1];
  Vertices[1][2] = Size[2];
  
  Vertices[2][0] = Size[0];
  Vertices[2][1] = Size[1];
  Vertices[2][2] = Size[2];
  
  Vertices[3][0] = -Size[0];
  Vertices[3][1] = Size[1];
  Vertices[3][2] = Size[2];
  
  Vertices[4][0] = 0;
  Vertices[4][1] = 0;
  Vertices[4][2] = 0;
  
  Indices[0] = 0;
  Indices[1] = 1;
  Indices[2] = 4;
  
  Indices[3] = 1;
  Indices[4] = 2;
  Indices[5] = 4;
  
  Indices[6] = 2;
  Indices[7] = 3;
  Indices[8] = 4;
  
  Indices[9] = 3;
  Indices[10] = 0;
  Indices[11] = 4;

  dTriMeshDataID Data = dGeomTriMeshDataCreate();
  //dGeomTriMeshDataBuildSimple(Data, (dReal*)Vertices, VertexCount, Indices, IndexCount);
  dGeomTriMeshDataBuildSingle(Data, Vertices[0], 3 * sizeof(float), VertexCount, &Indices[0], IndexCount, 3 * sizeof(dTriIndex));
  objects[4].geom = dCreateTriMesh(world.space, Data, 0, 0, 0);
  dGeomSetPosition(objects[4].geom, 0, 0, 0.0);
  objects[4].type = "world";
  objects[4].name = "crappy sky";
  world.numobjects = world.numobjects + 1;

  // Create a ground
  objects[3].geom = dCreatePlane(world.space,0,0,1,0);
  objects[3].type = "ground";
  objects[3].name = "ground(duh)";
  world.numobjects = world.numobjects + 1;

  // Create objects[0]
  objects[0].type = "sphere";
  objects[0].name = "ball1";
  objects[0].body = dBodyCreate(world.world);
  dMassSetZero(&objects[0].mass);
  dMassSetSphereTotal(&objects[0].mass,mass,radius);
  dBodySetMass(objects[0].body,&objects[0].mass);
  dBodySetPosition(objects[0].body, x0, y0, z0);
  objects[0].geom = dCreateSphere(world.space,radius);
  dGeomSetBody(objects[0].geom,objects[0].body);
  dBodySetLinearVel(objects[0].body, 1.0, 0.0,1.0); 
  world.numobjects = world.numobjects + 1;

  //Create objects[1]
  objects[1].type = "sphere";
  objects[1].name = "ball2";
  objects[1].body = dBodyCreate(world.world);
  dMassSetZero(&objects[1].mass);
  dMassSetSphereTotal(&objects[1].mass,mass,radius);
  dBodySetMass(objects[1].body,&objects[1].mass);
  dBodySetPosition(objects[1].body, -1.0, y0, 3.0);
  objects[1].geom = dCreateSphere(world.space,radius);
  dGeomSetBody(objects[1].geom,objects[1].body);
  world.numobjects = world.numobjects + 1;



  dsSimulationLoop (argc,argv,352,288,&fn);

  dWorldDestroy (world.world);
  dCloseODE();

  return 0;
}

 

here is the output :

sample6.cpp: In function ‘void simLoop(int)’:
sample6.cpp:102:57: error: cannot convert ‘const dReal* {aka const float*}’ to ‘const double*’ in assignment
sample6.cpp:103:59: error: cannot convert ‘const dReal* {aka const float*}’ to ‘const double*’ in assignment
sample6.cpp:104:62: error: cannot convert ‘const double*’ to ‘const float*’ for argument ‘1’ to ‘void dsDrawSphere(const float*, const float*, float)’
sample6.cpp:106:57: error: cannot convert ‘const dReal* {aka const float*}’ to ‘const double*’ in assignment
sample6.cpp:107:59: error: cannot convert ‘const dReal* {aka const float*}’ to ‘const double*’ in assignment
sample6.cpp:108:62: error: cannot convert ‘const double*’ to ‘const float*’ for argument ‘1’ to ‘void dsDrawSphere(const float*, const float*, float)’
 

when I fix these errors and run it I get a zero inertia runtime error

now I remember this code compiling and running fine. So I must be compiling it wrong (I bet its somthing stupid I simply forgot)

have any idea?



Sponsor:

#2 mightypigeon   Members   -  Reputation: 433

Like
0Likes
Like

Posted 02 March 2013 - 01:37 AM

Your "object" struct has doubles whilst it seems like ODE is using single precision floats for dReal.  You can instruct ODE to compile using doubles instead of floats (the default), perhaps you previously had this in your compiler options.

 

This page has some information on how to configure ODE to use doubles (though unless you really need the precision I'd recommend just using floats...)

http://ode-wiki.org/wiki/index.php?title=Manual:_Install_and_Use

 

--enable-double-precision enables double precision math

 

Further down:

 

Add one of the preprocessor symbols dSINGLE (single precision) or dDOUBLE (double precision), depending on how ODE was configured. If none is defined, single precision is assumed; if the wrong precision is enabled all floating-point data going in and out of ODE will be corrupt, producing all kinds of errors.







Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS