
6.3 S tiff Springs 101
Excerpt from file src/pfgen.cpp
void ParticleBuoyancy::updateForce(Particle* particle, real duration)
{
// Calculate the submersion depth.
real depth = particle->getPosition().y;
// Check if we’re out of the water.
if (depth >= waterHeight + maxDepth) return;
Vector3 force(0,0,0);
// Check if we’re at maximum depth.
if (depth <= waterHeight - maxDepth)
{
force.y = liquidDensity * volume;
particle->addForce(force);
return;
}
// Otherwise we are partly submerged.
force.y = liquidDensity * volume *
(depth - maxDepth - waterHeight) / 2 * maxDepth;
particle->addForce(force);
}
I have assumed in this code that the buoyancy is acting in the up