Blue
27-02-2008 21:22:19
hi all,
It hasn't to do with OgreOde, but I don't know where i should put it,
i use only ode and i have problem with "collisioncallback function", here is the code that I use:
I've made a sphere and i get an error when the object collide with the ground, here is an screen shoot:
![]()
[url=http://www.freeimagehosting.net/][img="http://img3.freeimagehosting.net/uploads/0ec72b7d32.jpg" alt=""]
![]()
[url=http://www.freeimagehosting.net/][img="http://img3.freeimagehosting.net/uploads/37b05f1aaa.jpg" alt=""]
thanks in advance.
It hasn't to do with OgreOde, but I don't know where i should put it,
i use only ode and i have problem with "collisioncallback function", here is the code that I use:
void OdeWorld::collisionCallback(void *data,dGeomID o1,dGeomID o2)
{
// Get a pointer back to the frame listener that called us
OdeWorld *world = (OdeWorld*)data;
// Get all the contacts
const int N = 100;
dContact contact[N];
int n = dCollide (o1,o2,N,&contact[0].geom,sizeof(dContact));
// If we had some contacts...
if(n > 0)
{
// Get the world and contact group IDs just the once
dWorldID wid = world->getWorld()->id();
dJointGroupID cid = world->getContactGroup()->id();
// Process all the contacts
for(int i=0; i<n; i++)
{
// Extra to use when we're colliding spheres
dGeomID ball = 0;
unsigned int flags = 0;
// Check to see if one of the colliding things is a sphere
if(dGeomGetClass(contact[i].geom.g1) == dSphereClass)
{
ball = contact[i].geom.g1;
}
else if(dGeomGetClass(contact[i].geom.g2) == dSphereClass)
{
ball = contact[i].geom.g2;
}
// If one of the colliding things is a sphere then...
if(ball)
{
// Get the body that this sphere uses
dBodyID body = dGeomGetBody(ball);
if(body)
{
// Get the first joint that connects the sphere to somewhere else
dJointID joint = dBodyGetJoint(body,0);
// Get the other body that this joint is connected to
dBodyID other_body = dJointGetBody(joint,0);
if(other_body == body)
{
other_body = dJointGetBody(joint,1);
}
// If there is another body (i.e. the body's not connected to the static world)...
if(other_body)
{
// Set the flags for sideways slip
flags = dContactFDir1 | dContactSlip2;
// Get the velocity of the body at its circumference
dVector3 vel;
dBodyGetRelPointVel(body,0,dGeomSphereGetRadius(ball),0,vel);
// If it's a hinge2 joint then we have to allow for steering
if(dJointGetType(joint) == dJointTypeHinge2)
{
dVector3 fdir,norm;
dMatrix3 rot;
// Find out how much we're steering
dReal steer = (dJointGetHinge2Param (joint, dParamLoStop) + dJointGetHinge2Param (joint, dParamHiStop)) * 0.5;
// Get the up and forward vectors with respect to the
// body the wheel's attached to
dBodyVectorToWorld(other_body,0,1,0,norm);
dBodyVectorToWorld(other_body,0,0,1,fdir);
// Rotate the forward vector around the up
// vector by the amount we're steering
dRFromAxisAndAngle(rot,norm[0],norm[1],norm[2],steer);
dMultiply0(contact[i].fdir1,rot,fdir,3,3,1);
}
else
{
// Otherwise, just get the direction in which the body it's
// attached to (i.e. the axle or car body) is pointing
dBodyVectorToWorld(other_body,0,0,1,contact[i].fdir1);
}
// Set the slip to be proportional to the tyre constant and the velocity of the tyre
//contact[i].surface.slip2 = phy->getTyre() * dSqrt(vel[0]*vel[0] + vel[1]*vel[1] + vel[2]*vel[2]);
}
}
}
// Set up the contact parameters
contact[i].surface.mode = flags | dContactSoftERP | dContactSoftCFM | dContactApprox1;
contact[i].surface.mu = world->getMu();
contact[i].surface.soft_erp = world->getERP();
contact[i].surface.soft_cfm = world->getCFM();
// Create and attach the contact joints
dJointID c = dJointCreateContact(wid,cid,&contact[i]);
dJointAttach (c,dGeomGetBody(contact[i].geom.g1), dGeomGetBody(contact[i].geom.g2));
}
}
}
I've made a sphere and i get an error when the object collide with the ground, here is an screen shoot:
[url=http://www.freeimagehosting.net/][img="http://img3.freeimagehosting.net/uploads/0ec72b7d32.jpg" alt=""]
[url=http://www.freeimagehosting.net/][img="http://img3.freeimagehosting.net/uploads/37b05f1aaa.jpg" alt=""]
thanks in advance.