Jump to content
  • Advertisement
Sign in to follow this  

Cannot run ODE code (open dynamics engine)

This topic is 1998 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

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;



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

  objects[1].position = dBodyGetPosition(objects[1].body);
  objects[1].rotation   = dBodyGetRotation(objects[1].body);

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;


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

  //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);
  dBodySetPosition(objects[0].body, x0, y0, z0);
  objects[0].geom = dCreateSphere(world.space,radius);
  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);
  dBodySetPosition(objects[1].body, -1.0, y0, 3.0);
  objects[1].geom = dCreateSphere(world.space,radius);
  world.numobjects = world.numobjects + 1;

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

  dWorldDestroy (world.world);

  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?

Share this post

Link to post
Share on other sites

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...)



--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.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!