addBouyancyForce woes

chuddle

11-09-2007 06:19:38

I seem to be unable to get the buoyancy system working right. I'm sure I'm doing something simple.

Constructor for the hull

Hull::Hull(...)
{
.
.
.
massHull = 10000;

bodyHull = new OgreNewt::Body( nworld, compound );
delete col;
delete compound;
bodyHull->setMassMatrix(massHull, inertia * massHull);
bodyHull->setCenterOfMass(offset);

bodyHull->attachToNode(nodeHull);
bodyHull->setPositionOrientation(position, orient);
bodyHull->setMaterialGroupID(sim->Materials["Material_BargeHull"]);
bodyHull->setCustomForceAndTorqueCallback<Hull>(&Hull::customForceCallback, this );
bodyHull->setUserData(this);
}


Then the customForceCallback


void Hull::customForceCallback(OgreNewt::Body *me)
{
Hull *pHull = (Hull *)me->getUserData();

Ogre::Vector3 grav(0.0, -9.8, 0.0);
grav *= pHull->massHull;
me->addForce(grav);
me->addBouyancyForce<Hull>( 1.0, 0.5, 0.5, Ogre::Vector3(0.0f, -9.8f, 0.0f), &Hull::buoyancyCallback, this );
}


then the buoyancy callback

bool Hull::buoyancyCallback(int Colid, OgreNewt::Body* me, const Ogre::Quaternion& orient, const Ogre::Vector3& pos, Ogre::Plane& plane)
{
//plane = Ogre::Plane( Ogre::Vector3(0,1,0), Ogre::Real(76) );
plane = Ogre::Plane( Ogre::Vector3(0,1,0), Ogre::Vector3(0,0,0) );

return true;
}


What happens is that the body falls right through the buoyancy plane and keeps going. The collision is full sized around the mesh.

The collision encompasses a volume of ~380 cubic meters - so it should still be (380000-10000) = (370000 kg * 9.8) almost 3.7 million newtons buoyant - I knocked the weight down to 100 kg with no change. The fluid density is at 1, but moved that up and down a bit with no change.

In the debugger I can see the the custom callback is getting called (also evidenced by the falling) - and I can see that the buoyancy callback is getting called every frame. It's producing a UNIT_Y normal plane with the proper displacement and returning true.

Ack! Have spent several days off and on re-implementing in different ways. I'm sure I've just totally missed something. Can anyone make a suggestion?

Thanks again!