Betajaen's Fluid Plane Thread

betajaen

04-06-2007 00:02:18

The next big thing in in 0.9 will be Fluids, I've already written the Fluid class which works fine. The FluidMesh has a bug in it which I'm sure it's my fault with the description but once that is fixed, we can all enjoy real-time fluids.

For a slightly different story; is buoyancy which isn't really supported with the particle fluid system (Well technically you can, you just need an insane amount of fluid particles to do it with).

So I present a basis for some good old buoyancy (Stolen and rewritten from one of the threads in the Ageia forums):

Actors* mActors;

mActors = mScene->getActors();

for(Actors::Iterator it = mActors->items.begin();it != mActors->items.end();++it) {

NxVec3 bs = (*it).second.first->getNxActor()->getGlobalPosition();
NxReal oceanHeight = 5 + NxMath::rand(-0.25,0.25f);
NxReal diff = bs.y - oceanHeight;
NxReal mass = (*it).second.first->getMass();

if (diff < 0) {
(*it).second.first->setLinearDamping(1.0f);
NxReal displacement = -diff * 0.10f;
(*it).second.first->addForce(Vector3(0, 9.8 * mass * displacement,0), NX_SMOOTH_IMPULSE);
}
else {
(*it).second.first->setLinearDamping(0.01f);
}
}


Obviously there are a few things to change.

1. Not all of the actors would be in the water, only a few. So they'd have to be filtered using a trigger or an intersection.

2. Water height's aren't random, they use waves - so a perlin noise would do the trick.

3. The code doesn't take into account of horizontal movement of water such as rivers.

4. Displacement should be how much of the body is underneath the water, not a random guess there.


Either way, it's a good start for anyone to have a stab at it and if anyone wants to - please do. It's going to be a while before I do. :D