Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / [DBP] Water simulation, including waves, spashes, and water pressure, using cellular automata

Author
Message
lower logic
18
Years of Service
User Offline
Joined: 15th Jun 2006
Location:
Posted: 27th Dec 2006 05:25 Edited at: 27th Dec 2006 19:24
I read about this in a book I got for christmas - game programming gems 3. This snippet models water using celluar automata.
Controls:
spacebar to start and play/pause simulation
left click to clear or draw walls (it will draw/erase based on if you click on a wall or not)
right click and mousemove to add flow to the water.



If it runs slowly on your computer increase the cell_size variable (line 8) until it runs smoothly.

Screen shots:

Water travelling up a pipe into a bucket because of water pressure:


Splash fun:


Flowing water:


The change in colors from blue to green to red represents the water pressure.
Mr Tank
21
Years of Service
User Offline
Joined: 25th Nov 2002
Location: United Kingdom
Posted: 27th Dec 2006 05:42
This looks pretty awesome. I really have to go to bed now, but i'll definitely check it out properly later.


You'll be able to click on this someday.
Kohaku
20
Years of Service
User Offline
Joined: 3rd May 2004
Location: The not very United Kingdom
Posted: 27th Dec 2006 06:16
That's quite incredible!


You are not alone.
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 27th Dec 2006 14:14
HOLY F***!

I know a bit about physics, made my own water simulation with help from Ric, but, oh, oh, this, this is just, incredible...

Chris Franklin_
17
Years of Service
User Offline
Joined: 21st Dec 2006
Location: Home
Posted: 27th Dec 2006 14:18
Quote: "HOLY F***!

I know a bit about physics, made my own water simulation with help from Ric, but, oh, oh, this, this is just, incredible..."

Ditto ^

Awesome man , keep it up

I've got a new account because all my order's go to my new e-mail.
El Goorf
18
Years of Service
User Offline
Joined: 17th Sep 2006
Location: Uni: Manchester, Home: Dunstable
Posted: 27th Dec 2006 14:22
Quote: "HOLY F***! "


Quote: "Ditto ^"


yes... very <censored> good.
lower logic
18
Years of Service
User Offline
Joined: 15th Jun 2006
Location:
Posted: 27th Dec 2006 19:55 Edited at: 27th Dec 2006 20:20
Thanks for all the comments. Cellular automata can also be used to simulate air flow (which can be used to simulate realistic explosions going around corners when in a confined space), heat transfer (conduction, convection, and radiation), and fire.

Just by removing the gravity and changing the code a bit, you have air/air pressure simulation:

Changes between this snippet and the first snippet include:
-Removed gravity
-Removed water specific interaction
-Amplified the air sort of interaction (so waves last longer, but waves can also be tuned down or completely removed if wanted)
-Changed the right mouse click so that now increased the air pressure (waves propagate in all directions until they hit walls).
-Air eventually drains out of the system so the pressure can return to normal after a while.

An explosion going down a hallway:


A wall protecting the area behind it from the explosion, simulating realistic cover:
jasonhtml
20
Years of Service
User Offline
Joined: 20th Mar 2004
Location: OC, California, USA
Posted: 28th Dec 2006 02:06
this is absolutely fantastic! nice work!


forum.thegamecreators.com/?m=forum_view&t=78971&b=8&p=0
forum.thegamecreators.com/?m=forum_view&t=91115&b=32
Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 28th Dec 2006 14:01
It is indeed fantastic.
Too bad it consumes so much fps though ...

It's the programmer's life:
Have a problem, solve the problem, and have a new problem to solve.
TEH_CODERER
21
Years of Service
User Offline
Joined: 12th Nov 2003
Location: Right behind you!
Posted: 28th Dec 2006 16:01
Wow-ee! That is absolutely awesome!

Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 28th Dec 2006 22:04
Lower Logic - Straight as I am, will you marry me?

*Ahem*

You should write a tutorial

Dared1111
18
Years of Service
User Offline
Joined: 25th Oct 2006
Location:
Posted: 29th Dec 2006 11:33 Edited at: 29th Dec 2006 22:06
can you write a tutorial on how to write this sort of thing?

Game progress- 30 percent
lower logic
18
Years of Service
User Offline
Joined: 15th Jun 2006
Location:
Posted: 29th Dec 2006 18:52
Haha, thanks. I'll think about writing a tutorial.
MadrMan
18
Years of Service
User Offline
Joined: 17th Dec 2005
Location: 0x5AB63C
Posted: 7th Jan 2007 14:22
one word: "WOW"


Ankillito
17
Years of Service
User Offline
Joined: 10th Dec 2006
Location: Litigious California
Posted: 10th Jan 2007 06:00
Just browsing around, can't test it yet as DBP is in the mail. It looks awesome, but is there a practical, in terms of gaming use? Either way, it's still impressive and I haven't even run it.

"There will always be evil, for, without evil, the good shall lose their virtue."
lower logic
18
Years of Service
User Offline
Joined: 15th Jun 2006
Location:
Posted: 10th Jan 2007 17:33 Edited at: 10th Jan 2007 17:35
I haven't tried this in an actual game, so I'm not sure how practical it would be, but I can sum up what the book said:

It's only practical when the cells are large. In a FPS game, the cells would be cubes, and would need to be around 0.5 meters long on each edge. To accurately represent the open space, you'd want to use some algorithm that moved the corners of each cell so that they were flush with the floor/walls so water couldn't move through walls or floor. Also, when cells aren't doing anything you'd want to remove them from the loops to optimize the simulation.

In an actual game you'd use the data from the cells to figure out when objects should catch on fire and use your own fire animations from there. You'd calculate the damage from explosions based on the difference in air pressure and use your own models to show the damage.

For water it wouldn't be practical to simulate splashes in 3d games as rendering the shape of the 3d water would take a lot of calculations, so it'd only really be useful for water pressure simulation, which isn't needed in many games.
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 10th Jan 2007 20:32
Well, lets not just think 3D. This simulation is in 2D, and I personally would be much more impressed playing a 2D game with effects like this, rather than playing a 3D game with effects that look fake.

Aaron Miller
18
Years of Service
User Offline
Joined: 25th Feb 2006
Playing: osu!
Posted: 11th Jan 2007 01:27
Very impressive indeed! 5 starts: *****

-db

GameDeveloper, make your own games with a drag-and-drop interface. Basically t3dgm+fpsc editor combined.
http://forum.thegamecreators.com/?m=forum_view&t=86045&b=8&p=2
Sixty Squares
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 13th Jan 2007 03:33
Wow.

Ankillito
17
Years of Service
User Offline
Joined: 10th Dec 2006
Location: Litigious California
Posted: 15th Jan 2007 21:19
Quote: "In an actual game you'd use the data from the cells to figure out when objects should catch on fire and use your own fire animations from there."


OIC. I just ran it now that I have DBP. I believe I agree with the aboved censored remark.

"There will always be evil, for, without evil, the good shall lose their virtue."
fik
20
Years of Service
User Offline
Joined: 28th Sep 2004
Location:
Posted: 25th Jan 2007 13:39
Totaly brilliant pice of work what more can be said.
revenant chaos
Valued Member
17
Years of Service
User Offline
Joined: 21st Mar 2007
Location: Robbinsdale, MN
Posted: 5th Apr 2007 14:58
this is absolutely amazing, this thing is even better then the 3d renderer that only uses 2d commands, and i thought that was incredible. Keep up the outstanding work.

I know what a hassle it would be to write a tutorial (in 9th grade I wrote a tutorial for the Texas instruments TI-83+ basic and distributed it to my class mates, who kept asking me to teach them, but never bothered to learn), but a tutorial in this sort of thing could bring the whole forum up to speed. I cant possibly see a tutorial of this sort going to waste, and it would be much appreciated if you could take some time to make some progressively more complex lessons.

keep rockin' on lower logic
Dared1111
18
Years of Service
User Offline
Joined: 25th Oct 2006
Location:
Posted: 22nd Jun 2007 21:44
revival!!!

gets out pads, others need to see this...

Your signature has been erased by a mod because it was too big
qwe
21
Years of Service
User Offline
Joined: 3rd Sep 2003
Location: place
Posted: 26th Jun 2007 18:35
Conway's Game of Life is a cellular automata program which is easy to code. look into that (wikipedia it) and code your own Game of Life if you want to get started with cellular automata. you might want to pick up a physics textbook if you want to make a water simulation:p

here's a simple but inefficient Game of Life in DBP

RomuluS85
18
Years of Service
User Offline
Joined: 10th Apr 2006
Location:
Posted: 1st Jul 2007 20:51
i'm attempting to port that in to DBGDK...
uuh... what the h*ck does:
diff# =-(cell(x,y+1).mass - cell(x,y).mass)
mean (that minus sign in the beginning to be exact...)

been a while since i last wrote DBPro code...
RomuluS85
18
Years of Service
User Offline
Joined: 10th Apr 2006
Location:
Posted: 1st Jul 2007 23:11
hmm... and in addition, i'm thinking about implementing that to a game... for example, for a grenade shockwave...

and one thing that came to my mind is:
does it really need to update the whole surroundings...
i mean, if you have a grenade it's shock wave has a theoretical maximum distance it can travel (before the wave becomes so small that it has no effect what so ever...)

take a smaller search "matrix" (x,y square) and fill it with the terrain around the grenade, do the Cellural Automata code for that and it should speed up a lot (since the search area is alot smaller).
this in addition could be used to give vector to the leafs / dust fx etc...
Brain111
17
Years of Service
User Offline
Joined: 5th Feb 2007
Location: In my own little world.
Posted: 9th Jul 2007 06:35
That's delicious.

Maybe there would be a fast way to use large cells but somehow render something other than squares to make them look smoothe? I don't necessesarilly mean just render dots, but I don't know what I'm thinking. Just some sort of way to make it look like a blob rather than a brick.

Anarchy Burger - hold the Government!
Turoid
21
Years of Service
User Offline
Joined: 1st Nov 2003
Location: The Netherlands
Posted: 9th Jul 2007 12:47
That is really good! I thought that my fluid simulation was cool NICE WORK!!

I am awesome and always right.
the carcinogen
17
Years of Service
User Offline
Joined: 2nd Aug 2007
Location:
Posted: 2nd Aug 2007 09:21
there is a game called Plasma Pong that was a winner at this year's Slamdance Guerilla Gamemaker Competition. It uses fluid dynamics in almost the same format to create an incredible game of Pong.

you can check it out at http://www.plasmapong.com.

Login to post a reply

Server time is: 2024-11-22 18:22:09
Your offset time is: 2024-11-22 18:22:09