I am trying to simulate a buoyancy force for objects submerged/suspended in a fluid in a 2D environment.
Game Physics: Engine Development: How to Build a Robust Commercial-Grade Physics Engine for Your Game by Ian Millington (Chapter 6, page 99) (ISBN 987-0-12-381976-5) AND the wikipedia article on buoyancy the actual calculation is:
P is the density of the fluid.
V is the submerged volume (area) and
G is the gravitational acceleration (0.00980665 Kilo-Newtons for Earth, but is variable in the code) and always acts in the opposite direction to gravity.
The code I have, below, produces a clean-looking result, but obviously the density of either the object in question or the fluid is not effecting the calculation, only the mass. If I insert the density of the fluid, say, water, at 1000.0 kg/m^3 the whole system explodes.
Is it something simple that I missed or did I screw up entirely?
The code I have so far:
//area_ratio is a scalar ratio of the area inside the defined fluid area (Volume submerged) and the entire object's bounding area (entire volume). //area_ratio is equal to a value in the interval [0.0, 1.0] //gravity is a force vector in Kilo-Newtons. Vector2D current_weight(mass * area_ratio * gravity); //current_area = The area inside the fluid. (Volume submerged) Vector2D buoyancy(gravity.Normalize() * -current_weight * current_area); //Forces and Impulses are automatically converted to Netwons by multiplying the values passed in by 1000.0 object->ApplyImpulse(buoyancy);