This question appears to be off-topic. The users who voted to close gave this specific reason:

"Questions about "how to get started," "what to learn next," or "which technology to use" are discussion-oriented questions which involve answers that are either based on opinion, or which are all equally valid. Those kinds of questions are outside the scope of this site. Visit our help center for more information." – Krom Stern, Josh Petrie

I've implemented a custom 2d fluid engine. I was able to get a working example up using this paper on viscoelastic fluids and the code from Flui°D°emo as a template. However, the fluids are not as stable as I would like and code could use lots of optimization love (multicore processing, cache friendliness, etc). What I want is a library that has done all that already, so that I only have to integrate it with Box2d and my game.
–
deft_codeMay 30 '11 at 12:43

4 Answers
4

Look into what Q-Games used for Pixeljunk Shooter. It is a 2d game with pretty involved fluid physics. I'm not sure if they used a homegrown or middleware physics engine, but the information is probably out there somewhere.

They have used a homegrown engine, but have included techniques that can be applied using any physics engine en some custom code. The actually gave a very informative talk about their fluid dynamics at GDC (slides here: gdcvault.com/play/1012447/Go-With-the-Flow-Fluid)
–
ghostMay 28 '11 at 8:39

The only library I could come up with that specifically deals with fluids is Fluidic. It is pretty alpha and only has one release, though. The physics library Bullet supports 'smoothed-particle hydrodynamics', a technique used to model fluids. Although the library is geared towards 3D, you could apply constraints to one axis to make it work in 2D.

My recommendation would be, as I already mentioned in some comments on other answers, to use a standard physics engine like Box2D or Chipmunk and use a number of circles to model the water (with gravity) or gas (without gravity) and combine these together into one water or gas body. You can apply some constraints on the individual bodies to make them 'clump' together so you can simulate viscosity. Have a look at this video to see how the individual bodies (modelled as squares in the video) work together. Note, however, the technique used in this video is not the same as mentioned in this paragraph. You can use the video to get a feel of how the circles interact with each other and try to mimic this with the constraints present in the physics library used.

The interesting part comes when you want combine multiple circles into body of water. The most straightforward solution I can come up with is drawing each circle as a metaball so they appear as part of a larger body. You can find the math and some example code behind these bodies here.

The video you linked to is using much more than just lots of circles. He uses a technique known as SPH. The blaze port of Flui°D°emo uses Box2d to find collisions and apply forces but uses SPH methods calculate forces not Box2d's rigid bodies.
–
deft_codeMay 30 '11 at 12:35

You are absolutely correct in that regard. The video was meant to be illustrative instead of an implementation example. Thank you for mentioning my mistake and I have updated the answer to prevent further misunderstandings.
–
ghostMay 31 '11 at 14:31

Well i havn't looked into this, but i know for a fact that almost any physics engine can emulate the idea. Box2D, etc.

Basically have particles bouncing around, off surfaces and eachother (faster for gasses) but also give them a constant gravity like effect (liquids would all have the same, but some gases you might want to rise slowly).

If you link up the outer particles you will get a polygonal shape representing the mass

OR

if you simply draw a pixel or particle graphic over each particle, you can achieve a cloud effect for the mass instead.

This answer is not suited for real time games in a practical size.
–
AttackingHoboMay 28 '11 at 6:32

3

I am not sure why you'd say that, as fluid dynamics are very often modelled as particles. For examples see the nvidia tech videos on fluid particles on youtube, the program Algodoo (formerly called Phun) or the talk Q-Games gave about their PixelJunk Shooter game (slides at gdcvault.com/play/1012447/Go-With-the-Flow-Fluid). In the latter case, Q-Games shows how they construct a polygon out of a collection of particles. I would think that this verifies that this answer is quite valid for realtime implementations IMHO.
–
ghostMay 28 '11 at 8:45

WOWOW why the downvotes? I'm not raging, just want to know why. It is a realistic technique and is used.
–
Randomman159May 28 '11 at 10:22

"particles bouncing around, off surfaces and eachother (faster for gasses)" that sounds like you are describing fluids on the molecular level, and while a naive approach could work with baked simulation, it wont work well for real time games. Particles are fine as long type of simulation is correct, "bouncing arround" does seem like it would work with macro particles. You also grossly misrepresented how to simulate density.
–
AttackingHoboMay 30 '11 at 3:54