The future of Tokamak

Blitz3D Forums/Blitz3D Userlibs/The future of Tokamak

THEY DID IT, THEY DID IT :)

Sweenie I love you and I love your wrapper :)

Do you remember some time ago I had a code where a box
was simply going through everything and jumping at
the edges...
This is the same code and if you run it with the new 1.21
it works really better, there is just a minor problem to
stop the box from moving but there is NO more going through
geometry and no more crazy jumping :)

Thanks again for the great wrapper !!!

Graphics3D 640,480,16,2

Const FPS=60

AmbientLight 50,50,50

l=CreateLight(2)
	PositionEntity l,-5,5,-5
	LightRange l,15

cam=CreateCamera()
	PositionEntity cam,0,3,-8

;TOKA
TOKSIM_CreateSimulator(0,-10,0)


;Anim bodie:
ab_vis=CreateMesh()

ab=TOKAB_Create()
	geo=TOKAB_AddBox(ab,10,.5,10)
	vis=CreateCube():ScaleMesh vis,5,.25,5:AddMesh vis,ab_vis:FreeEntity vis

	TOKAB_UpdateBoundingInfo ab

ab=TOKAB_Create()
	geo=TOKAB_AddBox(ab,2,6,10)
		TOKGEOM_SetPositionAndRotation geo,2,3,0,0,0,0
	vis=CreateCube():ScaleMesh vis,1,3,5:PositionMesh vis,2,3,0:AddMesh vis,ab_vis:FreeEntity vis

	TOKAB_UpdateBoundingInfo ab

ab=TOKAB_Create()
	geo=TOKAB_AddBox(ab,2,2,10)
		TOKGEOM_SetPositionAndRotation geo,-2,1,0,0,0,0
	vis=CreateCube():ScaleMesh vis,1,1,5:PositionMesh vis,-2,1,0:AddMesh vis,ab_vis:FreeEntity vis

	TOKAB_UpdateBoundingInfo ab

;Rigid bodie:
rb_vis=CreateCube()
	ScaleMesh rb_vis,1.5,1,1.5
	EntityColor rb_vis,255,0,0

rb=TOKRB_Create()
	TOKRB_AddBox rb,3,2,3
	TOKRB_SetPosition rb,-.75,4,0

	TOKRB_SetLinearDamping rb,.002
	TOKRB_SetAngularDamping rb,.01

	TOKRB_SetMass rb,5
	TOKRB_SetBoxInertiaTensor rb,3,2,3,5

	TOKRB_UpdateBoundingInfo rb

;_------------------------------	



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

While Not KeyDown(1)

	;------ FPS Counter ----------
	fps_count=fps_count+1:fps_timer=fps_timer+(MilliSecs()-fps_millis):fps_millis=MilliSecs()
	If fps_timer>1000:fps_timer=0:fpsc=fps_count:fps_count=0:EndIf
	;---------------------------------------

	Repeat
		elapsed=MilliSecs()-time
	Until elapsed
	;how many 'frames' have elapsed	
	ticks=elapsed/period
	;fractional remainder
	tween#=Float(elapsed Mod period)/Float(period)

	For k=1 To ticks
		time=time+period
		If k=ticks Then CaptureWorld


		If KeyHit(57)
		TOKRB_SetPosition rb,-.75,4,0
		TOKRB_SetRotation rb,0,0,0
		EndIf

		If KeyHit(17) w=Not w WireFrame w


		If KeyDown(200) MoveEntity cam,0,0,.1
		If KeyDown(208) MoveEntity cam,0,0,-.1
		If KeyDown(203) MoveEntity cam,-.1,0,0
		If KeyDown(205) MoveEntity cam,.1,0,0
		TurnEntity cam,MouseYSpeed()/12.0,-MouseXSpeed()/12.0,0
		RotateEntity cam,EntityPitch(cam),EntityYaw(cam),0
		MoveMouse GraphicsWidth()/2,GraphicsHeight()/2
	

		TOKSIM_Advance(1.5/FPS,3)
	
		UpdateWorld


		PositionEntity rb_vis,TOKRB_GetX(rb),TOKRB_GetY(rb),TOKRB_GetZ(rb)
		RotateEntity rb_vis,TOKRB_GetPitch(rb),TOKRB_GetYaw(rb),TOKRB_GetRoll(rb)
	Next
	

	RenderWorld tween
	
	Text 20,20,"Hit Space to reset"
	Text 20,35,"W to wireframe"
	
	Text 10,50,"FPS: "+fpsc
	Flip
Wend

TOKSIM_DestroySimulator()

MoveMouse 400,300:End

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


Paolo.