[ODE] Step by step guide to ODE
Pierre-Laurent CHAMBERT
pilo.c at wanadoo.fr
Wed Jul 12 10:13:15 MST 2006
ok here's my basic stuff in my Physics module
------------------------------------------------------------
Init :
m_World = dWorldCreate();
m_Space = dHashSpaceCreate(0);
m_ContactGroup = dJointGroupCreate(0);
// setup default world
dWorldSetGravity(m_World, 0.0, -9.81, 0.0);
dWorldSetCFM(m_World, 1e-5);
dWorldSetERP(m_World, 0.8);
dWorldSetAutoDisableFlag (m_World,1);
dWorldSetContactMaxCorrectingVel (m_World,0.1);
dWorldSetContactSurfaceLayer (m_World,0.001);
// add debug plane
m_StaticPlane = new GroundObject();
------------------------------------------------------------
------------------------------------------------------------
then to add a body + is collision shape :
m_Body = 0;
m_Geom = 0;
// create a sphere, 11cm radius
m_Body = dBodyCreate(PhysicsManager::Inst().QueryWorld());
dMassSetSphere (&m, 0.95f, 0.11f);
m_Geom = dCreateSphere (PhysicsManager::Inst().QuerySpace(), 0.11f);
dBodySetMass (m_Body,&m);
dGeomSetBody(m_Geom, m_Body);
------------------------------------------------------------
------------------------------------------------------------
next the collision callback func
int i;
// if (o1->body && o2->body) return;
PhysicsManager * pm = (PhysicsManager *)data;
// exit without doing anything if the two bodies are connected by a joint
dBodyID b1 = dGeomGetBody(o1);
dBodyID b2 = dGeomGetBody(o2);
if (b1 && b2 && dAreConnectedExcluding (b1,b2,dJointTypeContact)) return;
BaseObject *obj1 = (BaseObject *)dGeomGetData(o1);
BaseObject *obj2 = (BaseObject *)dGeomGetData(o2);
//printf("%d - %d\n", obj1, obj2);
assert(obj1 != NULL && obj2 != NULL);
float friction = obj1->GetFriction() < obj2->GetFriction()?
obj1->GetFriction() : obj2->GetFriction();
dContact contact[MAX_CONTACTS]; // up to MAX_CONTACTS contacts per box-box
for (i=0; i<MAX_CONTACTS; i++) {
contact[i].surface.mode = dContactBounce | dContactSoftCFM |
dContactMu2;// | dContactSlip1 | dContactSlip2;
contact[i].surface.mu = friction;
contact[i].surface.bounce = 0.7f;
contact[i].surface.bounce_vel = 0.1f;
contact[i].surface.soft_cfm = 0.01f;
}
if (int numc = dCollide (o1,o2,MAX_CONTACTS,&contact[0].geom,
sizeof(dContact))) {
for (i=0; i<numc; i++) {
dJointID c = dJointCreateContact (pm->m_World, pm->m_ContactGroup,
contact+i);
dJointAttach (c,b1,b2);
}
}
friction comes from my own rigidbody class, ignore it, use a value like
dInfinity
------------------------------------------------------------
------------------------------------------------------------
the the sim loop
void PhysicsManager::Integrate()
{
dSpaceCollide (m_Space, this, &PhysicsManager::ODENearCallback);
dWorldQuickStep (m_World, FixedPhysicFrameRate);
dJointGroupEmpty (m_ContactGroup);
}
I hope this can help you :)
On Wednesday 12 July 2006 18:20, michael kapelko wrote:
> somewhere in SimLoop, but i'm lost in the code, it's TOO much for the
> beginning
> i had a look at Bounce, but it's hard either. i don't get all these
> classes, enormous amount of bodies.
> i simply want very-very basic world, space, body, second body, collision
> to get at least some clue in ODE
> thanks.
> _______________________________________________
> ODE mailing list
> ODE at q12.org
> http://q12.org/mailman/listinfo/ode
More information about the ODE
mailing list