tokamak - using a terrain with TOKSIM_SetMesh?

Blitz3D Forums/Blitz3D Programming/tokamak - using a terrain with TOKSIM_SetMesh?

DrakeX(Posted 2004) [#1]
don't you hate it when you work on something for three days, post it on the forums, and then figure it out in an hour?

anyway here is the function that works now.

Function TOK_AddTerrainMesh(mesh,mat=-1,textureindex=0)
	If EntityClass(mesh)<>"Terrain" Then RuntimeError "Not a terrain in TOK_AddTerrainMesh"
	scount=TerrainSize(mesh)
	ttltris=ttltris+((scount-1)*(scount-1)*2)
	ttlvert=ttlvert+(scount*scount)
	
	ResizeBank triangles,ttltris*24
	ResizeBank vertices,ttlvert*16
	
	ctr=ttltris
	tric=tric+cvt
	cvt=ttlvert
	;add vertices to bank
	For x=0 To TerrainSize(mesh)-1
		For z=0 To TerrainSize(mesh)-1
			TFormPoint x,TerrainHeight(mesh,x,z),z,mesh,0
			PokeFloat vertices,offsetv,TFormedX()
			PokeFloat vertices,offsetv+4,TFormedY()
			PokeFloat vertices,offsetv+8,TFormedZ()
			PokeFloat vertices,offsetv+12,0.0
			offsetv=offsetv+16
		Next
	Next
	
	If mat<=0
		mindex=0
	Else
		mindex=mat
	EndIf
	
	;fill bank with triangles 
	For x=0 To TerrainSize(mesh)-2
		For z=0 To TerrainSize(mesh)-2
			v1=(x*TerrainSize(mesh))+z
			v2=(x*TerrainSize(mesh))+z+1
			v3=((x+1)*TerrainSize(mesh))+z+1
			v4=((x+1)*TerrainSize(mesh))+z
			
			PokeInt triangles,offsett,tric+v1
			PokeInt triangles,offsett+4,tric+v2
			PokeInt triangles,offsett+8,tric+v3
			PokeInt triangles,offsett+12,mindex
			PokeInt triangles,offsett+16,0
			PokeInt triangles,offsett+20,0
			offsett=offsett+24
			
			PokeInt triangles,offsett,tric+v3
			PokeInt triangles,offsett+4,tric+v4
			PokeInt triangles,offsett+8,tric+v1
			PokeInt triangles,offsett+12,mindex
			PokeInt triangles,offsett+16,0
			PokeInt triangles,offsett+20,0
			offsett=offsett+24
		Next
	Next
End Function


feel free to use it along with the TOK_SetMesh command that's used in the wrapper examples :)


Bot Builder(Posted 2004) [#2]
looks like my code, what was the problem with it?

http://playerfactory.proboards25.com/index.cgi?board=tokamak2&action=display&num=1077666832


DrakeX(Posted 2004) [#3]
oh yes, it's based on your code (the functions that came with the samples for the tokamak wrapper). i was multiplying the coords in the TFormPoint by the terrain's scale.. not knowing that blitz took into account the object's scale already. so it was horribly large.


Tom(Posted 2004) [#4]
it was horribly large


Sounds like something Ravey would say :)