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 / 2D Water Demo

Author
Message
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 14th Sep 2006 01:49
I wanted to make my water better in my ship game, and I came across Ric's awesome water code, so to learn it I decided to muck around with it. Here's a 2D Demo I made, use the mouse to increase and decrease the height. It takes a while fpr the waves to get from one end to the other, worth the wait though, that's when the fun really starts


P.S. Thanks Ric!

Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 14th Sep 2006 11:29
Nice one! You probably figured out that the damping value is critical - a touch to little and the whole thing explodes - too heavy and it's more like mud. You can spend ages testing different values until you get it right. This bit of code I came up with a while ago attempted to solve the problem through self regulatory damping - ie. the damping automatically finds the optimum value, and continually re-adjusts itself to keep the waves from dying or exploding. You have to watch it for a minute or so to see what it's doing:



p.s. sorry for hijacking your thread again!
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 15th Sep 2006 00:40
Yeah I did have some trouble with the damping, got quite annoying. I like this code snippet, I think I'll use the idea for it to solve my problem, besides, it gives the waves a little variety too.

p.s. No Problem lol

Crazy Ninja
19
Years of Service
User Offline
Joined: 27th Aug 2005
Location: Awesometon
Posted: 16th Sep 2006 06:00
hehe that was kind of fun. you need some boats on the water for you to sink.

____ ____ ____ ___ _ _ __ _ _ __ _ _ ____
|___ |--< |--| /__ Y | \| | | \| ___| |--|
Sixty Squares
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 17th Sep 2006 01:09
I like how it looks when the waves bounce back!

Ummm...
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 18th Oct 2006 20:23
Cool

I couldn't resist making it a little faster, my PC is kinda slow.



''Stick that in your text and scroll it!.''
Xenocythe
19
Years of Service
User Offline
Joined: 26th May 2005
Location: You Essay.
Posted: 21st Oct 2006 21:30 Edited at: 21st Oct 2006 21:30
Nice zoto!

EDIT:Ric, mind if I use that code for my game? It's beautiful.


Mr Tank
21
Years of Service
User Offline
Joined: 25th Nov 2002
Location: United Kingdom
Posted: 22nd Oct 2006 05:59
That's really cool. I adapted it to make a 2d version with a matrix. You can move the middle up and down with the mouse, and also hold space to make it rain.




You'll be able to click on this someday.
Mr X
19
Years of Service
User Offline
Joined: 25th Sep 2005
Location: Universe, milkyway, sol-system, Earth...
Posted: 22nd Oct 2006 13:34
WOW!!! Nice one, Mr Tank.
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 22nd Oct 2006 15:45
Really nice Mr Tank. I also really like the matrix normals you've made. You don't mind if I 'borrow' them? I've needed a good method for matrix normals that work in real time.

Mr Tank
21
Years of Service
User Offline
Joined: 25th Nov 2002
Location: United Kingdom
Posted: 22nd Oct 2006 16:11
Thanks. Feel free to use it- it's not like i have a patent on mathematics. You'll probably need to change the sign of the x and z normal components, and i think i got x and z the wrong way around.
Also, the way i had it is really more like the normals for the middle of matrix squares, so a better version would be...

normal(x,y,0)=height(x,wrap64(y,0))-height(x,wrap64(y,1))
normal(x,y,1)=height(wrap64(x,0),y)-height(wrap64(x,1),y)

You should check that light lights up the correct parts- if i've got it wrong the sea will appear to be lit from a different direction than other stuff.

Having made this i saw your other thread (seascape), and see that yours and ric's original water code is 2d too. I mean to check it out properly when i have a spare moment and have a think about it.
I think you don't need to have the fixed points to cause wave excitation- just play around with adding random water depth or surface velocity, like i did with the "rain" thing.


You'll be able to click on this someday.
bosskeith
18
Years of Service
User Offline
Joined: 5th Dec 2005
Location:
Posted: 31st Oct 2006 18:13
Mr tank the other thing that is realy cool about this is if you pull the node to it's highest or lowest points with some slight jitter it looks like liquid that is either draining or filling a box.

Login to post a reply

Server time is: 2024-11-22 22:59:57
Your offset time is: 2024-11-22 22:59:57