Liquid Orb

Blitz3D Forums/Blitz3D Programming/Liquid Orb

Neochrome(Posted 2003) [#1]
Need some help with a Liquid Orb FX.
i haven't a clue how to start to make a sphere deform like this.. im not a good coder so i rely on your help.

think of an sphere that is made of water with ripples going through it.. Any one up for the challenge here? Credits will be added to the game


Rob(Posted 2003) [#2]
This is my xmas pressie to you :)

You only need one single function. Call it when you want to ripple something. It is called RippleMesh() :)

;set up
Graphics3D 640,480,16,2
camera=CreateCamera()
PositionEntity camera,0,0,-3
light=CreateLight()
RotateEntity light,45,45,0

;any mesh with enough verts
mymesh = CreateSphere(12)
EntityShininess mymesh,1

While Not KeyHit(1)
	RippleMesh(mymesh,1,20,0.01)
	UpdateWorld
	RenderWorld
	Flip
Wend
End

;mesh is your mesh
;speed is how fast it ripples
;density is how fine the effect is (experiment to see how much of the mesh you affect)
;depth is how much it ripples

Function ripplemesh(mesh,speed#,density#,depth#)
	count=MilliSecs()*speed
	For scount=1 To CountSurfaces(mesh)
		surface = GetSurface(mesh,scount)
		numverts=CountVertices(surface)-1
		For i=0 To numverts
			a#=Cos(count+(i*density))*speed
			b#=Sin(count+(i*density))*speed
			c#=-b;Sin(count+(i*density))*speed
			nx#=VertexNX(surface,i)*depth
			ny#=VertexNY(surface,i)*depth
			nz#=VertexNZ(surface,i)*depth			
			x#=VertexX(surface,i)
			y#=VertexY(surface,i)
			z#=VertexZ(surface,i)		
			VertexCoords surface,i,x#+(a*nx),y#+(b*ny),z#+(c*nz)
		Next
	Next
End Function


It can be made faster by putting the cos and sin into a lookup table but thats a little bit more complex. I made it like this because you don't need anything but the function to make it easy to use.


Neochrome(Posted 2003) [#3]
sweet... nice one.. Thank you Rob..
it doesn't go back to a sphere tho it just gets worse.. how can i fix this?


Rob(Posted 2003) [#4]
Mmm :) to do this you have two options:
1. make a copy of the mesh
2. remember all the original positions (so you can fade the effect in and out again)

I can't promise I'll do any more work on it though.


Neochrome(Posted 2003) [#5]
hehe, this is cool... i'll play with it see what i come up with... again, thanks!


poopla(Posted 2003) [#6]
Neomancer, I'm beginning work on a mesh deformation library thrusday. I might do a tutorial for the subject.


Neochrome(Posted 2003) [#7]
cool.. i have real problems with deforming Meshes. i screw it up at least 9 out of 10 and end up with memory errors!

im not a strong coder, but i love doing it tho ;o)