Tokamak precision lack?

Blitz3D Forums/Blitz3D Userlibs/Tokamak precision lack?

Uncle Ho(Posted 2006) [#1]
hi there,

i am experimenting with tokamak for some time now. up to now everything worked just fine but now i am experiencing some strange things.

i made up a little example (most of the code is not mine) with a ball-joint swinging. on all computers i tested it so far the ball-joint does not stop movement at angle 0, 0, 0 but on some angle of 1.5, 0, -0.3 or so.
it sometimes even stopps movement when the ball is not even close to the center which looks pretty unrealistic.

does anyone have a clue?

Graphics3D 800, 600, 0, 2
SeedRnd MilliSecs()

; -> Cam & Light
camera = CreateCamera( )
PositionEntity camera, 0, 20, -35
light = CreateLight( 2 )

; -> Global Vars
Global elapsed, ticks
Global period = 1000 / 60
Global time = MilliSecs() - period

; -> Tokamak Init
Const Rigid_Bodies 		= 200
Const Animated_Bodies 	= 7
TOKSIM_SetRigidBodiesCount Rigid_Bodies
TOKSIM_SetAnimatedBodiesCount Animated_Bodies
TOKSIM_SetRigidParticleCount 0
TOKSIM_SetControllersCount 0
TOKSIM_SetGeometriesCount Rigid_Bodies + Animated_Bodies
TOKSIM_CreateSimulator( 0, -10, 0 )

; -> Ball & Chain
gBall = CreateSphere(12, gBall)
EntityColor gBall, 228, 228, 228
EntityShininess gBall, 1
gChain = CreateCylinder(8, 1, gBall)
PositionEntity gChain, 0, 14, 0
ScaleEntity gChain, .2, 14, .2
gLink = CreateCylinder(8, 1, gBall)
ScaleEntity gLink, .4, .2, .4
PositionEntity gLink, 0, 1, 0
EntityColor gLink, 128, 255, 0

gBall_RB = TOKRB_Create()
TOKRB_AddSphere gBall_RB, 2
TOKRB_SetPosition gBall_RB, 0, 5, 0
TOKRB_SetVelocity gBall_RB, Rand(1, 10), Rand(1, 10), Rand(1, 10)
TOKRB_SetMass gBall_RB, 150
TOKRB_SetSphereInertiaTensor gBall_RB,1, 150
TOKRB_UpdateBoundingInfo gBall_RB
TOKRB_SetAngularDamping gBall_RB, .01
TOKRB_SetLinearDamping gBall_RB, .01
TOKRB_SetCollisionID gBall_RB, 1
AlignToVector gBall, -x#, 0, -z#, 2
TOKRB_SetRotation gBall_RB, EntityPitch(gBall), EntityYaw(gBall), EntityRoll(gBall)
gBallJoint = TOKJOINT_Create(1, gBall_RB, 0)
TOKJOINT_SetPositionAndRotationWorld(gBallJoint, 0.0, 35.0, 0.0, 0, 0, 0)
TOKJOINT_SetType(gBallJoint, 1)
TOKJOINT_Enable(gBallJoint, True)
TOKJOINT_SetDampingFactor gBallJoint, 1.0

; -> Additional Meshes
shadow = CreateCylinder(16, 1)
ScaleEntity shadow, 1, 0.1, 1
PositionEntity shadow, 0, 0, 0
EntityColor shadow, 0, 0, 0
EntityAlpha shadow, 0.5

bullseye = CreateCylinder(16, 1)
ScaleEntity bullseye, 1.5, 0.01, 1.5
PositionEntity bullseye, 0, 0.05, 0
EntityColor bullseye, 255, 0, 0
EntityFX bullseye, 1

target = CreateCylinder(16, 1)
ScaleEntity target, 4, 0.01, 4
PositionEntity target, 0, 0.03, 0
EntityColor target, 255, 255, 0
EntityFX target, 1

ground = CreatePlane( )
EntityColor ground, 0, 200, 50


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 CaptureWorld
		
		If KeyHit(57) TOKRB_SetVelocity gBall_RB, Rand(1, 10), Rand(1, 10), Rand(1, 10)
		
		TOKSIM_Advance( 0.1, 1 )
	 
		PositionEntity gBall, TOKRB_GetX#(gBall_RB),TOKRB_GetY#(gBall_RB),TOKRB_GetZ#(gBall_RB)
		RotateEntity gBall, TOKRB_GetPitch#(gBall_RB),TOKRB_GetYaw#(gBall_RB),TOKRB_GetRoll#(gBall_RB),False
		
		PositionEntity shadow, TOKRB_GetX#(gBall_RB), 0.1 ,TOKRB_GetZ#(gBall_RB)	
	Next
	
	UpdateWorld( )
	RenderWorld( tween# )
	
	Text 10, 10, "PhysicsTime: " + TOKSIM_GetPhysicsTime()
	Text 10, 30, "APitch: " + TOKJOINT_GetFrameAPitch( gBallJoint )
	Text 10, 40, "AYaw: " + TOKJOINT_GetFrameAYaw( gBallJoint )
	Text 10, 50, "ARoll: " + TOKJOINT_GetFrameARoll( gBallJoint )
	
	Flip False
	
Wend

TOKSIM_DestroySimulator()
End



Damien Sturdy(Posted 2006) [#2]
From memory, there are commands to set just *how* slow an object is moving for it to become disabled. Find this command and disable it or set the values really low. That should sort your issue.


Uncle Ho(Posted 2006) [#3]
thx Cygnus, that's it :D

when i add:

TOKRB_SetSleepingParameter gBall_RB, 0.01


it works perfectly. of course you have to take care about performance to not set every RB SleepingParameter low i would guess.


Damien Sturdy(Posted 2006) [#4]
yeah, you gotta get it *just* right :-)

It'd be useful if the AutoDisable function took into account the amount of force still being applied, minus gravity.