Omnimaga

Calculator Community => Other Calc-Related Projects and Ideas => TI Z80 => Topic started by: Builderboy on September 21, 2011, 12:15:09 am

Title: Water Surface Simulation
Post by: Builderboy on September 21, 2011, 12:15:09 am
    So I recently upgraded the buoyancy library I wrote and made it a fully featured water surface simulator!  It can still be a bit wonky at times, but it sure gets the job done pretty well ^^ Of course it's Zedd compatible and handles object mass very nicely, as well as reacting to objects moving around in it.  The water surface is composed of 24 individual points that have a Y location and a Y velocity.  Every frame the following rules are applied:

Code: [Select]
MidpointRight = (ThisHeight + RightHeight)/2
Vel = Vel + (MidPointRight - ThisHeight)
MidpointLeft = (ThisHeight + LeftHight)/2
Vel = Vel + (MidPointLeft - ThisHeight)

Which can then be simplified into:

Code: [Select]
Vel = (RightHeight + LeftHeight)/2 - ThisHeight + Vel
Just apply this equation to each point, then apply the velocity/8 to each point, add some dampening so things don't get out of control, and you're golden!

But enough talk, lets look at the pretty pixels!



Title: Re: Water Surface Simulation
Post by: Freyaday on September 21, 2011, 12:19:04 am
Wow, that is amazing Builder. That is something I've been wanting to do for a very long time, but never knew how.
Wow.
Title: Re: Water Surface Simulation
Post by: Builderboy on September 21, 2011, 12:58:34 am
Thanks :) Also I updated the first post with some equation information for anybody who wanted to know ^^
Title: Re: Water Surface Simulation
Post by: LincolnB on September 21, 2011, 09:40:20 am
This looks really awesome. Are you going to include it in the next release of Zedd?
Title: Re: Water Surface Simulation
Post by: flyingfisch on September 21, 2011, 10:42:46 am
This is pretty awesome, man!
Title: Re: Water Surface Simulation
Post by: p2 on September 21, 2011, 10:45:20 am
O_o
You should make that in greyscale!!!


Better: Make a game of it!!

And then, with arrow-keys, it should be possible to controle a block at the left side. And you'll have to make enough waves to blow the enamys (ships, coming from the left side) away!!
Title: Re: Water Surface Simulation
Post by: Freyaday on September 21, 2011, 10:59:04 am
O_o
You should make that in greyscale!!!


Better: Make a game of it!!

And then, with arrow-keys, it should be possible to controle a block at the left side. And you'll have to make enough waves to blow the enamys (ships, coming from the left side) away!!
Omigod, that really would be an epic game! You have capsize them with waves!
MAKE THAT GAME! MAKE IT NOW!
Title: Re: Water Surface Simulation
Post by: p2 on September 21, 2011, 11:01:39 am
 ;D

Make It!!
Title: Re: Water Surface Simulation
Post by: flyingfisch on September 21, 2011, 02:09:35 pm
Gimme the source when yer done so I can do it for Casio!
Title: Re: Water Surface Simulation
Post by: ztrumpet on September 21, 2011, 03:33:34 pm
This is incredible!  I've never seen anything like it.  Way to go Builderboy! :D
Title: Re: Water Surface Simulation
Post by: Darl181 on September 21, 2011, 03:37:28 pm
I've seen something like it: Real water :D/me runs

O.O this is epic../me wonders if this could be used for a subhunt clone or something
Does this take into account forces from below/above the surface?  
ie if this were put in Demolition and a barrel exploded not far above it or below it would it ripple?
Title: Re: Water Surface Simulation
Post by: yunhua98 on September 21, 2011, 04:17:49 pm
this would be epic for a game like Slime Water Polo.  :D
Title: Re: Water Surface Simulation
Post by: ztrumpet on September 21, 2011, 06:06:00 pm
Why does the amount of water fluctuate?  Shouldn't it be impossible to create or destroy water?  Sometimes I can almost fill/empty the screen if I get all three objects in about the same spot horizontally and repeatedly go up, down, up, down.
Title: Re: Water Surface Simulation
Post by: sqrt(Time) on September 21, 2011, 06:51:40 pm
The amount fluctuates because it's just a very rough approximation - this is based off the "wave equation", a simplification which ignores under-the-surface swirling, and only really holds true if the waves stay nearly linear (i.e. the slope at any point doesn't get much bigger than, say, a half). Also, the way he applies the suction/friction with the cubes allows them to sort of "draw water up" around them without necessarily depleting the water elsewhere. (This would be currents under the surface, which as I said, are ignored by the wave equation.)
Title: Re: Water Surface Simulation
Post by: Builderboy on September 21, 2011, 07:57:24 pm
Yeah, at its basics you could look at the surface as a series of interconnected springs, which really doesn't simulate at all how water is supposed to work, but looks about right most of the time and is very fast to calculate.  I have been upgrading this a lot and the new way I work the springs, dampening, object dampening, and force handling makes it look a lot better ^^
Title: Re: Water Surface Simulation
Post by: ztrumpet on September 21, 2011, 08:08:33 pm
Oh, okay, cool.  It still looks really good. :D

Up next, multi-segmented lines/chains. ;)
Title: Re: Water Surface Simulation
Post by: Yeong on September 21, 2011, 08:27:31 pm
or spagettification near black hole?
*Yeong really wants to see that on calc :D
Title: Re: Water Surface Simulation
Post by: p2 on September 22, 2011, 09:30:58 am
Quote from: ztrumpet
Why does the amount of water fluctuate?  Shouldn't it be impossible to create or destroy water?  Sometimes I can almost fill/empty the screen if I get all three objects in about the same spot horizontally and repeatedly go up, down, up, down.
Maybe it's just too realistic!!
If you move an object very fast and it will touch another object (water) while moving, it'll become warm!
If it'll be very fast, it'll become hot.
And so the water was too hot, and it's in the air (invisible)  ;)



Please make that game!!!
Title: Re: Water Surface Simulation
Post by: Freyaday on September 23, 2011, 11:00:42 am
Quote from: ztrumpet
Why does the amount of water fluctuate?  Shouldn't it be impossible to create or destroy water?  Sometimes I can almost fill/empty the screen if I get all three objects in about the same spot horizontally and repeatedly go up, down, up, down.
Maybe it's just too realistic!!
If you move an object very fast and it will touch another object (water) while moving, it'll become warm!
If it'll be very fast, it'll become hot.
And so the water was too hot, and it's in the air (invisible)  ;)



Please make that game!!!
Lol p2.
Title: Re: Water Surface Simulation
Post by: aeTIos on September 26, 2011, 07:27:25 am
:o looks epic
Title: Re: Water Surface Simulation
Post by: epic7 on November 22, 2011, 07:10:21 am
Boating game!