Author Topic: Water Surface Simulation  (Read 8394 times)

0 Members and 1 Guest are viewing this topic.

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Water Surface Simulation
« 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!



« Last Edit: January 29, 2012, 01:43:28 pm by Builderboy »

Offline Freyaday

  • The One And Only Serial Time Killing Catboy-Capoeirista-Ballerino
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1970
  • Rating: +128/-15
  • I put on my robe and pixel hat...
    • View Profile
Re: Water Surface Simulation
« Reply #1 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.
In other news, Frey continues kicking unprecedented levels of ass.
Proud member of LF#N--Lolis For #9678B6 Names


I'm a performer at heart; I stole it last week.
My Artwork!

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Water Surface Simulation
« Reply #2 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 ^^

Offline LincolnB

  • Check It Out Now
  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1115
  • Rating: +125/-4
  • By Hackers For Hackers
    • View Profile
Re: Water Surface Simulation
« Reply #3 on: September 21, 2011, 09:40:20 am »
This looks really awesome. Are you going to include it in the next release of Zedd?
Completed Projects:
   >> Spacky Emprise   >> Spacky 2 - Beta   >> Fantastic Sam
   >> An Exercise In Futility   >> GeoCore

My Current Projects:

Projects in Development:
In Medias Res - Contest Entry

Talk to me if you need help with Axe coding.


Spoiler For Bragging Rights:
Not much yet, hopefully this section will grow soon with time (and more contests)



Offline flyingfisch

  • I'm 1337 now!
  • Members
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1620
  • Rating: +94/-17
  • Testing, testing, 1...2...3...4...5...6...7...8..9
    • View Profile
    • Top Page Website Design
Re: Water Surface Simulation
« Reply #4 on: September 21, 2011, 10:42:46 am »
This is pretty awesome, man!



Quote from: my dad
"welcome to the world of computers, where everything seems to be based on random number generators"



The Game V. 2.0

Offline p2

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 849
  • Rating: +51/-11
  • I'm back :)
    • View Profile
Re: Water Surface Simulation
« Reply #5 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!!
*insert supercool signature*

Offline Freyaday

  • The One And Only Serial Time Killing Catboy-Capoeirista-Ballerino
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1970
  • Rating: +128/-15
  • I put on my robe and pixel hat...
    • View Profile
Re: Water Surface Simulation
« Reply #6 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!
« Last Edit: September 21, 2011, 10:59:40 am by Freyaday »
In other news, Frey continues kicking unprecedented levels of ass.
Proud member of LF#N--Lolis For #9678B6 Names


I'm a performer at heart; I stole it last week.
My Artwork!

Offline p2

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 849
  • Rating: +51/-11
  • I'm back :)
    • View Profile
Re: Water Surface Simulation
« Reply #7 on: September 21, 2011, 11:01:39 am »
 ;D

Make It!!
« Last Edit: September 21, 2011, 12:46:34 pm by Qwerty.55 »
*insert supercool signature*

Offline flyingfisch

  • I'm 1337 now!
  • Members
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1620
  • Rating: +94/-17
  • Testing, testing, 1...2...3...4...5...6...7...8..9
    • View Profile
    • Top Page Website Design
Re: Water Surface Simulation
« Reply #8 on: September 21, 2011, 02:09:35 pm »
Gimme the source when yer done so I can do it for Casio!



Quote from: my dad
"welcome to the world of computers, where everything seems to be based on random number generators"



The Game V. 2.0

Offline ztrumpet

  • The Rarely Active One
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5712
  • Rating: +364/-4
  • If you see this, send me a PM. Just for fun.
    • View Profile
Re: Water Surface Simulation
« Reply #9 on: September 21, 2011, 03:33:34 pm »
This is incredible!  I've never seen anything like it.  Way to go Builderboy! :D

Offline Darl181

  • «Yo buddy, you still alive?»
  • CoT Emeritus
  • LV12 Extreme Poster (Next: 5000)
  • *
  • Posts: 3408
  • Rating: +305/-13
  • VGhlIEdhbWU=
    • View Profile
    • darl181.webuda.com
Re: Water Surface Simulation
« Reply #10 on: September 21, 2011, 03:37:28 pm »
I've seen something like it: Real water :D
* Darl181 runs

O.O this is epic..
* Darl181 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?
« Last Edit: September 21, 2011, 03:38:51 pm by Darl181 »
Vy'o'us pleorsdti thl'e gjaemue

Offline yunhua98

  • You won't this read sentence right.
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2718
  • Rating: +214/-12
  • Go take a dive in the River Lethe.
    • View Profile
Re: Water Surface Simulation
« Reply #11 on: September 21, 2011, 04:17:49 pm »
this would be epic for a game like Slime Water Polo.  :D

Spoiler For =====My Projects=====:
Minor setback due to code messing up.  On hold for Contest.
<hr>
On hold for Contest.


Spoiler For ===Staff Memberships===:






Have you seen any good news-worthy programs/events?  If so, PM me with an article to be included in the next issue of CGPN!
The Game is only a demo, the code that allows one to win hasn't been done.
To paraphrase Oedipus, Hamlet, Lear, and all those guys, "I wish I had known this some time ago."
Signature Last Updated: 12/26/11
<hr>

Offline ztrumpet

  • The Rarely Active One
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5712
  • Rating: +364/-4
  • If you see this, send me a PM. Just for fun.
    • View Profile
Re: Water Surface Simulation
« Reply #12 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.

Offline sqrt(Time)

  • LV2 Member (Next: 40)
  • **
  • Posts: 37
  • Rating: +4/-0
    • View Profile
Re: Water Surface Simulation
« Reply #13 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.)

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Water Surface Simulation
« Reply #14 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 ^^