tokamak physics thread 2:

Blitz3D Forums/Blitz3D Programming/tokamak physics thread 2:

you can? can somebody code a function for me that does this with every mesh i pass to to it? at the moment i have this for my collision entity...

Function MakeTokCollider(mesh)

	surface = GetSurface(mesh,1)
	
	;fill bank with vertices
	vertices=CreateBank(16*CountVertices(surface))
	offset=0
	For v=0 To CountVertices(surface)-1
	 PokeFloat vertices,offset,VertexX#(surface,v)
	 PokeFloat vertices,offset+4,VertexY#(surface,v)
	 PokeFloat vertices,offset+8,VertexZ#(surface,v)
	 PokeFloat vertices,offset+12,0.0
	 offset=offset+16  
	Next
	
	;fill bank with triangles
	triangles=CreateBank(24*CountTriangles(surface))
	offset=0
	For v=0 To CountTriangles(surface)-1
	 PokeInt triangles,offset,TriangleVertex(surface,v,0)
	 PokeInt triangles,offset+4,TriangleVertex(surface,v,1)
	 PokeInt triangles,offset+8,TriangleVertex(surface,v,2)
	 PokeInt triangles,offset+12,0
	 PokeInt triangles,offset+16,0
	 PokeInt triangles,offset+20,0
	 offset=offset+24  
	Next
	
	;Hand over the terrain data to Tokamak
	TOKSIM_SetTerrainMesh vertices,CountVertices(surface),triangles,CountTriangles(surface) 
	
	; Now we can free the banks as Tokamak has copied all data
	FreeBank vertices
	FreeBank triangles

End Function


i also made these:

Function CreateTokCube(entity,rb,x#,y#,z#,xs#=1.0,ys#=1.0,zs#=1.0,mass#=1.0)

	ScaleEntity entity,xs,ys,zs
	PositionEntity entity,x,y,z
	
	TOKRB_AddBox rb,xs*2,ys*2,zs*2
	TOKRB_SetPosition rb,x,y,z
	TOKRB_SetLinearDamping rb,0.001
	TOKRB_SetMass rb,mass
	TOKRB_SetBoxInertiaTensor rb,xs,ys,zs,mass

End Function


Function CreateTokSphere(entity,rb,x#,y#,z#,rad#=1.0,mass#=1.0)

	ScaleEntity entity,rad,rad,rad
	PositionEntity entity,x,y,z
	
	TOKRB_AddSphere rb,rad#*2
	TOKRB_SetPosition rb,x,y,z
	TOKRB_SetLinearDamping rb,0.001
	TOKRB_SetMass rb,mass
	TOKRB_SetBoxInertiaTensor rb,rad,rad,rad,mass

End Function


Function CreateTokCylinder(entity,rb,x#,y#,z#,rad#=1.0,height#=1.0,mass#=1.0)

	TOKRB_AddCylinder rb,rad*2,height
	TOKRB_SetPosition rb,x,y,z
	TOKRB_SetLinearDamping rb,0.001 
	TOKRB_SetAngularDamping rb,0.01 
	TOKRB_SetMass rb,mass
	TOKRB_SetCylinderInertiaTensor rb,rad*2,height,mass

End Function


to be used as such:

	nr=Rnd(1,3)	
		
	If nr=1 Then
		obj(i) = CreateCube()
		rb(i) = TOKRB_Create()
		CreateTokCube(obj(i),rb(i),x#,15+i*0.2,z#,1,1,1,2)
	ElseIf nr=2 
		obj(i) = CreateSphere()
		rb(i) = TOKRB_Create()
		CreateTokSphere(obj(i),rb(i),x#,15+i*0.2,z#,1,1.5)
	ElseIf nr=3 
		obj(i) = CreateCylinder()
		rb(i) = TOKRB_Create()
		CreateTokCylinder(obj(i),rb(i),x#,15+i*0.2,z#,1,1,2)
	EndIf


figured it might help you guys...