Whirlpool effect

Blitz3D Forums/Blitz3D Programming/Whirlpool effect

Tracer(Posted 2004) [#1]
I am trying to create sort of a whirlpool effect on a 'matrix' of triangles (all on one surface of course).. i can move the vertices just fine, i just don't seem to be able to get a decent looking effect :)

Any ideas?

Tracer


IPete2(Posted 2004) [#2]
Tracer,

Are you rotating the texture too at the same time as rotating and moving the mesh?

You may want to make the mesh alpha'd and add a second mesh slightly smaller inside it.

IPete2.


Tracer(Posted 2004) [#3]
hmm

whirlpool is the wrong name.. i am looking for a twisting motion (basically, part of the mesh twists circle wise, crunching up the texture and such).

Tracer


Jeppe Nielsen(Posted 2004) [#4]
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



Techlord(Posted 2004) [#5]
Jeppe Nielsen,

I was getting sleepy....very sleepy :) Too kewl.


EOF(Posted 2004) [#6]
Cool!
There's another one here but I can't remember the author of this code. Possibly FredBorg(?)
Use this image for a nice effect:

; Vortex demo.
; Creates custom cone.  Apex of cone <===> center of texture.
; Oriented so apex is on z+ axis, interior of cone is visible.

Graphics3D 640, 480

tx = LoadTexture("vortex2.jpg") ; image should be square, perhaps 256 x 256.
VortexCone = createVortexCone(24,32) ; try different heights
EntityTexture VortexCone, tx
EntityFX VortexCone, 1 ; full bright

cam = CreateCamera( )
PositionEntity cam, 0,0,-3
CameraZoom cam, 3.8 ; zoom >= 3.8 fills the screen

While Not KeyDown(1)
 TurnEntity VortexCone, 0,0, -.26
 RenderWorld : Flip
Wend
End

Function CreateVortexCone(segments=24,height=1)
 Local n, m,s, a#,t#, u#,v# 
 m=CreateMesh()
 s=CreateSurface(m)
 a=360.0/segments
 ; First two vertices are apex and one point on the base.
 AddVertex s,0,0,height,0.5,0.5     ; vertex 0
 AddVertex s,Cos(t),Sin(t),0,1,0.5  ; vertex 1
 For n=2 To segments
  t=t+a : u=(1+Cos(t))/2 : v=(1-Sin(t))/2
  AddVertex s,Cos(t),Sin(t),0,u,v  ; vertex n
  AddTriangle s,0,n,n-1
 Next 
 AddTriangle s,0,1,n-1
 Return m
End Function



Tracer(Posted 2004) [#7]
Nice!

Jeppe's one comes closest to what i want (and IS very hypnotic!) The last one is pretty cool as well :)

Thanks guys.. Especially Jeppe's will be a good basis to figure out how to do the effect i am experimenting with!

Tracer