EasyTOK question

Blitz3D Forums/Blitz3D Userlibs/EasyTOK question

Hi, I recently purchased easyTOK, and it's working fine, except i have a few questions on some bugs i'm getting, and how to fix them. In the below code, it will boot up fine, and work well, HOWEVER:
1: if you launch the program with refresh = true, the wall will mostly fall over, in contrast to if you launch the program with refresh = false, then press space to make refresh = true, the wall has no problems.

ALSO

2: if you right click (call the function BuildWall, aka, rebuild the wall) while refresh = true, you get some strange anomolies (most of the wall falls right through the floor).

check out this code and please tell me if you find any problems with it!

;FIRST EASYTOK PROGRAM
;WASD TO MOVE
;MOUSE TO TURN
;LEFT CLICK TO SHOOT
;RIGHT CLICK TO REBUILD THE WALL
;SPACE TO TURN ON/OFF PHYSICS REFRESH
;ENTER TO TURN ON/OFF SLOW MOTION


SeedRnd MilliSecs()
Graphics3D 1024, 768, 32, 1
Global slomo = False 
Global refresh = False

Global frametime1, frametime2, FPS


TOK_InitWorld( 0, -40, 0, 5000, 1000)
TOK_CreateGround( "Floor",  30, 255, 150, 0)


Include "Include\Inc_TimeMachine.bb"
Include "Include\Inc_EasyTOK.bb"
  
Global camera = CreateCamera()

PositionEntity camera, 0, 15, -10
light = CreateLight()
PositionEntity light, 0, 10, 0

BuildWall()


While Not KeyHit(1)
	frametime1 = MilliSecs()
	TOK_RefreshEasyTOK()
	If refresh = True Then 
		If slomo = False Then 
			If FPS > 0 Then TOK_RefreshPhysic(1.7/FPS,10)
		Else
			If FPS > 0 Then TOK_RefreshPhysic(0.1/FPS,10)
		EndIf 
	EndIf 
	Receive_Input()
	RenderWorld
	
	Text 0, 0, "Refreshing Physics = " + refresh
	Text 0, 20, "Slow Motion = " + slomo
	
	frametime2 = MilliSecs()
	If (frametime2-frametime1) <> 0 Then FPS = 1000/(frametime2-frametime1)
	Text 0, 40, FPS + " FPS"
	
	Flip()

Wend

TOK_FreePhysic()
End

Function BuildWall()
	TOK_DeleteRBEntity( "Cube" )
	For x = -10 To 10
		For y = 1.5 To 10
			TOK_CreateRBCube( "Cube", False, x * 2, y * 2, 0, 0, 0, 0, 1, 1, 1, 5, "", Rnd(0, 255), Rnd(0, 255), Rnd(0, 255), 1, 0)
		Next
	Next
	

End Function 

Function Receive_Input()
	TurnEntity camera, MouseYSpeed(), -1*MouseXSpeed(), 0
	MoveMouse 840, 525
	If KeyDown(17) Then MoveEntity camera, 0, 0, 1
	If KeyDown(31) Then MoveEntity camera, 0, 0, -1
	If KeyDown(30) Then MoveEntity camera, -1, 0, 0
	If KeyDown(32) Then MoveEntity camera, 1, 0, 0
	
	If MouseHit(1) Then
		Tmp$ = "bullet" + Rnd(0, 1000)
		TOK_CreateRBSphere( Tmp$, False, EntityX(camera), EntityY(camera), EntityZ(camera), 90, 0, 0, 1, 5, "", 0, 0, 0, 1, 0)
		TOK_ApplyImpulseWithAngle( Tmp$, EntityPitch(camera), EntityYaw(camera), 2000)
	EndIf
	
	If KeyHit(57) Then
		If refresh = True Then 
			refresh = False
		Else 
			refresh = True
		EndIf 	
	EndIf
	
	If KeyHit(28) Then
		If slomo = False Then
			slomo = True
		Else
			slomo = False 
		EndIf
	EndIf
	
	If MouseHit(2) Then buildwall()  
End Function


anybody?

I can't answer you but i have a question for you :)
Where can i find easytok demo just to try?
I really don't know what choose for physics!

Aza

you can't try it, but you can see the samples at this place

This is a guess but perhaps those few calls that occur to the TOK_RefreshEasyTOK() function when refresh=false would be enough for any interpenetrations to be eliminated, allowing the objects in the wall to settle before the user activates the simulation.

Starting with refresh=true means only 1 call to that function before the physics sim is updated, may be resulting in inter-penetrating bodies moving apart causing the wall to fall over.

Try adding a few calls to that function before the mainloop, or perhaps adjust the spacing on your wall blocks to see if that helps.

This is a complete guess as I don't know what the TOK_RefreshEasyTOK() actually does with regards to the physics.

if that was the problem it would have occured earlier, but it didn't start occuring until recently. Your post gave me an idea though, so i'll check it out.

i fixed half the problem, the drop in FPS due to the rebuilding the wall caused errors in the speed parameter of TOK_RefreshPhysic, and the developer of easytok said that high speeds can cause errors (if you refresh at a speed of 1.7, it gives similar (but worse) errors, so the line TOK_RefreshPhysic(1.7/FPS,10) caused a high speed when with a low FPS. I found a work around, now i need to FIX it...

the same bug was causing the weird thing here:

1: if you launch the program with refresh = true, the wall will mostly fall over, in contrast to if you launch the program with refresh = false, then press space to make refresh = true, the wall has no problems.


as said before, caused by the low FPS at launch

i got the solution, just make your accuracy dependent on FPS along with your speed. I used

If FPS > 0 Then TOK_RefreshPhysic(1.7/FPS,0.17*FPS)

so that if the speed goes down, TOK doesn't even refresh. Only time will tell if this solution works.