Deforming Vertices randomly

Blitz3D Forums/Blitz3D Programming/Deforming Vertices randomly

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.

Puki - I am currently having to work from just the demo version of B3D until I get my computer set up at home. The demo version doesnt have that file included unfortunately.

Stevie G, I understand Beziers are like smooth curves. I think I see what you mean, and yeah, the end result would make some great looking caverns, but it's way beyond my capabilities right now!

I combined Rob Farley's "Asteroid" code, and Dave Bird's "Segmented Cube" code, but it only seems to deform one face (typically the one facing vertically down), Not too sure what to do with it. Sorry I know Im being a pain with this, I never realised such a simple concept could get so involved!

Here's what I have so far:
Graphics3D 800,600

SetBuffer BackBuffer()


;*****************************INITIALISE******************************

cam=CreateCamera()

CameraViewport cam,0,0,800,600

;****************************BUILD ARRAYS *****************************

Dim vpos#(1,1)
Dim Map(100)

;***************************CREATE QUICK RANDOM MAP**********************


	For f= 1 To 100

		Map(f)=CreateWall()
		
		tt=LoadTexture("t.bmp")

		EntityTexture Map(f),tt
		
		Morph(Map(f))
				
		PositionEntity Map(f),Rand(-20,20),0,Rand(-20,20)
	Next

;*************************** MAIN LOOP ****************************
While Not KeyDown(1)

If KeyDown(200) Then MoveEntity cam,0,0,0.2
If KeyDown(208) Then MoveEntity cam,0,0,-0.2

If KeyDown(205) Then TurnEntity cam,0,-1,0
If KeyDown(203) Then TurnEntity cam,0,1,0

UpdateWorld
RenderWorld

Flip

Wend
End

;*******************************************FUNCTIONS************************



















Function CreateWall()

;*****************************CREATE SEGMENTED CUBE FROM 6 SIDES **************

	mesh=CreateMesh()
	
	segs=3
	
	For scnt=0 To 3
		surf=CreateSurface( mesh )
		stx#=-.5
		sty#=stx
		stp#=Float(1)/Float(segs)
		y#=sty
		For a=0 To segs
			x#=stx
			v#=a/Float(segs)
			For b=0 To segs
				u#=b/Float(segs)
				AddVertex(surf,x,y,0.5,u,v)
				x=x+stp
			Next
			y=y+stp
		Next
		For a=0 To segs-1
			For b=0 To segs-1
				v0=a*(segs+1)+b:v1=v0+1
				v2=(a+1)*(segs+1)+b+1:v3=v2-1
				AddTriangle( surf,v0,v1,v2 )
				AddTriangle( surf,v0,v2,v3 )
			Next
		Next
		RotateMesh mesh,0,90,0
	Next
	;top and bottom
	RotateMesh mesh,90,0,0
	For scnt=0 To 1
		surf=CreateSurface( mesh )
		stx#=-.5
		sty#=stx
		stp#=Float(1)/Float(segs)
		y#=sty
		For a=0 To segs
			x#=stx
			v#=a/Float(segs)
			For b=0 To segs
				u#=b/Float(segs)
				AddVertex(surf,x,y,0.5,u,v)
				x=x+stp
			Next
			y=y+stp
		Next
		For a=0 To segs-1
			For b=0 To segs-1
				v0=a*(segs+1)+b:v1=v0+1
				v2=(a+1)*(segs+1)+b+1:v3=v2-1
				AddTriangle( surf,v0,v1,v2 )
				AddTriangle( surf,v0,v2,v3 )
			Next
		Next
		RotateMesh mesh,180,0,0
	Next
	UpdateNormals mesh

Return mesh
End Function


;**************************MORPH VERTS*****************************

Function Morph(mesh)

surftotal=CountSurfaces(mesh)

For xx= 1 To surftotal
as1=GetSurface(mesh,xx)

; record the locations of the verts
Dim vpos#(CountVertices(as1)-1,3)
For n=0 To CountVertices(as1)-1
	vpos(n,0)=VertexX(as1,n)
	vpos(n,1)=VertexY(as1,n)
	vpos(n,2)=VertexZ(as1,n)
	vpos(n,3)=0
Next

For n=0 To CountVertices(as1)-1

; change these to make it more or less messy
xm#=Rnd(-.3,.3)
ym#=Rnd(-.0,.0)
zm#=Rnd(-.3,.3)

	For nn=0 To CountVertices(as1)-1
	
	; if the vert has not been monkeyed with monkey away
	If vpos(nn,3)=0
		If vpos(n,0)=vpos(nn,0) And vpos(n,1)=vpos(nn,1) And vpos(n,2)=vpos(nn,2)
			VertexCoords as1,nn,vpos(nn,0)+xm,vpos(nn,1)+ym,vpos(nn,2)+zm
			vpos(nn,3)=1
			EndIf
		EndIf
		
	Next
Next

Next

Return mesh

End Function





_________________________________EDIT__________________________________



Ive amended the code. Ive kinda got it sussed, only because CopyMesh would need retexturing and remorphing, and CopyEntity would result in identical blocks, I have simply created a new block for every map position. This shouldnt be much of a problem, graphics memory wise, and I hope to occlude more distant blocks eventually for rendering speeds etc. As I trial, I am quite pleased so far, although I still need to determine how to match the split edges up...