3D Water Bodies
This is a simple XNA project that simulates an ocean…
The idea first came to me when I was practicing on creating terrain using heightmaps! I was playing with the vertices of the terrain, giving them some motion on the Y Axis then I said to my self: “Wow! This looks like the sea wavy water! :D”
The principle is simple! examine this very simple example:
I have 9 vertices forming 4 quads
I also have an array of 9 integers to determine the direction of each vertex : up/down
when first initializing the WaterBody, a random value between -n,n is assigned to the Y component of each vertex. so each vertex should start with a random Y component… The direction of each vertex is also generated randomly!
Now all I have to do – every frame – is to move each vertex in its direction, if Position.Y<-n or Position.Y>n then fix Position.Y and change the direction of the vertex ( if up make it down, if down make it up! pretty simple huh? π )
If you apply the above to a larger number of vertices ( I used 70×70 in my project ) you’ll have a nice wavy water!
Adding some lighting and texture will make things better ;).
Adding sound effects will make things even better! π π
Here’s the final result!
You can control several things in the application like enabling/disabling lighting and texture, changing camera position…
You can change the max wave height,wind speed and the application will automatically randomize theΒ waves!
WaterBodies Executable ( 144 KB ) – XNA Redistributable 3.1 Required ONLY if you don’t have XNA Game Studio 3.1 installed
WaterBodies Source Code ( 183 KB ) – XNA Game Studio 3.1 Required
Revisions:
rev. 1 : Position,Rotation,Scale properties are now available! the WaterBody class is now more flexible than before!
rev. 2 : Updated camera class, now it’s a free look camera. Code now is more tidy..
hello, good contributions, the, but I have a problem with the download links
That’s odd! π¦ Nothing is working on mediafire.com π¦
it says it’s under maintenance
I checked the files, they are still on the server,
It should be up and running shortly π
BTW : you can check here
http://www.gamedev.net/community/forums/topic.asp?topic_id=581248
The members at gamedev suggested some improvements, but I’m busy right now to update the article!
I defenetly need code for xna to make effect like in game Left4dead boomer explotion. It even would be better without green color.
I haven’t played the game, any screenshots?
I am wondering do you have source code to run on XNA4.0? Thanks!
I updated the code to run under XNA4.0
Here it is:
http://www.mediafire.com/?gtnct01lfy7lvgq
The code runs for XNA Reach Profile, so index buffers use short for indexing.
Just a note, since normals calculation is done on the CPU, creating large water bodies will not run smoothly.
Thank you so much! It runs pretty well and is very helpful.
You’re welcome!