;Pushover with TOKAMAK AppTitle "Pushover V0.3" Graphics3D 800,600,0,2 cam = CreateCamera() MoveEntity cam,0,20,-50 ;setup tokamak Const FPS = 30 Global period=1000/FPS Global time=MilliSecs()-period Global tents = 100 Global ents Dim obj(tents) Dim rb(tents) Type TOK_Entity Field entity%,body% End Type TOKSIM_CreateSimulator(0,-10,0) SeedRnd MilliSecs() ;creating objects For x = 1 To 10 For y = 0 To 3 obj(ents + 1) = CreateCube() rb(ents + 1) = TOKRB_Create() TOKRB_CollideConnected rb(ents + 1),True TOKRB_AddBox rb(ents + 1),2.0,2.0,2.0 TOKRB_SetPosition rb(ents + 1),0.0+x*2-10,2.0+y*1.97,0 TOKRB_SetLinearDamping rb(ents + 1),0.003 TOKRB_SetAngularDamping rb(ents + 1),0.001 TOKRB_SetMass rb(ents + 1),0.9 TOKRB_SetBoxInertiaTensor rb(ents + 1),2.0,2.0,2.0,3.0 TOKRB_SetSleepingParameter rb(ents + 1),0.01 EntityColor obj(ents+1),Rnd(255),Rnd(255),Rnd(255) ents = ents + 1 Next Next Global mover = CreateCube() PositionEntity mover,0,2,-10 rb(ents + 1) = TOKRB_Create() TOKRB_CollideConnected rb(ents + 1),True TOKRB_AddBox rb(ents + 1),4.0,4.0,4.0 TOKRB_SetPosition rb(ents + 1),EntityX(mover),EntityY(mover),EntityZ(mover) TOKRB_SetLinearDamping rb(ents + 1),0.003 TOKRB_SetAngularDamping rb(ents + 1),0.001 TOKRB_SetMass rb(ents + 1),1000 TOKRB_SetBoxInertiaTensor rb(ents + 1),4.0,4.0,4.0,6.0 TOKRB_SetSleepingParameter rb(ents + 1),0.1 ;load area light = CreateLight() map = CreateCube() ScaleMesh map,20,1,20 TurnEntity map,0,0,0 EntityColor map,255,0,0 TOK_MakeStaticMesh%(map) ;main loop .loop If KeyDown(1) Then TOKSIM_DestroySimulator() End EndIf If KeyDown(200) Then MoveEntity mover,0,0,0.2 If KeyDown(208) Then MoveEntity mover,0,0,-0.2 If KeyDown(203) Then MoveEntity mover,-0.2,0,0 If KeyDown(205) Then MoveEntity mover,0.2,0,0 ;finish 3d updatetokamak() ;debug FPSframes=FPSframes+1 If MilliSecs()>FPSmillis+1000 Then FPSs=FPSframes FPSmillis=MilliSecs() FPSframes=0 End If Text 0,0,"FPS: "+fpss Flip Cls Goto loop ;functions Function updatetokamak() Repeat elapsed=MilliSecs()-time Until elapsed ticks=elapsed/period tween#=Float(elapsed Mod period)/Float(period) For k=1 To ticks time=time+period If k=ticks Then CaptureWorld TOKSIM_Advance(1.5/FPS,1) UpdateWorld() Next ;updateentities For x = 1 To ents PositionEntity obj(x),TOKRB_GetX(rb(x)),TOKRB_GetY(rb(x)),TOKRB_GetZ(rb(x)) RotateEntity obj(x),TOKRB_GetPitch(rb(x)),TOKRB_GetYaw(rb(x)),TOKRB_GetRoll(rb(x)),False Next TOKRB_SetPosition rb(ents+1),EntityX(mover),EntityY(mover),EntityZ(mover) RenderWorld tween End Function ;make toka map Function TOK_MakeStaticMesh%(mesh%) Local scount%,ind%,surface%,ttltris%,ttlvert%,cvt%,v% Local vertices%,triangles%,offsetv%,offsett%,ctr%,tric% 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) 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) offsetv = offsetv + 16 Next 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) offsett = offsett + 24 Next Next TOKSIM_SetStaticMesh vertices,ttlvert,triangles,ttltris FreeBank vertices FreeBank triangles End Function