# Simple ODE Example / Tutorial

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

## Recommended Posts

After accepting the fact that creating a physics engine for a game is a slightly complicated task for a n00b I took a peek at the ODE stuff. Problem being that it does not come with an example on how to set up a basic collision / gravity scenario :-( And there do not appear to be any tutorials available on the web (Yes, I have looked) Are there any sources that anyone knows of which could get me started on the very basics of ODE? Thanks in advance for any help :-)

##### Share on other sites
Hey! I was in the same boat last week.

If you download the ODE source (not the bin releases), and extract it, you'll find all kinds of demo code in the
ode 0.5\ode-0.5\ode\test\ directory.

I found them to be quite useful.

Hope this helps!

##### Share on other sites
I was wondering where the source for those Demo's were ;-) Although when I run them I get an erro because cannot find "cygwin1.dll" ...

I'll check out the sources.

Thanks a lot dude :-)

##### Share on other sites
Does anyone know how to unzip a .tar.gz in windows? I have winace, winzip, winrar, and PowerArchiver installed and none will open the zipped file with the sources from ode.org :-(

##### Share on other sites
winrar always does the job for me regarding .tar/.tar.gz archives.

##### Share on other sites
Ya, I use WinRAR for pretty much everything but .7z archives. It opens up .tar.gz just fine for me here.

##### Share on other sites
Quote:
 Original post by Spudderwinrar always does the job for me regarding .tar/.tar.gz archives.

Same here. On that note xyuri, make sure that the file type is registered to WinRar so you can easily double-click and open it. Once you do that there is another archive that contains all the files.

##### Share on other sites
I downloaded a different source from the ODE site which seems to work much better...

I have found some examples which are a little confusing to me, but I'll go through them tonight and see what I can make of it.

One thing is for sure, I'm writing a tutorial for n00b's when I get through this all ;-)

Thanks guys.

##### Share on other sites
jakem3s90, I just cant seem to make any sense of what they have written in those examples ... There is bound to be a much easier way about it ... all I want to do is have a box that falls! Would you maybe be able to provide me with one please?

Thanks,
Michael D

##### Share on other sites
Which compiler / IDE are you using? Also, which graphics API are you using?

I might be able to send you a some code to help you get started!

##### Share on other sites
This should be all you need, but I'm writing most of it from memory, so some of it could be wrong... What you *should* do is look at ODE's Latest User Guide, since it explains how to create objects and so forth, and you can get the basics of the collision detection functions from the source code provided in the source release.

//thinks you should always keep track of:dWorldID worldID = 0;dSpaceID spaceID = 0;dJointGroupID contactGroup = 0;//these things handle your box:dBodyID bodyID = 0;dGeomID geomID = 0;//INIT:worldID = dWorldCreate();dWorldSetGravity(worldID,0.0f,-9.8f,0.0f);spaceID = dHashSpaceCreate(0);contactGroup = dJointGroupCreate(0);dMass mass;bodyID = dBodyCreate(worldID);dMassSetBox(&mass,1.0f,0.5f,0.5f,0.5f);dBodySetMass(bodyID,&mass);dBodySetPosition(bodyID,0.0f,0.0f,0.0f);geomID = dCreateBox(spaceID,0.5f,0.5f,0.5f);dGeomSetBody(geomID,bodyID);//DEINIT:dGeomDestroy(geomID);dBodyDestroy(bodyID);dWorldDestroy(worldID);dSpaceDestroy(spaceID);dCloseODE();//final clean-up//COLLISION DETECTION:dSpaceCollide(spaceID,0,&callbackFunc);//changeInTime is the seconds passed since the last update:dWorldQuickStep(worldID,changeInTime);dJointGroupEmpty(contactGroup);//COLLISION DETECTION FUNCTION:#define MAX_CONTACTS 16void callbackFunc(void* data,dGeomID o1, dGeomID o2){  dBodyID b1 = dGeomGetBody(o1);  dBodyID b2 = dGeomGetBody(o2);    dContact contacts[MAX_CONTACTS];  int i,numc;  if (numc = dCollide(o1,o2,MAX_CONTACTS,&contacts[0].geom,sizeof(dContact))){    for (i = 0;i < numc;i++){      contacts.surface.mode = dContactSlip1 | dContactSlip2 | dContactSoftERP | dContactSoftCFM | dContactApprox1;      contacts.surface.mu = dInfinity;      contacts.surface.slip1 = 0.1;      contacts.surface.slip2 = 0.1;      contacts.surface.soft_erp = 0.5;      contacts.surface.soft_cfm = 0.0;            dJointID c = dJointCreateContact(worldID,contactGroup,&contacts);      dJointAttach(c,b1,b2);    }  }}

##### Share on other sites
Quote:
 Original post by jakem3s90Which compiler / IDE are you using? Also, which graphics API are you using?I might be able to send you a some code to help you get started!

I'm using C with Dev-C++ and OpenGL :-) ALl open source stuff, but on windows ;-)
I would appreciate it soo much if you would write me up an example! :-) Thank you very much dude.

Gorax, I've read through most of the user manual but I dont quite get how I should structure everything, like, you can create a virtual object but how is the easiest way to read all those objects (and their coords) to draw them to the screen etc...

One useful thing I got from the manual though is this list which shows the sequence that your code should run in :-)

Quote:
 /* * A typical simulation will proceed like this: * 1. Create a dynamics world. * 2. Create bodies in the dynamics world. * 3. Set the state (position etc) of all bodies. * 4. Create joints in the dynamics world. * 5. Attach the joints to the bodies. * 6. Set the parameters of all joints. * 7. Create a collision world and collision geometry objects, as necessary. * 8. Create a joint group to hold the contact joints. * 9. Loop: * (a) Apply forces to the bodies as necessary. * (b) Adjust the joint parameters as necessary. * (c) Call collision detection. * (d) Create a contact joint for every collision point, and put it in the contact joint group. * (e) Take a simulation step. * (f) Remove all joints in the contact joint group. * 10. Destroy the dynamics and collision worlds. */

I put it in the header of my header as a reference for me :-)

##### Share on other sites
The examples are pretty complete in getting you up to speed on the various aspects. I recall printing out the docs as I used ODE initially for a program that (genetically) generated articulate motion for models. I should probably put some of it up somewhere as I had to write a custom loader to account for (ODE) physical aspects of the models.

##### Share on other sites
You can open .tar.gz files in WinZip by renaming the file with an extension .tgz