Real Time Wave Field by sixblades29th Jul 2004 21:21
|
---|
Summary A moving wave field that could be textured and used for water. Description This program has always fascinated me so I decided to put it on the web. Tell me what you think! (email: s_i_x_b_l_a_d_e_s@yahoo.com) Code ` This code was downloaded from The Game Creators ` It is reproduced here with full permission ` http://www.thegamecreators.com Remstart ******************** * Matrix Wave * A demonstration by * Sixblades Designs ******************** Remend `Set up the variables. Here you can change how the waves look on the matrix. wid=1000 lng=1000 xseg=40 zseg=40 amp=100 freq=7 time=0 `Color the backdrop black. Color backdrop RGB(0,0,0) `Make the matrix we will use as a water/wavy type surface Make matrix 1,wid,lng,xseg,zseg `Initiate the loop. Sync on Do GoSub ControlTheWaves `Move the camera according to the arrowkeys Control camera using arrowkeys 0,1,1 `Position camera 0,camera position x(0),get ground height(1,camera position x(0),camera position z(0)),camera position z(0) ` make the command above a non comment and it will stick the camera to the surface. Sync Loop ControlTheWaves: `This subroutine changes every point in the matrix, then animates it based on a time variable `go thru time Inc time,1 `make sure it stays within 360 time=wrapvalue(time) `Here is the heart of the code, this is where it happens. For x=0 to xseg For z=0 to zseg `Here we take the x and z coordinates and plug them into the wave equation. If we add them together, we have a single 3 dimensional wave. `You can create nonsymmetrical waves by changing the amplitude/frequency/time of the x or z. y#=Cos((freq*x)+(time))*amp+Cos((freq*z)+(time))*amp `Set the point in the matrix equal to the equation. Set matrix height 1,x,z,y# Next z Next x `THIS PART IS CRUCIAL! First time I tried this I got extremely frustrated `until I looked up the command. You must update the matrix or nothing visible will happen. Update matrix 1 Return |