Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

At this point the platform and programming language don't matter I would just like to know if something out there exists for this. Any help is appreciated.

share|improve this question
    
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_code May 30 '11 at 12:43
add comment

3 Answers

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.

share|improve this answer
8  
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) –  ghost May 28 '11 at 8:39
add comment

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.

share|improve this answer
4  
This answer is not suited for real time games in a practical size. –  AttackingHobo May 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. –  ghost May 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. –  Randomman159 May 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. –  AttackingHobo May 30 '11 at 3:54
    
Particles works good enough en.wikipedia.org/wiki/Smoothed-particle_hydrodynamics. Was used in FLT:s latest demo as described in directtovideo.wordpress.com/2011/05/03/numb-res This implementation might be a bit heavy weight, but simpler approximations as in the Pixel Junk Shooter GDC talk should work fine. –  void May 30 '11 at 5:52
show 2 more comments

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.

share|improve this answer
    
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_code May 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. –  ghost May 31 '11 at 14:31
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.