Buoyancy like in Newton

Post Reply
zbuffer
Posts: 8
Joined: Sat Jan 05, 2013 11:13 am

Buoyancy like in Newton

Post by zbuffer »

Hello!

I would like to port buoyancy force calculation from Newton to Bullet. I have seen the hightfield fluid demo but the Newton way is simpler and calculates the volumes directly.

Steps I have to implement include:
1. Create a pool which is not colliding with objects but works as a trigger
2. Check if a dynamic body overlaps the trigger -> is cutting the surface or is inside
3. Find distance from the body center to the trigger surface in opposite direction to the gravity
4. Calculate the submerged volume
5. Apply buoyancy force, apply some damping

I started to implement it and I'm stuck.
I have created the pool as a Ghost Object and I have set up a Simulation Tick Callback to process the
overlapping pairs managed by the Ghost.
In the callback I go through the overlapping pair cache and for every pair I cast the proxy->m_clientObject as btCollisionObject and if one of them is equal to Ghost then I run the buoyancy calculation for the other.
In the buoyancy calculation I use rayTestSingle to shoot a ray at the Ghost. I then draw the hit points for debugging and here comes a problem.

I have realized that the rayTestSingle works only when the ray is hitting the Ghost surface from the outside. If the body center is inside the Ghost there is no hit. It is clearly visible because the hit points occur only at the bottom of the Ghost - when the body is leaving the Ghost and the ray is poiniting at the outside of the bottom surface.

Is there a way to register hits from the inside?

Maybe I do everything wrong? Is there a different approach to do it?

Best
Post Reply