I've done my best at understanding the buoyancy system but there's something I'm missing. When a body enters the buoyancy region is never seems to come to rest and leaps out of the water and sinks down in a never ending cycle - it does eventually come to rest but, this takes maybe 5 minutes and even then doesn't appear totally stable.
The density I pass to NewtonBodyAddBuoyancyForce is calculated via Density=((Viscosity * Mass) / Volume), where Viscosity is 1.5 (taken from the Newton SDK buoyancy example), Viscosity is perhaps a misnomer here so you could call it 'DensityScale' instead I suppose and the mass and volume are returned by the respective Newton functions within the Buoyancy callback. The plane equation is passed to the plane callback and is correct when stepped through in the debugger and aligns correctly to the graphics body and physics object, (currently (0,1,0,40) - where 40 equals surface height in units from world origin).
The mass of the box is 350 and it is 10x10x10, gravity is 9.8 so the box has a downward, (0,-1,0) force of 3430 (give or take floating point error) applied in the force and torque callback.
The code for the Buoyancy callback is currently:
- Code: Select all
const NewtonBody* pBody=Body0;
const NewtonBody* pTrigger=Body1;
if(NewtonCollisionIsTriggerVolume(NewtonBodyGetCollision(Body0)))
{
pBody=Body1;
pTrigger=Body0;
}
WaterVolumeInfo WaterInfo=*(WaterVolumeInfo*)NewtonBodyGetUserData(pTrigger);
dFloat fMass;
dFloat fDummy;
NewtonBodyGetMassMatrix(pBody,&fMass,&fDummy,&fDummy,&fDummy);
dFloat fVolume=NewtonConvexCollisionCalculateVolume(NewtonBodyGetCollision(pBody));
dFloat fDensity=((WaterInfo.fViscosity * fMass) / fVolume);
D3DXVECTOR3 Gravity=Physics_GetGravity();
NewtonBodyAddBuoyancyForce(pBody,fDensity,0.8f,0.8f,&Gravity.x,GetPhysicsBuoyancyPlane,(void*)WaterInfo.Plane);
return(1);
This is a video of what currently happens Buoyancy Problem, 3044kb Indeo Video 5.1 avi.
Please excuse the poor video quality. I've checked things like, making sure the water graphics line up with the physics representation etc, the debug display is on (although you can barely tell in the video). I think that the density calculated is too great and is overcoming gravity and throwing the body out but, the body still behaves strangely even if that is the case. I've tried reproducing this error using the SDK but it works when I create a box of the same size and mass and doesn't display this problem.
Does anyone recognise this symptom or could possibly suggest steps I could take to sort it?
Just to double check, my understanding is that;
liquidMass = liquidDensity * bodyVolume and,
BodyMass = liquidMass = liquidDensity * BodyVolume
so,
liquidDensity = BodyMass / BodyVolume;
Is that correct or am I doing it all wrong?
Ideally I'd like to be able to configure the WaterInfo.fViscosity so one value makes objects sink more and a different (higher/lower) value makes objects float more.
Thanks for any help.