Peristalis / Wobble Model Effect

Blitz3D Forums/Blitz3D Programming/Peristalis / Wobble Model Effect

Clyde(Posted 2004) [#1]
Here's my feeble attempt at trying to recreate a popular demo effect, where objects twist around on an axis. I know the effect as a Peristalis Effect.

I wondered if you could help me make it a proper peristalis effect. As allthough it doesnt look too bad, it does lack in smoothness and the movement is all screwy. And to be honest, I don't quite know how to address it too well. And please use your own media, as Im unable to host at present.

Here's the routine that I'd appreciate any help with:

;peristalis effect :WIP
;by Mikey F

Const xres=640,yres=480
Graphics3D xres,yres,32
SetBuffer BackBuffer()

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

lit=CreateLight()
AmbientLight 000,000,000

Global cntsurf,surf

Global UpdateX#
Global UpdateY#
Global UpdateZ#

Global angle1#,angle2#
Global angle3#,angle4#
Global angle5#,angle6#
Global counter

Global aa1#,aa2#,aa3#,aa4#,aa5#,aa6#


;-==========================================================-
;-=[load and make / store vertex and triangles etc        ]=-
;-=[in order to manipulate each face, that's the theory ;)]=-
;-==========================================================-

Global copymodel	=LoadMesh	("media\yourmodel.3ds")
Global surf1		=GetSurface	(copymodel,1)

Global effectmod	=CreateMesh()
Global surf2		=CreateSurface(effectmod)

Global amount1		=CountVertices	(surf1)
Global amount2		=CountTriangles	(surf1)

Dim vrt(amount1,3),vrtx#(amount1),vrty#(amount1),vrtz#(amount1)
Dim tri(amount2)


For count=0 To CountVertices(surf1)-1

	AddVertex(surf2,VertexX(surf1,count),VertexY(surf1,count),VertexZ(surf1,count))

 	VertexNormal surf2,count, VertexNX( surf1, count), VertexNY( surf1, count), VertexNZ( surf1, count )

	vrtx(count)=VertexX#(surf2,count)
	vrty(count)=VertexY#(surf2,count)
	vrtz(count)=VertexZ#(surf2,count)

	vertices=count

Next

For count=0 To CountTriangles(surf1)-1

	tri(count)=AddTriangle(surf2,TriangleVertex(surf1,count,0),TriangleVertex(surf1,count,1),TriangleVertex(surf1,count,2))
	triangles=count

Next

FreeEntity 		copymodel

texture			=LoadTexture("media\texture.png",512)

ScaleEntity 	effectmod,.1,.1,.1
;EntityShininess effectmod,.5
PositionEntity 	effectmod,0,0,10
EntityFX 		effectmod,16
EntityTexture	effectmod,texture

;-=============-
;-=[Main Loop]=-
;-=============-
While Not KeyHit(1)
Cls
	
	wobble_wobble()
	
	RotateEntity effectmod,xr#,yr#,zr#
	
	xr#=xr#+.3
	yr#=yr#+.5
	zr#=zr#+.4

	RenderWorld()
	UpdateWorld()
	
Flip
Wend
FreeEntity effectmod


Function wobble_wobble()

cntsurf	=CountSurfaces	(effectmod)
surf	=GetSurface	(effectmod,cntsurf)

aa1=angle1
aa2=angle2

aa3=angle3
aa4=angle4

aa5=angle5
aa6=angle6

For count=0 To amount1-1
	
	x#=vrtx#(count)
	y#=vrty#(count)
	z#=vrtz#(count)

	counter=count ;comment this for different movement :)

	UpdateX=Sin(aa1+counter)*4;+Cos(aa2+counter)*12
	UpdateY=Cos(aa3+counter)*3;+Cos(aa4+counter)*32
	
	UpdateZ=Sin(aa5+counter)*12;+Cos(aa6+counter)*14

    VertexCoords surf,count,x#+UpdateX,y#+UpdateY,z#+UpdateZ

Next

angle1 = angle1 +2	
angle2 = angle2 -4
;-
angle3 = angle3 +3
amgle4 = angle4 +2
;-
angle5 = angle5 -2
angle6 = angle6 +1

If angle1>359 Then angle1=000
If angle2<000 Then angle2=359
;--
If angle3>359 Then angle3=000
If angle4>359 Then angle4=000
;--
If angle5<000 Then angle5=359
If angle6>359 Then angle6=000

End Function



Clyde(Posted 2004) [#2]
Any joy?

Cheers,
Mikey F


DJWoodgate(Posted 2004) [#3]
Well peristalsis brings to mind Halo's Blit3d MeshFx code, which you should have somewhere in your 3d samples folder. He calls it the egg tube effect. That is what I would call peristalsis, though maybe what you want is more akin to flagelation, in which case any number of people here should be able to oblige ;)


Clyde(Posted 2004) [#4]
Wicked what's flagelation?
Cheers :)


DJWoodgate(Posted 2004) [#5]
Sorry typo, I meant flagellation.


Clyde(Posted 2004) [#6]
Sorry to be thick though mate, what exactly is it?
Any examples Please?


Clyde(Posted 2004) [#7]
Ah well thanks anyway.


jfk EO-11110(Posted 2004) [#8]
Well maybe I'd try to calculate each vertexes distance to the center, then add some inertia to any movement of the mesh. Depending on the distance of each vertex, it will be more sluggish, just like your beer-belly or some huge b**bs, they wobble more than - say - the near center parts (well, distance to the center Y axe, probably). Just a thought.


Clyde(Posted 2004) [#9]
Sounds interesting all this, but Im still none the wiser.


Clyde(Posted 2004) [#10]
Any help with this?

All I want to do is make a mesh twist about.
Cheers


jfk EO-11110(Posted 2004) [#11]
Well, if I was you I would solve this problem like this: Make a 2D Program that will wobble a single point.

like

Graphics 640,480,16,2
SetBuffer BackBuffer()


While KeyDown(1)=0
 Cls
 

 If MilliSecs() > tt
  tt=MilliSecs()+100 ; update rubber logic every n MilliSecs
  If MouseHit(1)
   newx#=MouseX()
   newy#=MouseY()
   tensionx#=(newx#-x#)/1.5 ; intial motion detection
   tensiony#=(newy#-y#)/1.5
  EndIf

  oldx#=x
  oldy#=y#
  x#=x#+ tensionx#
  y#=y#+ tensiony#


  If ((x > newx) And (oldx <= newx)) Or ((x < newx) And (oldx >= newx))
   tensionx#=(newx#-x#)/1.1 ; amount of elasticity (near 1.0 = very wobbly)
   tensiony#=(newy#-y#)/1.1
  EndIf
  If ((y > newy) And (oldy <= newy)) Or ((y < newy) And (oldy >= newy))
   tensionx#=(newx#-x#)/1.1
   tensiony#=(newy#-y#)/1.1
  EndIf
 EndIf

 realx#=realx+(x-realx)/5.0 ; smooth rubber chanches
 realy#=realy+(y-realy)/5.0


 Oval realx-5,realy-5,10,10,1
 Text 0,0, "Hit the mouse somewhere"
 Flip
Wend


Now you only have to add a 3rd dimension, and feed the algorithm with all vertices of your mesh. The inital motion detection that is given by a mouseclick in this example needs to be calculated from the previous and new mesh location. Now what I said in the first post: you can modify the wobble value (here 1.1) depending on the distance of the vertices to the center of the mesh. Probably that looks really impressive.