Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (489)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (553)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Very simple liquids simulation  (Read 6011 times)
0 Members and 1 Guest are viewing this topic.
Offline Archibald

Junior Member


Projects: 1



« Posted 2012-03-03 00:06:52 »

A simple game, 100x100 "map", each cell holds the wall status (yes/no) and liquid volume (volume of liquid present, 0=air). From the top of the screen falls water and go to bottom as ordered by gravity and obstacles.

How to simulate this liquid (not necessarily water, I'm not sure what it will be, right now it behaves like a mix of water, gell and sand Cheesy)?

Right now I have an algorithm like that:
- if the neighbour is WALL, do nothing in that direction
- move 3% of liquid volume down (if no obstacle), can't move down if target cell's volume is double volume of current cell
- move 2% of liquid volume right (if no obstacle and the volume of liquid in the target cell is lower)
- move 2% of liquid volume left (if no obstacle and the volume of liquid in the target cell is lower)
- move 1% of liquid volume up (if no obstacle and the volume of liquid in the target cell is lower), also only if current cell liquid volume is >1000 (so the air gives some pressure and the water does not pop up into the very top unless there is an extreme liquid pressure/volume)

I'm also wondering about more elements (like gas or oil), which makes it tricky if we make an assumption that only one element can occupy a single cell (best for the display and clarity to the player). But that's for later.

Offline RylandAlmanza

Junior Member


Medals: 3



« Reply #1 - Posted 2012-03-03 00:21:46 »

This is in AS3 (Flashpunk), but I'm sure you could port it to java:
Flashpunk water demo (Click to add water): http://dl.dropbox.com/u/3527200/watery/index.html
Flashpunk water source: http://pastebin.com/zFJLYjpK

I actually might try porting it if I have the time a little later

EDIT: Actually, I think the flash version was also ported from this original Processing version: http://w-shadow.com/blog/2009/09/01/simple-fluid-simulation/
Offline theagentd
« Reply #2 - Posted 2012-03-03 08:09:20 »

A simple game, 100x100 "map", each cell holds the wall status (yes/no) and liquid volume (volume of liquid present, 0=air). From the top of the screen falls water and go to bottom as ordered by gravity and obstacles.

How to simulate this liquid (not necessarily water, I'm not sure what it will be, right now it behaves like a mix of water, gell and sand Cheesy)?

Right now I have an algorithm like that:
- if the neighbour is WALL, do nothing in that direction
- move 3% of liquid volume down (if no obstacle), can't move down if target cell's volume is double volume of current cell
- move 2% of liquid volume right (if no obstacle and the volume of liquid in the target cell is lower)
- move 2% of liquid volume left (if no obstacle and the volume of liquid in the target cell is lower)
- move 1% of liquid volume up (if no obstacle and the volume of liquid in the target cell is lower), also only if current cell liquid volume is >1000 (so the air gives some pressure and the water does not pop up into the very top unless there is an extreme liquid pressure/volume)

I'm also wondering about more elements (like gas or oil), which makes it tricky if we make an assumption that only one element can occupy a single cell (best for the display and clarity to the player). But that's for later.


http://knucklecracker.com/creeperworld2/cw2.php?

What's stopping you from just adding more than one liquid variable in each cell? The interactions shouldn't be that difficult.

Myomyomyo.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Archibald

Junior Member


Projects: 1



« Reply #3 - Posted 2012-03-04 01:43:38 »

I will post some link too so I'm not worse Smiley
http://www.kickstarter.com/projects/445452543/in-profundis-random-cave-exploration-sim-game?ref=category
(BTW, have you noticed how few "liquid" games are there?)

This is in AS3 (Flashpunk), but I'm sure you could port it to java:
Flashpunk water demo (Click to add water): http://dl.dropbox.com/u/3527200/watery/index.html
You have similar problem to mine of the water behaving like sand (triangle) if you put enough volume. Althrough, it look very well under mediocre-low volumes.

Quote
What's stopping you from just adding more than one liquid variable in each cell? The interactions shouldn't be that difficult.
I'm worried about how to present it to the player (display). Mixing colours is the only solution I could think of and I'm not sure it is so great one...
Plus, if we make things like oil on top of water then incoming new water from the top should not mix with oil but push it saidways or something.
Offline Archibald

Junior Member


Projects: 1



« Reply #4 - Posted 2012-03-20 13:35:57 »

I added several liquids/gases per cell, it looks OK.

Now, how do I make oil? On one hand it is a liquid so it should go down (the bottom parts with higher pressure), on the other it should float on top of water.
I was thinking that it should occupy the same cell as water, but if there is another cell of water above it should try to go up until it is on top. It should also rather fast move sideways (spread on top of the water table). This all would work well if there was no pressure, but with the current pressure based physics there might be required to have more than one row of oil cells on top of water (so not all oil can occupy the very top of water table). Not sure how to make an algorithm for this.
Offline theagentd
« Reply #5 - Posted 2012-03-20 14:45:22 »

Just do it as it is in reality. Calculate a pressure/density value based on the fluids/gases occupying the current and neighboring cells, move fluids depending on the pressure and fluid characteristics.

Myomyomyo.
Offline Archibald

Junior Member


Projects: 1



« Reply #6 - Posted 2012-03-20 21:20:44 »

Just do it as it is in reality. Calculate a pressure/density value based on the fluids/gases occupying the current and neighboring cells, move fluids depending on the pressure and fluid characteristics.
I doubt I have a processing power that would allow it (for gases I need 30-50 cycles per second minimum to make it look cool, liquids are less restrictive maybe 3-5 per second would be enough) and even if I had it I would probably do better for gameplay purpose to enlarge the map (20,000 cells make an absolute minimum map) than introduce perfect physics.

But well, maybe this would give some ideas, so, how the real one liquids behave exactly?
Offline theagentd
« Reply #7 - Posted 2012-03-21 08:18:29 »

I don't know the exact math, but you should know that oil floats up to the surface of water because it has a lower density. Gasses also behave like fluids with very low densities. Again I don't know exactly how it works, but I don't see how adding density calculations to your current system is a very big step performance wise.

Realistic 3D gasses/liquids require much more advanced simulations to be physically accurate, but they still are possible to do in realtime. For example it was done for Stalker: Clear Sky: http://www.youtube.com/watch?v=nfW_b3c00kM

I believe your problem is that you're using too small cells. You should be able to get good results without 20 000 cells and some clever rendering to reduce the blockiness. Seriously, if you want performance, just port it to OpenCL or even an OpenGL shader.

Myomyomyo.
Offline Archibald

Junior Member


Projects: 1



« Reply #8 - Posted 2012-03-21 19:26:45 »

What's the difference between pressure and density? Right now I have volume (pressure) of each liquid/gas per cell (except plain air).

Renderer is not a problem at all, only part of the map (10000 cells) is displayed. I meant the algorithm that run all the cells regardless of visibility.
As for "blockiness" it's the opposite, I want that effect Smiley It is not to be 3D realistic thing but kind or pixelated/retro/voxel thing. Also, I want the cells to affect the gameplay (like redirecting the fluids via some pipes, getting burn if exposed to steam), not as merely visual effects.

Offline theagentd
« Reply #9 - Posted 2012-03-21 20:50:17 »

Density = a property of a fluid/gas
Pressure = something you calculate based on the fluids/gases occupying a cell

Myomyomyo.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 783
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #10 - Posted 2012-03-21 20:50:20 »

What's the difference between pressure and density?
Pressure depends on density and temperature of gases.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 783
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #11 - Posted 2012-03-21 20:52:16 »

Density = a property of a fluid/gas
There, FTFY.

You can't compress fluids (unless you attempt to recreate an environment similar to a neutron star).

You can compress gases, influencing their density and temperature (temporarily).

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline ra4king

JGO Kernel


Medals: 345
Projects: 3
Exp: 5 years


I'm the King!


« Reply #12 - Posted 2012-03-23 21:46:35 »

(Pressure * Temperature)/Volume

Density = Mass / Volume

Offline sproingie

JGO Kernel


Medals: 202



« Reply #13 - Posted 2012-03-23 22:04:38 »

You don't need the conditions of a neutron star for compressing a liquid: it's about 1000 bars at the botton of the Marianas trench, which will compress water a whopping 5% (or not quite, since it's salt water).

For anything remotely practical though, you can treat liquid as incompressible.  And for a game where you're talking about propagating it into tiles, I say forget fluid dynamics entirely and fake it til it looks good.

Offline Archibald

Junior Member


Projects: 1



« Reply #14 - Posted 2012-03-25 09:44:06 »

Water increases pressure by 1 atmosphere every 10 meters (that's why spaceships have muche more flagile hulls than submarines since the peressure difference in space is 1 atmosphere while there is 10 atmospheres difference at the 100m depth).

Also, an interesting observation, the pressure of air almost no change with depth (if you enter 100m building you don't start suffocating also if you fall into a deep hole you don't feel being crushed by all the additional air above you), completely unlike water (100m depth is around the max you can enter without tricky equipment).

For anything remotely practical though, you can treat liquid as incompressible.  And for a game where you're talking about propagating it into tiles, I say forget fluid dynamics entirely and fake it til it looks good.
http://www.kongregate.com/games/whiteboardwar/creeper-world-2-academy
Pressure of liquids adds soooo many fancy stuff (vulcanos, fountains) that it is a completely different quality. Without pressure liquids could be merely aestetic things, not gameplay things.
Offline sproingie

JGO Kernel


Medals: 202



« Reply #15 - Posted 2012-03-25 18:00:41 »

I'm no physics expert, but I'm pretty sure you can model pressure without requiring compressibility.  In fact it should be easier, since then it's just a matter of propagating force through the medium without "absorbing" any of it.

Offline theagentd
« Reply #16 - Posted 2012-03-25 22:12:56 »

For anything remotely practical though, you can treat liquid as incompressible.  And for a game where you're talking about propagating it into tiles, I say forget fluid dynamics entirely and fake it til it looks good.
http://www.kongregate.com/games/whiteboardwar/creeper-world-2-academy
Pressure of liquids adds soooo many fancy stuff (vulcanos, fountains) that it is a completely different quality. Without pressure liquids could be merely aestetic things, not gameplay things.
I linked that in the 3rd post of this thread...  Roll Eyes

Myomyomyo.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

TehJavaDev (18 views)
2014-08-28 18:26:30

CopyableCougar4 (26 views)
2014-08-22 19:31:30

atombrot (39 views)
2014-08-19 09:29:53

Tekkerue (36 views)
2014-08-16 06:45:27

Tekkerue (33 views)
2014-08-16 06:22:17

Tekkerue (22 views)
2014-08-16 06:20:21

Tekkerue (33 views)
2014-08-16 06:12:11

Rayexar (70 views)
2014-08-11 02:49:23

BurntPizza (47 views)
2014-08-09 21:09:32

BurntPizza (37 views)
2014-08-08 02:01:56
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!