I'm trying to do a simple object bounce off a ground plane. The problem I'm encountering is that, when an object collides with the ground plane, the y-component of its velocity is not what is being adjusted (despite the normal vector of the collision being (0,1,0) ). Instead, the z-component is adjusted, causing the object to shoot off in the -z direction once underground, while still falling according to gravity (parabolic motion).
I've scoured the web for as many tutorials as I could find, and searched to my best efforts through these forums for any info, but have not found anything similar to this problem.
So, does anyone know why it might be changing the z-component instead of the y-component of the object's velocity? Any help would be greatly appreciated as this has been driving me a tad crazy. Thanks!
void initODE(){ World = dWorldCreate(); MAX_CONTACTS=20; Space = dSimpleSpaceCreate(0); contactgroup = dJointGroupCreate(0); dCreatePlane(Space, 0, 1, 0, 0); dWorldSetGravity(World, 0, -9.8, 0); dWorldSetERP(World, 0.2); dWorldSetCFM(World, 1e-5); dWorldSetContactMaxCorrectingVel(World, 0.9); dWorldSetContactSurfaceLayer(World, 0.001); dWorldSetAutoDisableFlag(World, 0);}void worldObject::addToWorld(){ dMatrix3 R, R1,R2,R3,R4; float DEGTORAD=3.1415/180.0; Body = dBodyCreate(World); dBodySetPosition(Body, pos.x, pos.y, pos.z); dBodySetLinearVel(Body, 0,0,0); switch (type) { case (RECTANGLE): { dMassSetBox(&Mass, 1,width, height, length); Geom = dCreateBox(Space, width, height, length); break; } case (SPHERE): { dMassSetSphere(&Mass, 1, radius); Geom = dCreateSphere(Space, radius); break; } case (CYLINDER): { dMassSetCylinder(&Mass, 1, 1, radius1, length_cyl); // Geom = dCreateCCylinder(Space, radius1, length_cyl); break; } } dBodySetMass(Body, &Mass); dGeomSetBody(Geom, Body); // Get the rotation from the editing and apply it dRFromAxisAndAngle(R1,0,0,1,chi*DEGTORAD); dRFromAxisAndAngle(R2,0,1,0,phi*DEGTORAD); dRFromAxisAndAngle(R3,1,0,0,theta*DEGTORAD); dMULTIPLY0_333(R4,R1,R2); dMULTIPLY0_333(R,R4,R3); dBodySetRotation(Body, R);}static void nearCallback (void *data, dGeomID o1, dGeomID o2){ int i; dBodyID b1 = dGeomGetBody(o1); dBodyID b2 = dGeomGetBody(o2); dContact contact[MAX_CONTACTS]; for (i = 0; i < MAX_CONTACTS; i++) { contact.surface.mode = dContactBounce | dContactSoftCFM; contact.surface.mu = dInfinity; contact.surface.mu2 = 0; contact.surface.bounce = 0.51; contact.surface.bounce_vel = 0.1; contact.surface.soft_cfm = 1.01; } if (int numc = dCollide(o1, o2, MAX_CONTACTS, &contact[0].geom, sizeof(dContact))) { for (i = 0; i < numc; i++) { dJointID c = dJointCreateContact(World, contactgroup, &contact); dJointAttach(c, b1, b2); } }} void collide(){ dSpaceCollide(Space, 0, &nearCallback); dWorldQuickStep(World, gameTime); dJointGroupEmpty(contactgroup); }