• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
industrialgrok

Cannot run ODE code (open dynamics engine)

1 post in this topic

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?

0

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

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.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0