Take a look at the JBox2d examples (grab from svn https://jbox2d.svn.sourceforge.net/svnroot/jbox2d). We have a working simulation of fluids, we just haven't really incorporated it into the engine. Runs pretty fast though.
Fluid Simulation
General DiscussionWell I just want to know if anybodys got that SPH stuff working along with the C++ box2d version. Cause if I can work that into my engine it would add a whole 'nother dimension to its capabilities.
Hey,
Im trying to check the simulation but I can't get it to work properly... looks like there's a box containing the fluid particles and they're not really interacting with the falling box.
I think there must be a scale parameter set wrong.
To implement the FluidTest files into the TestBed project I just added the relevant #include and entry in TestEntry.
Any idea how to set it correctly?
Thanks,
MJ
See the image for what I mean.
http://img268.imageshack.us/i/screenqfb.png/

Im trying to check the simulation but I can't get it to work properly... looks like there's a box containing the fluid particles and they're not really interacting with the falling box.
I think there must be a scale parameter set wrong.
To implement the FluidTest files into the TestBed project I just added the relevant #include and entry in TestEntry.
Any idea how to set it correctly?
Thanks,
MJ
See the image for what I mean.
http://img268.imageshack.us/i/screenqfb.png/

Sorry, I haven't been around much in these forums recently. For what it's worth, I've been working very hard for months on developing the fluid physics, and the solution (for me at least) involves very little Box2D, so I've not been a regular visitor to these forums. For those who are interested, I'll give the following summary of what I've learned:
- With all due respect to ewjordan, who got me started down this route with his Java code, his implementation is flawed in a number of ways. I know this now because I had to go "back to basics" and really study the maths behind the papers which the implementation is based on to work out what was missing/wrong.
- Box2D is not cut out for fluid physics. It can't be added easily to the existing system, and in my opinion it would be detrimental to the engine to do so. Box2D is a really great 2D rigid-body physics engine (one which still forms a major part of the game I'm working on), and it should be left at that. In my experience, adding fluid physics involves all kinds of wacky stuff (OpenMP code to make the logic multithreaded, or possibly a CUDA implementation, or something similar based on OpenCL when that becomes available), and aside from the interactions with the rest of the world, as detailed earlier in this thread, Box2D doesn't really play a big part in that. I'm still 100% happy with what Box2D does, but I don't advocate adding fluid physics to its "bag of tricks". It's just too big a change, and would impact negatively on the engine.
- Fluid physics is hard. Whilst I still think it's going to be a big deal in games over the next few years, right now it comes with serious trade-offs with regards to development time, processing efficiency, and stability. It's not something for the faint-hearted, and whilst I'm one of the mentalists that's making it a central aspect of my game, I'd advise others against it until the techniques become more well understood in a realtime environment, and some genius puts a flexible and stable engine together to make it happen.
All that said, what exactly is the problem you're having mattjakob? Are the particles not falling down from the box they're spawned in? That implies a problem with the gravity setting in your b2world to me. In the test code, the fluid physics doesn't kick in until the particles have fallen a bit - they start outside the grid in which the processing happens, and fall into it before starting to behave like fluids. If they're not falling at all, it seems like gravity is the issue.
- With all due respect to ewjordan, who got me started down this route with his Java code, his implementation is flawed in a number of ways. I know this now because I had to go "back to basics" and really study the maths behind the papers which the implementation is based on to work out what was missing/wrong.
- Box2D is not cut out for fluid physics. It can't be added easily to the existing system, and in my opinion it would be detrimental to the engine to do so. Box2D is a really great 2D rigid-body physics engine (one which still forms a major part of the game I'm working on), and it should be left at that. In my experience, adding fluid physics involves all kinds of wacky stuff (OpenMP code to make the logic multithreaded, or possibly a CUDA implementation, or something similar based on OpenCL when that becomes available), and aside from the interactions with the rest of the world, as detailed earlier in this thread, Box2D doesn't really play a big part in that. I'm still 100% happy with what Box2D does, but I don't advocate adding fluid physics to its "bag of tricks". It's just too big a change, and would impact negatively on the engine.
- Fluid physics is hard. Whilst I still think it's going to be a big deal in games over the next few years, right now it comes with serious trade-offs with regards to development time, processing efficiency, and stability. It's not something for the faint-hearted, and whilst I'm one of the mentalists that's making it a central aspect of my game, I'd advise others against it until the techniques become more well understood in a realtime environment, and some genius puts a flexible and stable engine together to make it happen.
All that said, what exactly is the problem you're having mattjakob? Are the particles not falling down from the box they're spawned in? That implies a problem with the gravity setting in your b2world to me. In the test code, the fluid physics doesn't kick in until the particles have fallen a bit - they start outside the grid in which the processing happens, and fall into it before starting to behave like fluids. If they're not falling at all, it seems like gravity is the issue.
Hello.
I agree with you for what concerns the fluid simulation in box2d... still Im giving it a try 🙂
The problem as you can see in the screenshot is that the particles remain constrained in a tiny box in the middle of the screen (white rectangle)... without falling and spreading or else.
I agree with you for what concerns the fluid simulation in box2d... still Im giving it a try 🙂
The problem as you can see in the screenshot is that the particles remain constrained in a tiny box in the middle of the screen (white rectangle)... without falling and spreading or else.
I'm not sure what I can tell you if you're having problems with the code. There should be no problem in taking the code I posted at the top of page 8 of this thread and copying it into the version 2.0.1 testbed (I can make no such claims about more recent versions - this thread: http://www.box2d.org/forum/viewtopic.php?f=2&t=3201 seems to be sort of thing which might require a bit of fiddling with, if you're using it).
So, check:
1 - What's the gravity of the b2world set to? Gravity should be defaulted to something sensible by the testbed, but if you've got a world with zero-gravity then you can't expect the particles to fall into the area in which the fluid physics is calculated.
2 - Can you still interact with the test properly? Can you click and drag particles around, or the box? If not, you could have some problem with the test itself. Try setting some breakpoints in FluidTest::Step and making sure that that's called properly, with appropriate values of dt.
The fluid physics doesn't kick in until the fluids fall a bit, into the area described by the hashGrid, so the particles should start off by using Box2D to fall into that area under their own steam (well, under the effects of gravity 😉 ). Your problem doesn't sound like its with the fluid physics, but something to do with how you've set up Box2D, or something to do with how the test fits into the testbed.
So, check:
1 - What's the gravity of the b2world set to? Gravity should be defaulted to something sensible by the testbed, but if you've got a world with zero-gravity then you can't expect the particles to fall into the area in which the fluid physics is calculated.
2 - Can you still interact with the test properly? Can you click and drag particles around, or the box? If not, you could have some problem with the test itself. Try setting some breakpoints in FluidTest::Step and making sure that that's called properly, with appropriate values of dt.
The fluid physics doesn't kick in until the fluids fall a bit, into the area described by the hashGrid, so the particles should start off by using Box2D to fall into that area under their own steam (well, under the effects of gravity 😉 ). Your problem doesn't sound like its with the fluid physics, but something to do with how you've set up Box2D, or something to do with how the test fits into the testbed.
Original thread: https://box2d.org/forum/viewtopic.php?t=574