tokamak physics thread 2:

Blitz3D Forums/Blitz3D Programming/tokamak physics thread 2:

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.

Car demo. still very buggy. use arrows to drive. you can move the camera around with wasd + mouse

this is a car made from a box with cylinders attached to the rear wheels with hingjoints and independent axles on the front. the front wheels go a little buggy every now and again.

have a look...(this is v3 wrapper code)


;# TOKAMAK car DEMO v0.0017 (bradford6)
; Credits:
; SWEENIE for creating the TOKAMAK WRAPPER
; www.tokamakphysics.com to get SDK
; note:
; you must put TOKAMAK.DLL (from SDK) in system32
; must put sweenies tokamak files in blitz3d/userlibs directory
; this is rev -1 so it is very early and probably buggy, 


Graphics3D 800,600,0,2
Global midw = GraphicsWidth()/2
Global midh =GraphicsHeight()/2
SetBuffer BackBuffer()
HidePointer 
WireFrame False

Const ENTS=100	; TOTAL NUMBER OF TOKAMAKPHYSICS ENTITIES
Const FPS=50
Const w=17, s=31, a=30, d=32, space=57

Global campiv = CreatePivot()
Global camera = CreateCamera(campiv)
Global pickmarker = CreateSphere(4)
EntityAlpha pickmarker,.75
Global pictentity,pnx#,pny#,pnz#,pcx#,pcy#,pcz#
Global latspeed#,speed#,MX#,MY#

Global TOKS
CameraClsColor(camera,0,0,0)


TOKSIM_CreateSimulator(ENTS,1,0,-10,0)

; go and create a generic checkerboard texture to apply to the objects
cubetex = create_cube_texture()
spheretex = create_sphere_texture()
cyltex = create_cyl_texture()
worldtex = create_world_texture()


world = CreateCube()
;world = LoadMesh("roadmap2.3ds")
EntityPickMode world,2
sc# = 50
ScaleMesh world,sc#,sc#,sc# : PositionMesh world,0,sc#,0 : FlipMesh world : EntityTexture world,worldtex
obstacle = CreateCube() : EntityTexture obstacle,cyltex : ScaleMesh obstacle,5,10,10 : PositionMesh obstacle,-10,16,0
RotateMesh obstacle ,0,0,65 : AddMesh obstacle,world

obstacle2 = CreateSphere(6) : EntityTexture obstacle2,cubetex : ScaleMesh obstacle2,10,4,10 : PositionMesh obstacle2,32,-1,30
RotateMesh obstacle2 ,0,0,0 : AddMesh obstacle2,world


maketokcollider(world)
;maketokcollider(obstacle)

Dim obj(ENTS)
Dim rb(ENTS)

SeedRnd MilliSecs()  


; add--------------------------------------------------------------------------

.cardata
	;create_TOK_BOX(xs#,ys#,zs#,xp#,yp#,zp#,damp#,angdamp#,mass#,iw#,ih#,id#,imass#, texture)
	;create_TOK_BOX(8,1,8,0,5,0,0.0025,.125,4,cubetex)
	carwidth#=2 iw#=carwidth#
	carheight#=4 ih#=carheight#
	carlength#=4 id#=carlength#	
	mass# = .5 imass# = mass#
	
	wheelwidth# = 2.5
	wheellength# = 3.5
	wheelclearance# = 2
	wheelheight# = 0.5 ; thickness
	wheeldiameter# = 4 ; tall-ness
	carx# = 2
	cary# = 5
	carz# = 2
	
	; OBJ-1
	create_TOK_BOX(carwidth#,carheight#,carlength#,carx#,cary#,carz#,0.001,0.001,mass#,iw,ih,id,imass,cubetex,"car")

	;create_TOK_BALL(segs,sc#,xp#,yp#,zp#,angdamp#,lindamp#,mass#,IT1#,IT2#)
	; # create tokamak sphere
	
	; ----------------------------------------------------------------------------------

	id#=2
	ih#=3
	iw#=1
	;zs#=1 id#=zs#	
	mass# = 1
	imass# = 1
	
	rearwheelmass# = 3
	angdampfront#= 0.002
	angdamprear# = 0.001
	lindampfront# = 0.002
	lindamprear# = 0.001
	segs = 16
	
	axleiw#=1 axleih#=0.25 axleid#=1 
	
	axlemass# = 1.5
	axleimass# = 1.5
For c = 1 To 4
	Select c
		Case 1 : cx# = carx#-(carwidth#/1.5) : cy# = cary#-(carheight#/2) : cz# = carz#+(carlength#/1.5) : wheelname$ = "leftfront" : inc = 1
					
					; obj 2
					create_TOK_BOX(1.5,.5,1,cx#,cy#,cz#,0.001,0.01,axlemass#,axleiw,axleih,axleid,axleimass,cubetex,"car")

					;obj 3
					create_TOK_CYL(segs,wheeldiameter#,wheelheight#,cx#-1,cy#,cz#,angdampfront#,lindampfront#,mass#,Id#,ih#,imass#,spheretex,wheelname$)
					;create_TOK_ball(segs,wheeldiameter#,cx#-1,cy#,cz#,angdampfront#,lindampfront#,mass#,Id#,imass#,spheretex,wheelname$)
					

					;create_TOK_ball(5,wheelsize#,carx#-wheelheight#,cary#-wheelwidth#,carz#+wheellength#,angdamp#,lindamp#,mass#,Id#,imass#,spheretex,"leftfront")
					EntityColor obj(2),155,0,0 
					EntityColor obj(3),255,0,0 ; red = 
					TOKRB_SetRotation(rb(toks),0,00,90)
					;TOKRB_SetTorque(rb(toks),5,0,0)
					
					; axle
					joint1a = TOKJOINT_Create(2,rb(1),rb(2))
					TOKJOINT_SetType(joint1a,3)
					TOKJOINT_SetPositionAndRotationWorld(joint1a,cx#,cy#,cz#,0,0,0)
					TOKJOINT_Enable(joint1a,True)
					TOKJOINT_SetLowerLimit joint1a,-3.14*0.50 ; (-45 degrees)
					TOKJOINT_SetUpperLimit joint1a,3.14*0.50  ; (+45 degrees)
					TOKJOINT_EnableLimit joint1a,True  

					; wheel
					joint1b = TOKJOINT_Create(2,rb(2),rb(3))
					TOKJOINT_SetType(joint1b,3)
					TOKJOINT_SetPositionAndRotationWorld(joint1b,cx#-1,cy#,cz#,0,0,90)
					TOKJOINT_Enable(joint1b,True)
					TOKJOINT_SetJointLength(Joint1b,3)
					TOKJOINT_SetLowerLimit2 joint1b,-3.14*0.1 ; (-45 degrees)
					TOKJOINT_SetUpperLimit2 joint1b,3.14*0.1  ; (+45 degrees)
					TOKJOINT_EnableLimit2 joint1b,True  

		Case 2 : cx# = carx#+(carwidth#/1.5) : cy# = cary#-(carheight#/2) : cz# = carz#+(carlength#/1.5) : wheelname$ = "rightfront" : inc = 2
					
					
					; obj 4
					create_TOK_BOX(1.5,.5,1,cx#,cy#,cz#,0.001,0.01,axlemass#,axleiw,axleih,axleid,axleimass,cubetex,"car")

					; obj 5
					create_TOK_CYL(segs,wheeldiameter#,wheelheight#,cx#+1,cy#,cz#,angdampfront#,lindampfront#,mass#,Id#,ih#,imass#,spheretex,wheelname$)
					;create_TOK_ball(segs,wheeldiameter#,cx#+1,cy#,cz#,angdampfront#,lindampfront#,mass#,Id#,imass#,spheretex,wheelname$)
					

					;create_TOK_ball(5,wheelsize#,carx#-wheelheight#,cary#-wheelwidth#,carz#+wheellength#,angdamp#,lindamp#,mass#,Id#,imass#,spheretex,"leftfront")
					EntityColor obj(4),0,255,0 ; green= 
					EntityColor obj(5),0,120,0
					TOKRB_SetRotation(rb(toks),0,00,90)
					;TOKRB_SetTorque(rb(toks),5,0,0)
					
					; axle
					joint2a = TOKJOINT_Create(2,rb(1),rb(4))
					TOKJOINT_SetType(joint2a,3)
					TOKJOINT_SetPositionAndRotationWorld(joint2a,cx#,cy#,cz#,0,0,0)
					TOKJOINT_Enable(joint2a,True)
					TOKJOINT_SetLowerLimit joint2a,-3.14*.5 ; (-45 degrees)
					TOKJOINT_SetUpperLimit joint2a,3.14*0.5  ; (+45 degrees)
					TOKJOINT_EnableLimit joint2a,True  

					; wheel
					joint2b = TOKJOINT_Create(2,rb(4),rb(5))
					TOKJOINT_SetType(joint2b,3)
					TOKJOINT_SetPositionAndRotationWorld(joint2b,cx#+1,cy#,cz#,0,0,90)
					TOKJOINT_Enable(joint2b,True)
					TOKJOINT_SetJointLength(Joint2b,.1)
					TOKJOINT_SetLowerLimit2 joint2b,-3.14*0.1 ; (-45 degrees)
					TOKJOINT_SetUpperLimit2 joint2b,3.14*0.1  ; (+45 degrees)
					TOKJOINT_EnableLimit2 joint2b,True  


	

		Case 3 : cx# = carx#-(carwidth#) : cy# = cary#-(carheight#/2) : cz# = carz#-(carlength#/1.5) : wheelname$ = "leftrear" : inc = 3
					; obj 6
					create_TOK_CYL(segs,wheeldiameter#,wheelheight#,cx#,cy#,cz#,angdamprear#,lindamprear#,rearwheelmass#,Id#,ih#/2,rearwheelmass#*2,spheretex,wheelname$)
					;create_TOK_ball(segs,wheeldiameter#,cx#,cy#,cz#,angdampfront#,lindampfront#,mass#,Id#,imass#,spheretex,wheelname$)
					

					EntityColor obj(6),255,0,0 ; blue= 
					TOKRB_SetRotation(rb(toks),0,00,90)
					;TOKRB_SetTorque(rb(toks),5,0,0)
					joint3 = TOKJOINT_Create(2,rb(1),rb(6))
					TOKJOINT_SetType(joint3,3)
					TOKJOINT_SetPositionAndRotationWorld(joint3,cx#,cy#,cz#,0,0,90)
					TOKJOINT_Enable(joint3,True)
	

		Case 4 : cx# = carx#+(carwidth#) : cy# = cary#-(carheight#/2) : cz# = carz#-(carlength#/1.5) : wheelname$ = "rightrear" : inc = 4
					; obj 7
					create_TOK_CYL(segs,wheeldiameter#,wheelheight#,cx#,cy#,cz#,angdamprear#,lindamprear#,rearwheelmass#,Id#,ih#/2,rearwheelmass#*2,spheretex,wheelname$)
					;create_TOK_ball(segs,wheeldiameter#,cx#,cy#,cz#,angdampfront#,lindampfront#,mass#,Id#,imass#,spheretex,wheelname$)
					

					
					EntityColor obj(7),255,0,0 ; yellow= 
					TOKRB_SetRotation(rb(toks),0,00,90)
					;TOKRB_SetTorque(rb(toks),5,0,0)
					joint4 = TOKJOINT_Create(2,rb(1),rb(7))
					TOKJOINT_SetType(joint4,3)
					TOKJOINT_SetPositionAndRotationWorld(joint4,cx#,cy#,cz#,0,0,90)
					TOKJOINT_Enable(joint4,True)
	

	
	End Select
	
	

Next
	; ----------------------------------------------------------------------------------

For columns = 1 To 4
	For rows = 1 To 4
	
		create_TOK_BOX(4,4,4,(columns*4)+20,rows*4,16,0.001,0.001,1.5,4,4,4,2,cubetex,"car")
	Next
Next

; ----------------------------------------------------------------------------------




; add--------------------------------------------------------------------------

Centerpivot = CreatePivot()

light=CreateLight()
PositionEntity light,7,15,-5
PointEntity light,Centerpivot

rot#=0

period=800/FPS
time=MilliSecs()-period

imptime=MilliSecs()

camx#=Cos(rot#)*50
camz#=Sin(rot#)*50

;rot#=rot#+0.05

If rot#>360 Then rot#=0

PositionEntity campiv,camx#,40,camz#
PointEntity campiv,centerpivot  

FlushMouse 
; +++ MAIN LOOP START ++++++ MAIN LOOP START ++++++ MAIN LOOP START ++++++ MAIN LOOP START +++
.mainloop
While Not KeyHit(1)

	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.75/FPS,1)

move_camera()

	UpdateWorld

	Next

; Not sure wether to put this here or inside the for/next above...
For i=1 To TOKS
 If TOKRB_IsIdle(rb(i)) Then
  EntityAlpha obj(i),0.5
 Else
  EntityAlpha obj(i),1.0
  TOKRB_Active(rb(i),True)

 EndIf
 
 If EntityName(obj(i)) = "ball"
	; do stuff
 EndIf

 If EntityName(obj(i)) = "box"
	;If MouseDown(2) = 1 Then TOKRB_ApplyTwist(rb(i),0,150,0)
 EndIf


.carmovement
;accel# = 0.01
;force# = force# * .99

;TOKRB_ApplyImpulse rb(1),-(Sin(EntityYaw(obj(1)))*force#),-(Sin(EntityPitch(obj(1)))*force#),Cos(EntityYaw(obj(1)))*force#
;ok
;TOKRB_ApplyImpulse rb(2),-(Sin(EntityYaw(obj(1)))*force#),-(Sin(EntityPitch(obj(1)))*force#),Cos(EntityYaw(obj(1)))*force#
;TOKRB_ApplyImpulse rb(4),-(Sin(EntityYaw(obj(1)))*force#),-(Sin(EntityPitch(obj(1)))*force#),Cos(EntityYaw(obj(1)))*force#
;TOKRB_SetTorque rb(2),-(Cos(EntityYaw(obj(1)))*force#)/2,0,-(Sin(EntityYaw(obj(1)))*force#)/2
;TOKRB_ApplyTwist rb(3),-(Cos(EntityYaw(obj(1)))*force#)/2,0,-(Sin(EntityYaw(obj(1)))*force#)/2
;TOKRB_ApplyTwist rb(2),0,-(Sin(EntityYaw(obj(1)))*force#),0
carpitch# = EntityPitch(obj(1))
caryaw# = EntityYaw(obj(1))
carroll# = EntityRoll(obj(1))
caryaw_cos# = Cos(caryaw#)
caryaw_sin# = Sin(caryaw#)

	If KeyDown(200) = 1
								
				TOKRB_ApplyTwist(rb(6),caryaw_cos#*force#,0,caryaw_sin#*force#)
				TOKRB_ApplyTwist(rb(7),caryaw_cos#*force#,0,caryaw_sin#*force#)
				force# = 6
				;TOKRB_ApplyImpulse rb(1),-(Sin(EntityYaw(obj(1)))*force#),-(Sin(EntityPitch(obj(1)))*force#),Cos(EntityYaw(obj(1)))*force#
	EndIf

	If KeyDown(208) = 1
				TOKRB_SetAngularMomentum(rb(6),caryaw_cos#*force#,0,caryaw_sin#*force#)
				TOKRB_SetAngularMomentum(rb(7),caryaw_cos#*force#,0,caryaw_sin#*force#)
				force# = -4

	EndIf
	
		
	ncaryaw# = caryaw# + turn#
	
	If KeyDown(203) = 1
		turn# = turn# + 0.05
		If turn#>40 Then turn# = 40
		
	EndIf
	If KeyDown(205) = 1
		turn# = turn# - 0.05
		If turn#<-40 Then turn# = -40
	EndIf

	TOKRB_SetRotation(rb(2),carpitch#,ncaryaw#,carroll#)
	TOKRB_SetRotation(rb(4),carpitch#,ncaryaw#,carroll#)




	If MouseDown(2) = 1 Then place_rb(cubetex)

 PositionEntity obj(i),TOKRB_GetX#(rb(i)),TOKRB_GetY#(rb(i)),TOKRB_GetZ#(rb(i)) 
 RotateEntity obj(i),TOKRB_GetPitch#(rb(i)),TOKRB_GetYaw#(rb(i)),TOKRB_GetRoll#(rb(i)),False
Next

If MouseDown(1)=1 Then push_rigid_body()


RenderWorld tween
Color 255,255,255
Text 0,0,"Physics Time:"+TOKSIM_GetPhysicsTime()*1000.0+ " milliseconds"
Text 0,10,"Render Time:"+Str(elapsed)+ " milliseconds"
Text 0,20,"pnx"+pnx#+"  pny "+pny#+"  pnz  "+pnz# 
;Text 0,30,"Render Time:"+Str(elapsed)+ " milliseconds"
Text 0,40,"force: "+force#
;Text 0,50,"Render Time:"+Str(elapsed)+ " milliseconds"
Text 0,50,"camera X : "+EntityX(campiv)+"   Y : "+EntityY(campiv)+"  Z : "+EntityZ(campiv)

Color 255,0,0
Rect midw-4,midh-4,8,8,0
	Flip False

Wend

; == MAIN LOOP END ==== MAIN LOOP End ==== MAIN LOOP End ==== MAIN LOOP End ==== MAIN LOOP End ==


TOKSIM_DestroySimulator()

End

;==================================================================================
Function curvevalue#(newvalue#,oldvalue#,increments# )
	If increments>1 Then oldvalue#=oldvalue#-(oldvalue#-newvalue#)/increments
	If increments<=1 Then oldvalue=newvalue
	Return oldvalue#
End Function
;==================================================================================
Function move_camera()
	; Movement controls
	If KeyDown(w)=1 Then speed# = speed#+.03
	If KeyDown(a)=1 Then latspeed# = latspeed# - .02
	If KeyDown(s)=1 Then speed# = speed# -.03
	If KeyDown(d)=1 Then latspeed# = latspeed# + .02

latspeed#=latspeed#*.98
speed#=speed#*.98

MY#=curvevalue#(MouseYSpeed(),MY#,3 )
MX#=curvevalue#(MouseXSpeed(),MX#,3 )
TurnEntity campiv,MY#,-MX#,0 ; turn camera up and down
;TurnEntity campiv,0,-MX#,0 ;  turn nnn left --right
RotateEntity campiv,EntityPitch(campiv),EntityYaw(campiv),0
If EntityPitch(campiv)>88 Then RotateEntity campiv,88,EntityYaw(campiv),EntityRoll(campiv)
If EntityPitch(campiv)<-88 Then RotateEntity campiv,-88,EntityYaw(campiv),EntityRoll(campiv)

MoveMouse 100,100

MoveEntity campiv,latspeed#,0,speed#
	


End Function
;==================================================================================
Function create_cube_texture()
	tex = CreateTexture(64,64)
	ScaleTexture tex,.5,.5
	SetBuffer TextureBuffer(tex)
		Color 20,20,200
		Rect 0,0,64,64
		Color 255,255,255
		Rect 0,0,32,32
		Rect 32,32,64,64
		Color 0,0,0
		Rect 0,0,64,64,0
	SetBuffer BackBuffer()
	Return tex
	
End Function

Function create_world_texture()
	tex = CreateTexture(128,128)
	ScaleTexture tex,.25,.25
	SetBuffer TextureBuffer(tex)
		Color 100,100,100
		Rect 0,0,128,128
		Color 50,50,50
		Rect 0,0,64,64
		Rect 64,64,128,128
		Color 200,200,0
		Rect 0,0,128,128,0
		

	SetBuffer BackBuffer()
	Return tex
	
End Function

;==================================================================================
Function create_sphere_texture()
	tex = CreateTexture(128,128)
	SetBuffer TextureBuffer(tex)
		Color 0,200,0
		Rect 0,0,128,128
		Color 255,255,0
		Rect 0,0,64,64
		Rect 64,64,128,128
		Color 0,0,0
		Rect 0,0,64,64,0
		Color 0,0,0
		Rect 64,64,128,128,0
		Color 0,0,0
		Rect 0,0,128,128,0
	ScaleTexture tex,.5,.5


	SetBuffer BackBuffer()
	Return tex

	
End Function

;==================================================================================
Function create_cyl_texture()
	tex = CreateTexture(128,128)
	SetBuffer TextureBuffer(tex)
		Color 0,0,0
		Rect 0,0,128,128
		Color 255,0,0
		Rect 0,0,64,64
		Rect 64,64,128,128
	SetBuffer BackBuffer()
	Color 255,255,0 ; YELLOW
	Return tex

	
End Function

;==================================================================================
Function campick()
	pictentity = 0
	CameraPick(camera,midw,midh)
	pictentity = PickedEntity() 
	If Pictentity<>0
		
		;EntityAlpha pictentity,.7	
		pnx# = PickedNX#()
		pny# = PickedNY#()
		pnz# = PickedNZ#()	
		pcx# = PickedX#()
		pcy# = PickedY#()
		pcz# = PickedZ#()

	
	EndIf
	

End Function

Function create_TOK_BOX(xs#,ys#,zs#,xp#,yp#,zp#,damp#,angdamp#,mass#,iw#,ih#,id#,imass#,texture,name$)

			TOKS = TOKS+1
			If TOKS>ENTS 
				TOKS = ENTS
				Return
			EndIf
			obj(TOKS) = CreateCube()
			NameEntity obj(toks),name$
			ScaleEntity obj(TOKS),xs#/2,ys#/2,zs#/2
			EntityPickMode obj(TOKS),2
			EntityTexture obj(TOKS),texture
			rb(TOKS) = TOKRB_Create()
			TOKRB_SetSleepingParameter(rb(TOKS),-100)
			TOKRB_AddBox rb(TOKS),xs#,ys#,zs#
			TOKRB_SetPosition(rb(TOKS),xp#,yp#,zp#)
			TOKRB_SetLinearDamping rb(TOKS),damp#
			TOKRB_SetAngularDamping rb(TOKS),angdamp# 

			TOKRB_SetMass rb(TOKS),mass#
			TOKRB_SetBoxInertiaTensor rb(TOKS),iw#,ih#,id#,imass# 
			
			

End Function

Function create_TOK_BALL(segs,sc#,xp#,yp#,zp#,angdamp#,lindamp#,mass#,IT1#,IT2#,texture,name$)
			  TOKS = TOKS+1
			  
				If TOKS>ENTS 
					TOKS = ENTS
					Return
				EndIf
	
			
				obj(TOKS) = CreateSphere(segs)
				NameEntity obj(toks),name$

			  ScaleEntity obj(TOKS),sc#/2,sc#/2,sc#/2
			  EntityPickMode obj(TOKS),2

			  EntityTexture obj(TOKS),texture
			  rb(TOKS) = TOKRB_Create()
			  TOKRB_AddSphere rb(TOKS),sc#
			  TOKRB_SetPosition(rb(TOKS),xp#,yp#,zp#)
			  TOKRB_SetAngularDamping rb(TOKS),angdamp# 
			  TOKRB_SetLinearDamping rb(TOKS),lindamp#
			  TOKRB_SetMass rb(TOKS),mass#
			  TOKRB_SetSphereInertiaTensor rb(TOKS),IT1#,IT2#  
End Function



Function create_TOK_CYL(segs,diameter#,height#,xp#,yp#,zp#,angdamp#,lindamp#,mass#,Id#,Ih#,Imass#,texture,name$)

			TOKS = TOKS+1
			  
				If TOKS>ENTS 
					TOKS = ENTS
					Return
				EndIf
			
			obj(TOKS) = CreateCylinder(segs)
 				EntityPickMode obj(TOKS),2
  			 EntityTexture obj(TOKS),texture
			  rb(TOKS) = TOKRB_Create()
			  TOKRB_AddCylinder rb(TOKS),diameter#,height#
			  ScaleEntity obj(TOKS),diameter#/1.95,height#,diameter#/1.95
			  TOKRB_SetPosition(rb(TOKS),xp#,yp#,zp#)
			  TOKRB_SetAngularDamping rb(TOKS),angdamp# 
			  TOKRB_SetLinearDamping rb(TOKS),lindamp#
			  TOKRB_SetMass rb(TOKS),mass#
			  TOKRB_SetCylinderInertiaTensor rb(TOKS),Id#,Ih#,Imass# 
			  TOKRB_Active(rb(toks),True)
			;TOKRB_CollideConnected(rb(toks),True)
End Function
;==================================================================================

Function place_rb(tex)
	
		campick()
		If pictentity>0
			PositionEntity pickmarker,pcx#,pcy#,pcz#
			;create_TOK_BOX(xs#,ys#,zs#,xp#,yp#,zp#,damp#,angdamp#,mass#,iw#,ih#,id#,imass#,texture,name$)
	
			create_TOK_BOX(4,4,4,pcx#,pcy#+2,pcz#,0.001,0.002,2,4,4,4,2,tex,"foo")
			Repeat : Until MouseDown(2) = 0
			
	 	EndIf
	FlushMouse()
End Function
		
;==================================================================================



;==================================================================================

Function push_rigid_body()
	
		campick()
	 	For n = 1 To TOKS
			If pictentity = obj(n)
				i = n
				
				If KeyDown(29) Or KeyDown(157)
				
					TOKRB_ApplyImpulse2 rb(i),-pnx#*15,-pny#*15,-pnz#*15,pcx#,pcy#,pcz# 
				Else
					TOKRB_ApplyImpulse2 rb(i),-pnx#,-pny#,-pnz#,pcx#,pcy#,pcz# 				;TOKRB_ApplyImpulse rb(i),-pnx#,pny#,-pnz#
				EndIf
			EndIf
		Next		
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,0
   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