Problem with buoyancy

speps

28-03-2008 19:20:52

Hi,

I'm not a newbie with C++ programming, but new to Ogre. I'm currently using Ogre 1.4.7 and OgreNewt (with Newton 1.53) for the physics engine.

The buoyancy demo of OgreNewt doesn't run on my laptop but I read the code and reproduced the behavior in my own project.

Here is the code for the callbacks :


void PhysicsListener::forceCallback(OgreNewt::Body* me)
{
Ogre::Real mass;
Ogre::Vector3 inertia;

me->getMassMatrix(mass, inertia);

Ogre::Vector3 gravity = Ogre::Vector3(0, -9.8, 0) * mass;
me->addForce(gravity);

// also don't forget buoyancy force.
// just pass the acceleration due to gravity, not the force (accel * mass)!
// first parameters : fluidDensity, fluidLinearViscosity, fluidAngularViscosity
me->addBouyancyForce(0.7, 0.1, 0.1, Ogre::Vector3(0.0f, -9.8f, 0.0f), &PhysicsListener::buoyancyCallback);
}

bool PhysicsListener::buoyancyCallback(int colID, OgreNewt::Body* me, const Ogre::Quaternion& orient, const Ogre::Vector3& pos, Ogre::Plane& plane)
{
// here we need to create an Ogre::Plane object representing the surface of the liquid. in our case, we're
// just assuming a completely flat plane of liquid, however you could use this function to retrieve the plane
// equation for an animated sea, etc.
plane = Ogre::Plane(Ogre::Vector3(0,1,0), Ogre::Vector3(0,0,0));

return true;
}

These functions are declared static.

And the callback is set here :

body->setCustomForceAndTorqueCallback(&PhysicsListener::forceCallback); // gravity + buoyancy

If I call setStandardForceCallback() instead it works very well but with only gravity obviously.

Here is a little video of the problem :
http://speps.fr/pub/buoyancy-problem.avi (2.2mb)

Any help will be appreciated. Thanks.

speps.

PS : at first, I posted that in the general help forum, sorry about that

speps

31-03-2008 13:55:12

Hi,

I would really like some help on this one, please.
I can give any other information wanted by anyone.
Thanks.

speps.