Jump to content
  • Advertisement
Sign in to follow this  
rjackets

OpenGL ODE and DirectX

This topic is 4861 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

i everyone. I've done a lot of looking around but I can't seem to find much about this topic. The samples that come with the ODE SDK are all done in OpenGL so I need a couple pointers in the right direction. In particular, since ODE is graphics API independant how do I go about using *.X files with it? Can I use a directx "mesh" object in any way or will I need to lock it and use raw vertex data? Second, I'm not completely sure about the pipeline of the ODE. From what I understand the process is: 1) Set up world and spaces (what is a space?) 2) Create bodies and position/configure them (this is mostly where I'm getting hung up) 3) each frame use dQuickStep (or something along those lines) and have a callback function for what to call when you get a collision. All help is appreciated. Thanks. PS. If anyone knows of any barebones ODE tutorials I would appreciate any links too.

Share this post


Link to post
Share on other sites
Advertisement
ODE has dBodyGetPosition and dBodyGetRotation functions that you can call on each body. You can setup a D3D transformation matrix w/ this data for the mesh when rendering it.

Share this post


Link to post
Share on other sites
Okay, I see where you're going with this. So I think I understand now how to use the primitive collisions, but what if I want to use a "trimesh" collision?

Share this post


Link to post
Share on other sites
Quote:
Original post by rjackets
In particular, since ODE is graphics API independant how do I go about using *.X files with it?

You don't.
Quote:

Can I use a directx "mesh" object in any way or will I need to lock it and use raw vertex data?

I don't see any way you are going to be able to use ODE's tri mesh stuff without locking. Once you have locked it should be fairly trivial though: dGeomTriMeshDataBuild allows you to specify a stride, so as long as your position data is the first thing in your vert you should be able to use the locked data directly. If that does not work, or if you also want to use normals you may have to copy the data out into vector3 arrays.
Quote:

Second, I'm not completely sure about the pipeline of the ODE. From what I understand the process is:
1) Set up world and spaces (what is a space?)
2) Create bodies and position/configure them (this is mostly where I'm getting hung up)
3) each frame use dQuickStep (or something along those lines) and have a callback function for what to call when you get a collision.

I think you have it about right. I chose not to use ODE myself, but I spent some time researchig it and it seems that most of these engines work in this sort of way. Set the positions/masses/velocities of stuff, call Step() or the equiv, read the positions and stuff back (many of which may have changed by stepping) and use it to update your graphics.

Share this post


Link to post
Share on other sites
Okay, now I realize this is now outside the realm of DirectX specific help but I figured I'd put it in the same thread for consistency. I've gotten it running so that my objects are linked to the ODE system... So now it starts 10 units above the floor and it falls properly. The floor is made with dCreatePlane(...) and the object colliding with it is a basic sphere. The collision is being detected as it is supposed to be, but it is not responding to it -- it basically just goes through the floor. The rotational momentum changes ever-so-slightly so it is detectable. I set it to stop calculating the physics when it collides, so it clearly is colliding. So my question is: is there anything I have to do to explicitly specify how to behave when it collides? I have the following nearCallback (like in the samples). All help would be greatly appreciated -- and once I get the barebones sample working I swear I'll make a public tutorial since it seems a lot of people are looking for them ;)

here is my nearCallback code:


static void nearCallback(void *data, dGeomID o1, dGeomID o2)
{
int i;

// if bodies are connected by a joint, return
dBodyID b1 = dGeomGetBody(o1);
dBodyID b2 = dGeomGetBody(o2);
if(b1 && b2 && dAreConnectedExcluding (b1, b2, dJointTypeContact))
return;

dContact contact[MAX_CONTACTS]; // up to MAX_CONTACTS per box
for(i=0; i<MAX_CONTACTS; i++)
{
contact.surface.mode = dContactBounce | dContactSoftCFM;
contact.surface.mu = dInfinity;
contact.surface.mu2 = 0;
contact.surface.bounce = 0.1;
contact.surface.bounce_vel = 0.1;
contact.surface.soft_cfm = 0.01;
}
if(int numc = dCollide(o1, o2, MAX_CONTACTS, &contact[0].geom,
sizeof(dContact)))
{
collided = TRUE;

for(i=0; i<numc; i++)
{
dJointID c = dJointCreateContact(world, contactgroup, contact+1);
dJointAttach(c, b1, b2);
}
}
}



Share this post


Link to post
Share on other sites
ummm, nevermind. I must have missed something when I was working through this. I just tried a direct cut-and-paste from the sample code and it works fine [wink].

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!