looking for a water effect

Blitz3D Forums/Blitz3D Programming/looking for a water effect

This one is a little more interesting.

use WASD to 'fly'

[SPACEBAR] toggles wireframe

Graphics3D 1024,768
Global campiv = CreatePivot()			; camera pivot entity
Global camera = CreateCamera(campiv)	; camera (campiv is the parent)
Global light = CreateLight(2)
MoveEntity light,-40,20,-40

PositionEntity campiv,0,30,0
RotateEntity camera,15,0,0
CameraClsColor camera,230,230,255

cube = CreateCube()
EntityColor cube,20,20,20
ScaleEntity cube,15,25,15

Global midw = GraphicsWidth()/2  	; 	 middle of
Global midh = GraphicsHeight()/2 	;  the screen
	HidePointer 						; hide the mouse pointer
	WireFrame False						; don't do wireframe


Global WATER_GRID_SIZE = 32
Global sizer = 3
Global WATER_HEIGHT# = 16
Dim WaterY(WATER_GRID_SIZE+1,WATER_GRID_SIZE+1)
Global wz,wx
Global hite#
Global waterlevel#
Global waterangle#
Global water
Global watert
Global curdetail
	

Const ENTS = 50							; TOTAL NUMBER OF TOKAMAKPHYSICS Rigid Bodies
Const ANIMS = 10						; TOTAL NUMBER OF TOKAMAKPHYSICS Animated bodies

Const FPS=50							
Const w=17, s=31, a=30, d=32, space=57	; movement keys
shot_delay = 120						; delay between shots
Global pickmarker = CreateSphere(4)		; visual for campick
EntityAlpha pickmarker,.75				; slightly transparent
Global pictentity,pnx#,pny#,pnz#,pcx#,pcy#,pcz#	; pick stuff (pick normals and pick coordinates)
Global latspeed#,speed#,MX#,MY#			; camera speed



		For q = 0 To WATER_GRID_SIZE
							For j = 0 To WATER_GRID_SIZE
									WaterY(q,j) = Rnd(0,360)
								Next 
							Next
					; Create some terrain and load the water texture onto it
					water = CreateTerrain(WATER_GRID_SIZE)
					;watert = LoadTexture("wswirl.jpg")
					watert = CreateTexture(256,256)
					
					SetBuffer TextureBuffer(watert)
						Color  0,0,255 
						Rect 0,0,256,256
						Color 255,255,255
						For i = 1 To 75
							circle = Rnd(2,25)
							Oval Rnd(0,225),Rnd(0,225),circle,circle,0
						Next
					;waterg = LoadTexture("wswirl.jpg")
					waterg = CreateTexture(256,256)

						SetBuffer TextureBuffer(waterg)
						Color  0,200,0 
						Rect 0,0,256,256
						
						For i = 1 To 10000
						    Color 0,Rnd(5,135),0
							Plot Rnd(0,255),Rnd(0,255)
							;Oval Rnd(0,225),Rnd(0,225),circle,circle,0
							
						
						Next
					SetBuffer BackBuffer()
					TextureBlend watert,3
					ScaleTexture watert,.2,.2
					ScaleTexture waterg,.5,.5

					EntityTexture water,watert,0,1
					EntityTexture water,waterg,0,0
					EntityAlpha water,.9
					
					; Resize and position the water
					PositionEntity water,-1000,8,-1000
					;MoveEntity water,0,5,0
					ScaleEntity water,WATER_GRID_SIZE*sizer,WATER_HEIGHT#,WATER_GRID_SIZE*sizer
					
					; Modify the detail of the terrain
					TerrainShading water,False
					curdetail = 500
					TerrainDetail water,curdetail,False

; #################################################################
Repeat

	water_wave()
	
If KeyHit( 57 )=True Then enable=1-enable 
WireFrame enable
move_camera()

	
	RenderWorld
			Color 255,0,0
			Rect midw-4,midh-4,8,8,0

	Flip
	

Until KeyHit(1) = 1
ShowPointer 


Function water_wave()
; Here we itterate through all the cells on the terrain grid (switch wireframe on to
	; see them) and then make them simply bounce up and down.
	For wz = 0 To WATER_GRID_SIZE-1
		For wx = 0 To WATER_GRID_SIZE-1
			hite# = Sin(WaterY(wz,wx))
			ModifyTerrain water,wx,wz,(hite#/4)+.5,False
			WaterY(wz,wx) = WaterY(wz,wx) + 2
			If watery(wz,wx)>3439 Then watery(wz,wx) = 1
		Next
	Next
	
waterangle# = waterangle# +.2
If waterangle#>360 Then waterangle#=.2
RotateTexture watert,Sin(waterangle#)
 ;;RotateTexture cloudmask,waterangle#
End Function

Function curvevalue#(newvalue#,oldvalue#,increments# )
	If increments>1 Then oldvalue#=oldvalue#-(oldvalue#-newvalue#)/increments
	If increments<=1 Then oldvalue=newvalue
	Return oldvalue#
End Function
;==================================================================================
Function move_camera()
	; Movement controls
	If KeyDown(w)=1 Then speed# = speed#+.03
	If KeyDown(a)=1 Then latspeed# = latspeed# - .02
	If KeyDown(s)=1 Then speed# = speed# -.03
	If KeyDown(d)=1 Then latspeed# = latspeed# + .02

latspeed#=latspeed#*.98
speed#=speed#*.98

MY#=curvevalue#(MouseYSpeed(),MY#,3 )
MX#=curvevalue#(MouseXSpeed(),MX#,3 )
TurnEntity campiv,MY#,-MX#,0 ; turn camera up and down
;TurnEntity campiv,0,-MX#,0 ;  turn nnn left --right
RotateEntity campiv,EntityPitch(campiv),EntityYaw(campiv),0
If EntityPitch(campiv)>88 Then RotateEntity campiv,88,EntityYaw(campiv),EntityRoll(campiv)
If EntityPitch(campiv)<-88 Then RotateEntity campiv,-88,EntityYaw(campiv),EntityRoll(campiv)

MoveMouse 100,100

MoveEntity campiv,latspeed#,0,speed#
	


End Function