• Create Account

## Simple ODE Example / Tutorial

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.

13 replies to this topic

### #1xyuri  Members

Posted 19 February 2005 - 11:42 PM

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

### #2jakem3s90  Members

Posted 19 February 2005 - 11:57 PM

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!

### #3xyuri  Members

Posted 20 February 2005 - 12:07 AM

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

### #4xyuri  Members

Posted 20 February 2005 - 12:29 AM

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 :-(

### #5Spudder  Members

Posted 20 February 2005 - 06:59 AM

winrar always does the job for me regarding .tar/.tar.gz archives.

### #6SirLuthor  Members

Posted 20 February 2005 - 07:04 AM

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

### #7Drew_Benton  Members

Posted 20 February 2005 - 08:51 AM

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.

### #8xyuri  Members

Posted 20 February 2005 - 10:03 AM

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.

### #9xyuri  Members

Posted 22 February 2005 - 01:08 AM

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

### #10jakem3s90  Members

Posted 22 February 2005 - 01:48 AM

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!

### #11Gorax  Members

Posted 22 February 2005 - 02:07 AM

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;
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 16
void 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[i].surface.mode = dContactSlip1 | dContactSlip2 | dContactSoftERP | dContactSoftCFM | dContactApprox1;
contacts[i].surface.mu = dInfinity;
contacts[i].surface.slip1 = 0.1;
contacts[i].surface.slip2 = 0.1;
contacts[i].surface.soft_erp = 0.5;
contacts[i].surface.soft_cfm = 0.0;

dJointID c = dJointCreateContact(worldID,contactGroup,&contacts[i]);
dJointAttach(c,b1,b2);
}
}
}



### #12xyuri  Members

Posted 22 February 2005 - 09:52 AM

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. * © 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 :-)

### #13Brandon N  Members

Posted 23 February 2005 - 12:09 AM

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.

### #14dexterace  Members

Posted 23 February 2005 - 08:31 AM

You can open .tar.gz files in WinZip by renaming the file with an extension .tgz

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.