Whirlpool effect

Blitz3D Forums/Blitz3D Programming/Whirlpool effect

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Is this of any use? just created it :-)
Pretty hypnotising effect if you also turn on texture rotation :)


;swirl example by Jeppe Nielsen 2004
Graphics3D 800,600,16,2

cam=CreateCamera()
PositionEntity cam,0,0,-2

tex=CreateTexture(32,32)
SetBuffer TextureBuffer(tex)
Color 255,255,255
Rect 0,0,32,32
Color 255,0,0
Rect 0,0,16,16
Rect 16,16,16,16
SetBuffer BackBuffer()
ScaleTexture tex,0.1,0.1


matrix=CreateMatrix(5,5,50,50)
EntityFX matrix,1

EntityTexture matrix,tex

swirlspeed#=1

control=0

rotatetex=0

Repeat

SwirlMesh(matrix,0,0,swirlspeed)

RenderWorld

Color 0,0,0
Text 400,20,"+ / - to change swirl speed",1
Text 400,30,"Space to toggle between sinus/manual control",1
Text 400,40,"Return to toggle texture rotation on/off",1

If KeyHit(57)

	control=1-control
	swirlspeed#=0

EndIf

If KeyHit(28)

	rotatetex=1-rotatetex

EndIf

If rotatetex=1

a#=a#+1
RotateTexture tex,a

EndIf

If control=1
	
	If KeyDown(78)
	
		swirlspeed=swirlspeed+0.1
	
	EndIf
	
	If KeyDown(74)
	
		swirlspeed=swirlspeed-0.1
	
	EndIf
	
Else

	swirlspeed=Sin(MilliSecs()/10)*2

EndIf

Flip

Until KeyDown(1)
End


Function CreateMatrix(wid#,hei#,secx,secy,parent=0)
mesh=CreateMesh(parent)
surf=CreateSurface(mesh)

dx#=1/Float(secx)
dy#=1/Float(secy)

y#=0
For yy=1 To secy
	x#=0
	For xx=1 To secx
		
		vert=AddVertex(surf,x#,y#,0,x#,y#,0)
		AddVertex(surf,x#+dx#,y#,0,x#+dx#,y#,0)
		AddVertex(surf,x#,y#+dy#,0,x#,y#+dy#,0)
		AddVertex(surf,x#+dx#,y#+dy#,0,x#+dx#,y#+dy#,0)
		
		AddTriangle surf,vert,vert+3,vert+1
		AddTriangle surf,vert+2,vert+3,vert
		
		x#=x#+dx#
	Next
	y#=y#+dy#
Next

ScaleMesh mesh,wid#,hei#,1
PositionMesh mesh,-wid/2,-hei/2,0

Return mesh
End Function

Function SwirlMesh(mesh,x#,y#,speed#)
surf=GetSurface(mesh,1)
vertices=CountVertices(surf)-1

For v=0 To vertices
	
	dx#=VertexX(surf,v)-x
	dy#=VertexY(surf,v)-y
	
	dist#=Sqr(dx*dx+dy*dy)
	
	modifier#=2.718-Exp(dist^0.25);change this to change swirl effect
	;modifier#=dist
	;modifier#=1/dist
	
	an#=ATan2(dy,dx)+speed*modifier#
	
	VertexCoords surf,v,x+Cos(an)*dist,y+Sin(an)*dist,0
	
Next
End Function