   ODE Collision Joint Problems
  I'm fairly new to physics programming, but in only a night's work I've managed to figure out the basics and have my rendered world match ODE's physical world.  At the moment I have two physical cubes dropping, and one has an impulse applied to it when you click the left mouse button.  This is to test what I'm currently working on: collision detection.  I'm trying to launch the lower cube upwards into the top cube and have them collide.I've gotten the physical geometries to match the size of the rendered geometries, and my collision callback event is registering the collision, but the joint is not forming and there is no reaction on the screen.  Here is my callback function code:static void nearCallback(void *data, dGeomID o1, dGeomID o2){dBodyID b1 = dGeomGetBody(o1);dBodyID b2 = dGeomGetBody(o2);dContact contact;contact.surface.mode = dContactBounce | dContactSoftCFM;contact.surface.mu = dInfinity;contact.surface.bounce = 0.9;contact.surface.bounce_vel = 0.1;contact.surface.soft_cfm = 0.001;if(int numc = dCollide(o1, o2, 1, &contact.geom, sizeof(dContact))){MessageBoxA(NULL, "Attempting to form Collision Joint", "nearCallback", MB_OK);dJointID c = dJointCreateContact(mWorld, mContactGroup, &contact);dJointAttach(c, b1, b2);if(b1 & b2 & dAreConnected(b1,b1))MessageBoxA(NULL, "Collision Joint Formed", "nearCallback", MB_OK);if(dJointGetType(c) == dJointTypeContact)MessageBoxA(NULL, "c is a Contact Joint", "nearCallback", MB_OK);}}The three message box calls are debugs I put in, which have confirmed that the collision is occurring, but the joint is not properly attaching the two objects.  The first and third message boxes appear, but the second does not.Any insights as to why this might be happening would be greatly appreciated.   
  Isn't that supposed to be dAreConnected(b1,b2) ?   ;  Ok, that was a stupid typo which I should have caught.  Now it shows that the joint is being successfully created.  However, there is no visible collision on screen.  The two objects simply pass through each other and then continue to fall into the void.  Is there something wrong with my collision parameters?   ;  I see that your flags argument in dCollide is 1. The Ode documentation says:Quote:flags specifies how contacts should be generated if the geoms touch.The lower 16 bits of flags is an integer that specifies the maximum number of contact points to generate. The number of contacts requested can't be zero.So basically you are asking Ode to generate 1 contact point which is too few to properly "push" the two boxes apart when they hit (and most likely intersect) each other. I normally use between 20 and 40 max contacts depending on the performance of the simulation. Also, feel free to experiment. You may be able to get away with as few as 5 or 10 max contacts.;  I've changed it to use 20 contact points, so my code is now:if(int numc = dCollide(o1, o2, 20, &contact.geom, sizeof(dContact))){dJointID c = dJointCreateContact(mWorld, mContactGroup, &contact);dJointAttach(c, b1, b2);}Now I get a crash (access violation reading location) at the next render loop immediately after the two blocks collide.I did some tests with the flags variable, and found that 1, 2, and 3 do not cause a crash but also get no results.  Once I put in 4 or more max contact points I start getting the crash and error.   ;dContact contact;should be dContact contact[20];now, and change &contact.geom to &contact[0].geom in the dCollide call.By the way, between 3 and 5 is probably the optimum amount of contacts to request.   ;  They now react to each other when they collide.  When they hit they both spin a little, but continue traveling down and pass right through each other.  I have the geometry size set to the size of my rendered box, so I don't think the collision box is the problem.  Do I need to set the size of the body somehow too?   ;  Do the boxes have a reasonable mass? You could try using dMassSetBoxTotal to distribute the mass throughout the box. Also, what value are you using in dWorldStep?   ;  This is the setup code for one of my boxes.  Both boxes are identical.Real size = ent1->getBoundingRadius();mBody = dBodyCreate(mWorld);mGeom = dCreateBox(mSpace, size, size, size);dMassSetBox(&m, 1, size, size, size);dBodySetMass(mBody, &m);dGeomSetBody(mGeom, mBody);dBodySetPosition(mBody, 0, 200, 0);Would artificially making the mass higher be better or worse?  Also, here is my world stepping call:dSpaceCollide(mSpace, 0, &nearCallback);dWorldQuickStep(mWorld, 0.01);dJointGroupEmpty(mContactGroup); [Edited by - MartyrOfKharak on May 22, 2010 1:13:33 PM];  Everything looks OK. There are any number of things that could be making the simulation not work right. You could try not using softCFM for the contact points. For example:dContact contact;contact.surface.mode = dContactBounce;contact.surface.bounce = 0.0;contact.surface.bounce_vel = 0.0;contact.surface.mu = dInfinity;contact.surface.mu2 = 0.0;contact.surface.soft_cfm = 0.0;is what I use.Because this is not a complicated simulation, you could also try using good-old dWorldStep instead of dWorldQuickStep. There is some information about this in this part of the Ode Manual. Quote:Would artificially making the mass higher be better or worse?You are currently setting the density of the box (in kg/m^3), not its total mass (see here for more info). Right now you are setting the density to 1 kg/m^3 which is less dense than the air we breathe. Increasing the density of the box, or simply giving it a reasonable mass, would make it more realistic. If it would help or not, I don't know. Try it and see. [smile]   