I don't know how well-researched you guys are about how to get SPH particles vs solid bodies interacting properly. If you know about this (white papers, source code examples, etc), it'd be useful to me to know about them. I haven't been able to find a huge amount of resources, but the ones I have found have all advocated a Verlet integration type approach, with two main rules:
1 - If a particle intersects with static geometry, just apply a big enough force in the right direction to push the particle back out again.
2 - If a particle intersects with dynamic geometry... It gets weird. All of the approaches I've seen represent a solid (but movable) body as a bunch of particles representing the verts, let them mix up in the fluid every frame, and at the end apply constraints to "pop" the particles back into something representing a solid shape.
The reason I bring all this up now is because I've been trying Boris' "option 5" from his earlier post. Namely, to filter all of the particles such that they just fall through the world, generating pairs but not generating any contact points, allowing me to iterate through the relevant pairs and dealing with them myself (I figured it was a step towards trying "option 3", where the particles don't exist in the broadphase at all and using AABB queries to find out what needs processing by hand). The prerequisite for both approaches is handling the interaction between fluid and non-fluid ourselves, and I think that's important. Representing particles as small circular solid bodies doesn't really work - the interactions with the static bodies aren't bad but, for instance, try making the box have a low enough density to float on the fluid. Doesn't work. I think if the fluid simulation is going to be "correct" or useful, the approach should really be non-solid particle bodies that are affected by the environment, and can apply forces to the movable parts of it.
Anyway, I've started by trying to get the particles to not intersect with the static geometry (no attempt at having them move the box yet). For debugging, my code draws pairs (in red) when intersections take place, and draws the points they should move to (blue points) to get out of the geometry. I've followed ewjordan's lead of just setting positions directly rather than calculating forces, since the particles don't really interact inside the engine anyway. I'm doing something wrong, though. The particles bleed and tunnel through the geometry whatever I try to do to seperate them from the solid geometry. If anyone knows how fluid/non-fluid interactions should work can take a look at it and let me know where I've gone wrong, that would be ace. I had to fudge b2World to give an accessor to the broadphase, so that I could examine the pairs - pretty simple, just add the following into b2World.h, somewhere public:
(Also, I've not performance-profiled this approach yet, but from watching it onscreen it seems a lot quicker to me)
1 - If a particle intersects with static geometry, just apply a big enough force in the right direction to push the particle back out again.
2 - If a particle intersects with dynamic geometry... It gets weird. All of the approaches I've seen represent a solid (but movable) body as a bunch of particles representing the verts, let them mix up in the fluid every frame, and at the end apply constraints to "pop" the particles back into something representing a solid shape.
The reason I bring all this up now is because I've been trying Boris' "option 5" from his earlier post. Namely, to filter all of the particles such that they just fall through the world, generating pairs but not generating any contact points, allowing me to iterate through the relevant pairs and dealing with them myself (I figured it was a step towards trying "option 3", where the particles don't exist in the broadphase at all and using AABB queries to find out what needs processing by hand). The prerequisite for both approaches is handling the interaction between fluid and non-fluid ourselves, and I think that's important. Representing particles as small circular solid bodies doesn't really work - the interactions with the static bodies aren't bad but, for instance, try making the box have a low enough density to float on the fluid. Doesn't work. I think if the fluid simulation is going to be "correct" or useful, the approach should really be non-solid particle bodies that are affected by the environment, and can apply forces to the movable parts of it.
Anyway, I've started by trying to get the particles to not intersect with the static geometry (no attempt at having them move the box yet). For debugging, my code draws pairs (in red) when intersections take place, and draws the points they should move to (blue points) to get out of the geometry. I've followed ewjordan's lead of just setting positions directly rather than calculating forces, since the particles don't really interact inside the engine anyway. I'm doing something wrong, though. The particles bleed and tunnel through the geometry whatever I try to do to seperate them from the solid geometry. If anyone knows how fluid/non-fluid interactions should work can take a look at it and let me know where I've gone wrong, that would be ace. I had to fudge b2World to give an accessor to the broadphase, so that I could examine the pairs - pretty simple, just add the following into b2World.h, somewhere public:
Code:
inline b2BroadPhase* GetBroadphase() { return m_broadPhase; }
(Also, I've not performance-profiled this approach yet, but from watching it onscreen it seems a lot quicker to me)