I'm actually having some great success with that source code Vorderman, thanks a bunch. I also had a hard time getting the ground to do collisions, probably because of my inexperience with Tokamak though.
It seems to me you just assign a collisionID to a rigidbody and then set the collisionresponse you want....but it's not quite working that way. :(
Press the Up Arrow to spawn a cube.
Here's the source:
;Tokamak Test
Graphics3D 1024,768,32,1
SetBuffer BackBuffer()
SeedRnd MilliSecs()
Global camera = CreateCamera()
PositionEntity camera,0,20,-20
RotateEntity camera,40,0,0
light = CreateLight()
RotateEntity light,0,0,45
;TOKAMAK ENVIRONMENT SETUP
TOKSIM_SetRigidBodiesCount(500)
TOKSIM_SetGeometriesCount(500)
TOKSIM_CreateSimulator(0,-9.8,0)
;TOKSIM_SetOverlappedPairsCount(50000)
;TOKSIM_SetGeometriesCount(50000)
TOKSIM_SetCollisionResponse(1,2,1)
Global TCube
Type TCube
Field mesh
Field TOK_RB
End Type
;TOKAMAK GROUND PLANE
Global ground = CreateCube()
PositionEntity ground,0,0,0
ScaleMesh ground,20,.1,20
ground_TOKRB = TOKRB_Create()
TOKRB_AddBox ground_TOKRB,20,.1,20
TOKRB_SetCollisionID ground_TOKRB,2
;MakeTokCollider( ground )
;TOKSIM_SetMaterial 1,10,10 ;ragdoll body parts use this setting
;TOKSIM_SetMaterial 2,0.4,0.15 ;tokamak level mesh uses this setting
Global total%
Local newTime% = MilliSecs()
Local oldTime% = newTime
Local deltaTime#
While Not KeyHit(1)
Cls
newTime = MilliSecs()
deltaTime = (newTime - oldTime) / 1000.0
oldTime = newTime
If KeyDown(200) Then CreateTCube()
For cube.TCube = Each TCube
PositionEntity cube\mesh,TOKRB_GetX#(cube\TOK_RB),TOKRB_GetY#(cube\TOK_RB),TOKRB_GetZ#(cube\TOK_RB),True
RotateEntity cube\mesh,TOKRB_GetPitch#(cube\TOK_RB),TOKRB_GetYaw#(cube\TOK_RB),TOKRB_GetRoll#(cube\TOK_RB),True
Next
;ADVANCE TOKAMAK SIMULATION
TOKSIM_Advance(deltaTime,2)
UpdateWorld
RenderWorld
Text 5,5,deltaTime
Text 5,30,total
Flip
Wend
;DESTROY THE TOKAMAK SIMULATION
TOKSIM_DestroySimulator()
End
Function CreateTCube()
total = total + 1
cube.TCube = New TCube
cube\mesh = CreateCube()
EntityColor cube\mesh,Rand(255),Rand(255),Rand(255)
ScaleEntity cube\mesh,.5,.5,.5
PositionEntity cube\mesh,0,10,0
cube\TOK_RB = TOKRB_Create()
TOKRB_AddBox cube\TOK_RB,1.0,1.0,1.0
TOKRB_SetMass cube\TOK_RB,10.0
TOKRB_SetPosition cube\TOK_RB,EntityX#(cube\mesh),EntityY#(cube\mesh),EntityZ#(cube\mesh)
;TOKGEOM_SetMaterialIndex cube\TOK_RB,1
TOKRB_ApplyImpulse cube\TOK_RB, Rnd(-1.0,1.0) , Rnd(1,01) ,Rnd(-1.0,1.0)
TOKRB_ApplyTwist cube\TOK_RB, Rnd(-5.0,5.0) , Rnd(-5.0,5.0) ,Rnd(-5.0,5.0)
TOKRB_SetCollisionID cube\TOK_RB,1
End Function
Function MakeTokCollider(mesh)
scount=CountSurfaces(mesh)
For ind=1 To scount
surface=GetSurface(mesh,ind)
ttltris=ttltris+CountTriangles(surface)
ttlvert=ttlvert+CountVertices(surface)
Next
vertices=CreateBank(16*ttlvert)
triangles=CreateBank(24*ttltris)
offsetv=0
offsett=0
For ind=1 To scount
surface = GetSurface(mesh,ind)
ctr=CountTriangles(surface)
tric=tric+cvt
cvt=CountVertices(surface)
;fill bank with vertices
For v=0 To cvt-1
PokeFloat vertices,offsetv,VertexX#(surface,v)
PokeFloat vertices,offsetv+4,VertexY#(surface,v)
PokeFloat vertices,offsetv+8,VertexZ#(surface,v)
PokeFloat vertices,offsetv+12,0.0
offsetv=offsetv+16
Next
;fill bank with triangles
For v=0 To ctr-1
PokeInt triangles,offsett,tric+TriangleVertex(surface,v,0)
PokeInt triangles,offsett+4,tric+TriangleVertex(surface,v,1)
PokeInt triangles,offsett+8,tric+TriangleVertex(surface,v,2)
PokeInt triangles,offsett+12,2 ; Material ID
PokeInt triangles,offsett+16,0
PokeInt triangles,offsett+20,0
offsett=offsett+24
Next
Next
;Hand over the terrain data to Tokamak
TOKSIM_SetStaticMesh vertices,ttlvert,triangles,ttltris
; Now we can free the banks as Tokamak has copied all data
FreeBank vertices
FreeBank triangles
End Function