You gotta check this out, I was testing the Joint types (I know we aint got proper axle type joints 'yet') but anyways, I created a galloping box LOL!
Just hold space down
[code]
; Joint tests, trying to simulate vehicle axles
;
; I got a galloping car instead hehe
;
; Scouse
Const FPS=50
Graphics3D 800,600,0,2
SetBuffer BackBuffer()
WireFrame False
Const ENTS=5
camera = CreateCamera()
PositionEntity camera,-5,8,-10
TOKSIM_CreateSimulator(ENTS,5,0,-10,0)
ground = CreateCube()
EntityColor ground,5,5,55
ScaleEntity ground,50,5,50
PositionEntity ground,0,-5,0
abground = TOKAB_Create()
TOKAB_AddBox(abground,100.0,10.0,100.0)
TOKAB_SetPosition(abground,0.0,-5.0,0.0)
wall1 = CreateCube()
EntityColor wall1,25,25,55
ScaleEntity wall1,2,10,50
PositionEntity wall1,50,0,0
abwall1 = TOKAB_Create()
TOKAB_AddBox(abwall1,4.0,20.0,100.0)
TOKAB_SetPosition(abwall1,50.0,0,0.0)
wall2 = CreateCube()
EntityColor wall2,25,25,55
ScaleEntity wall2,2,10,50
PositionEntity wall2,-50,0,0
abwall2 = TOKAB_Create()
TOKAB_AddBox(abwall2,4.0,20.0,100.0)
TOKAB_SetPosition(abwall2,-50.0,0,0.0)
wall3 = CreateCube()
EntityColor wall3,25,25,55
ScaleEntity wall3,50,10,2
PositionEntity wall3,0,0,-50
abwall3 = TOKAB_Create()
TOKAB_AddBox(abwall3,100.0,20.0,4.0)
TOKAB_SetPosition(abwall3,0.0,0,-50.0)
wall4 = CreateCube()
EntityColor wall4,25,25,55
ScaleEntity wall4,50,10,2
PositionEntity wall4,0,0,50
abwall4 = TOKAB_Create()
TOKAB_AddBox(abwall4,100.0,20.0,4.0)
TOKAB_SetPosition(abwall4,0.0,0,50.0)
Dim obj(ENTS)
Dim rb(ENTS)
obj(1) = CreateCube()
ScaleEntity obj(1),.5,.5,1
rb(1) = TOKRB_Create()
TOKRB_AddBox rb(1),1.0,1.0,2.0
;TOKRB_CollideConnected rb(1),True
TOKRB_SetPosition rb(1),0,2,0
PositionEntity obj(1),0,2,0
TOKRB_SetLinearDamping rb(1),0.001
TOKRB_SetAngularDamping rb(1),0.001
TOKRB_SetMass rb(1),2.0
TOKRB_SetBoxInertiaTensor rb(i),1,1,2,2.0
obj(2) = CreateSphere()
ScaleEntity obj(2),.5,.5,.5
rb(2) = TOKRB_Create()
;TOKRB_CollideConnected rb(2),True
TOKRB_AddSphere rb(2),1
TOKRB_SetPosition rb(2),-1,1.5,0.7
PositionEntity obj(2),-1,1.5,0.7
TOKRB_SetAngularDamping rb(2),0.02
TOKRB_SetLinearDamping rb(2),0.001
TOKRB_SetMass rb(2),0.5
TOKRB_SetSphereInertiaTensor rb(2),1,1
obj(3) = CreateSphere()
ScaleEntity obj(3),.5,.5,.5
rb(3) = TOKRB_Create()
;TOKRB_CollideConnected rb(3),True
TOKRB_AddSphere rb(3),1
TOKRB_SetPosition rb(3),1,1.5,0.7
PositionEntity obj(3),1,1.5,0.7
TOKRB_SetAngularDamping rb(3),0.02
TOKRB_SetLinearDamping rb(3),0.001
TOKRB_SetMass rb(3),0.5
TOKRB_SetSphereInertiaTensor rb(3),1,1
obj(4) = CreateSphere()
ScaleEntity obj(4),.5,.5,.5
rb(4) = TOKRB_Create()
;TOKRB_CollideConnected rb(5),True
TOKRB_AddSphere rb(4),1
TOKRB_SetPosition rb(4),-1,1.5,-.7
PositionEntity obj(4),-1,1.5,-.7
TOKRB_SetAngularDamping rb(4),0.02
TOKRB_SetLinearDamping rb(4),0.001
TOKRB_SetMass rb(4),0.5
TOKRB_SetSphereInertiaTensor rb(4),1,1
obj(5) = CreateSphere()
ScaleEntity obj(5),.5,.5,.5
rb(5) = TOKRB_Create()
;TOKRB_CollideConnected rb(5),True
TOKRB_AddSphere rb(5),1
TOKRB_SetPosition rb(5),1,1.5,-.7
PositionEntity obj(5),1,1.5,-.7
TOKRB_SetAngularDamping rb(5),0.02
TOKRB_SetLinearDamping rb(5),0.001
TOKRB_SetMass rb(5),0.5
TOKRB_SetSphereInertiaTensor rb(5),1,1
;obj(i) = CreateCylinder()
;rb(i) = TOKRB_Create()
;TOKRB_AddCylinder rb(i),2.0,1.0
;TOKRB_SetPosition(rb(i),x#,2+i*0.2,z#)
;TOKRB_SetAngularDamping rb(i),0.02
;TOKRB_SetLinearDamping rb(i),0.001
;TOKRB_SetMass rb(i),2.0
;TOKRB_SetCylinderInertiaTensor rb(i),2.0,1.0,2.0
;EntityColor obj(i),Rnd(100,230),Rnd(100,230),Rnd(100,230)
axletype=1
axle1=TOKJOINT_Create (2,rb(1),rb(2))
TOKJOINT_SetPositionWorld axle1,-.5,1.5,.7
TOKJOINT_SetType axle1,axletype
TOKJOINT_Enable axle1,True
axle2=TOKJOINT_Create (2,rb(1),rb(3))
TOKJOINT_SetPositionWorld axle2,.5,1.5,.7
TOKJOINT_SetType axle2,axletype
TOKJOINT_Enable axle2,True
axle3=TOKJOINT_Create (2,rb(1),rb(4))
TOKJOINT_SetPositionWorld axle3,-.5,1.5,-.7
TOKJOINT_SetType axle3,axletype
TOKJOINT_Enable axle3,True
axle4=TOKJOINT_Create (2,rb(1),rb(5))
TOKJOINT_SetPositionWorld axle4,.5,1.5,-.7
TOKJOINT_SetType axle4,axletype
TOKJOINT_Enable axle4,True
Centerpivot = CreatePivot()
light=CreateLight()
PositionEntity light,7,15,-5
PointEntity light,Centerpivot
rot#=0
period=1000/FPS
time=MilliSecs()-period
imptime=MilliSecs()
; 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.0/FPS)
If rot#>360 Then rot#=0
;PositionEntity camera,camx#,40,camz#
PointEntity camera,centerpivot
UpdateWorld
Next
; Not sure wether to put this here or inside the for/next above...
For i=1 To 5
If TOKRB_IsIdle(rb(i)) Then
EntityAlpha obj(i),0.5
Else
EntityAlpha obj(i),1.0
EndIf
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 KeyDown(57) Then
; i=Rnd(1,ENTS)
; TOKRB_ApplyImpulse rb(i),Rnd(-3.0,3.0),Rnd(15,30),Rnd(-3.0,3.0)
; TOKRB_ApplyImpulse2 rb(i),0,30,0,TOKRB_GetX#(rb(i))+0.5,TOKRB_GetY#(rb(i))-0.5,TOKRB_GetZ#(rb(i))+0.5
TOKRB_ApplyTwist rb(2),1,0,0
TOKRB_ApplyTwist rb(3),1,0,0
TOKRB_ApplyTwist rb(4),1,0,0
TOKRB_ApplyTwist rb(5),1,0,0
; TOKRB_SetForce rb(i),0,0,-10
; TOKRB_SetForce2 rb(i),0,0,-10,TOKRB_GetX#(rb(i))+0.5,TOKRB_GetY#(rb(i))-1.5,TOKRB_GetZ#(rb(i))+0.5
; For i=1 To ENTS
;TOKRB_SetTorque rb(i),0,60,0
; Next
EndIf
RenderWorld tween
Text 0,0,"Physics Time:"+TOKSIM_GetPhysicsTime()*1000.0+ " milliseconds"
Text 0,10,"Render Time:"+Str(elapsed)+ " milliseconds"
Flip False
Wend
TOKSIM_DestroySimulator()
End
[/CODE]
Have fun!
Tom
Just hold space down
[code]
; Joint tests, trying to simulate vehicle axles
;
; I got a galloping car instead hehe
;
; Scouse
Const FPS=50
Graphics3D 800,600,0,2
SetBuffer BackBuffer()
WireFrame False
Const ENTS=5
camera = CreateCamera()
PositionEntity camera,-5,8,-10
TOKSIM_CreateSimulator(ENTS,5,0,-10,0)
ground = CreateCube()
EntityColor ground,5,5,55
ScaleEntity ground,50,5,50
PositionEntity ground,0,-5,0
abground = TOKAB_Create()
TOKAB_AddBox(abground,100.0,10.0,100.0)
TOKAB_SetPosition(abground,0.0,-5.0,0.0)
wall1 = CreateCube()
EntityColor wall1,25,25,55
ScaleEntity wall1,2,10,50
PositionEntity wall1,50,0,0
abwall1 = TOKAB_Create()
TOKAB_AddBox(abwall1,4.0,20.0,100.0)
TOKAB_SetPosition(abwall1,50.0,0,0.0)
wall2 = CreateCube()
EntityColor wall2,25,25,55
ScaleEntity wall2,2,10,50
PositionEntity wall2,-50,0,0
abwall2 = TOKAB_Create()
TOKAB_AddBox(abwall2,4.0,20.0,100.0)
TOKAB_SetPosition(abwall2,-50.0,0,0.0)
wall3 = CreateCube()
EntityColor wall3,25,25,55
ScaleEntity wall3,50,10,2
PositionEntity wall3,0,0,-50
abwall3 = TOKAB_Create()
TOKAB_AddBox(abwall3,100.0,20.0,4.0)
TOKAB_SetPosition(abwall3,0.0,0,-50.0)
wall4 = CreateCube()
EntityColor wall4,25,25,55
ScaleEntity wall4,50,10,2
PositionEntity wall4,0,0,50
abwall4 = TOKAB_Create()
TOKAB_AddBox(abwall4,100.0,20.0,4.0)
TOKAB_SetPosition(abwall4,0.0,0,50.0)
Dim obj(ENTS)
Dim rb(ENTS)
obj(1) = CreateCube()
ScaleEntity obj(1),.5,.5,1
rb(1) = TOKRB_Create()
TOKRB_AddBox rb(1),1.0,1.0,2.0
;TOKRB_CollideConnected rb(1),True
TOKRB_SetPosition rb(1),0,2,0
PositionEntity obj(1),0,2,0
TOKRB_SetLinearDamping rb(1),0.001
TOKRB_SetAngularDamping rb(1),0.001
TOKRB_SetMass rb(1),2.0
TOKRB_SetBoxInertiaTensor rb(i),1,1,2,2.0
obj(2) = CreateSphere()
ScaleEntity obj(2),.5,.5,.5
rb(2) = TOKRB_Create()
;TOKRB_CollideConnected rb(2),True
TOKRB_AddSphere rb(2),1
TOKRB_SetPosition rb(2),-1,1.5,0.7
PositionEntity obj(2),-1,1.5,0.7
TOKRB_SetAngularDamping rb(2),0.02
TOKRB_SetLinearDamping rb(2),0.001
TOKRB_SetMass rb(2),0.5
TOKRB_SetSphereInertiaTensor rb(2),1,1
obj(3) = CreateSphere()
ScaleEntity obj(3),.5,.5,.5
rb(3) = TOKRB_Create()
;TOKRB_CollideConnected rb(3),True
TOKRB_AddSphere rb(3),1
TOKRB_SetPosition rb(3),1,1.5,0.7
PositionEntity obj(3),1,1.5,0.7
TOKRB_SetAngularDamping rb(3),0.02
TOKRB_SetLinearDamping rb(3),0.001
TOKRB_SetMass rb(3),0.5
TOKRB_SetSphereInertiaTensor rb(3),1,1
obj(4) = CreateSphere()
ScaleEntity obj(4),.5,.5,.5
rb(4) = TOKRB_Create()
;TOKRB_CollideConnected rb(5),True
TOKRB_AddSphere rb(4),1
TOKRB_SetPosition rb(4),-1,1.5,-.7
PositionEntity obj(4),-1,1.5,-.7
TOKRB_SetAngularDamping rb(4),0.02
TOKRB_SetLinearDamping rb(4),0.001
TOKRB_SetMass rb(4),0.5
TOKRB_SetSphereInertiaTensor rb(4),1,1
obj(5) = CreateSphere()
ScaleEntity obj(5),.5,.5,.5
rb(5) = TOKRB_Create()
;TOKRB_CollideConnected rb(5),True
TOKRB_AddSphere rb(5),1
TOKRB_SetPosition rb(5),1,1.5,-.7
PositionEntity obj(5),1,1.5,-.7
TOKRB_SetAngularDamping rb(5),0.02
TOKRB_SetLinearDamping rb(5),0.001
TOKRB_SetMass rb(5),0.5
TOKRB_SetSphereInertiaTensor rb(5),1,1
;obj(i) = CreateCylinder()
;rb(i) = TOKRB_Create()
;TOKRB_AddCylinder rb(i),2.0,1.0
;TOKRB_SetPosition(rb(i),x#,2+i*0.2,z#)
;TOKRB_SetAngularDamping rb(i),0.02
;TOKRB_SetLinearDamping rb(i),0.001
;TOKRB_SetMass rb(i),2.0
;TOKRB_SetCylinderInertiaTensor rb(i),2.0,1.0,2.0
;EntityColor obj(i),Rnd(100,230),Rnd(100,230),Rnd(100,230)
axletype=1
axle1=TOKJOINT_Create (2,rb(1),rb(2))
TOKJOINT_SetPositionWorld axle1,-.5,1.5,.7
TOKJOINT_SetType axle1,axletype
TOKJOINT_Enable axle1,True
axle2=TOKJOINT_Create (2,rb(1),rb(3))
TOKJOINT_SetPositionWorld axle2,.5,1.5,.7
TOKJOINT_SetType axle2,axletype
TOKJOINT_Enable axle2,True
axle3=TOKJOINT_Create (2,rb(1),rb(4))
TOKJOINT_SetPositionWorld axle3,-.5,1.5,-.7
TOKJOINT_SetType axle3,axletype
TOKJOINT_Enable axle3,True
axle4=TOKJOINT_Create (2,rb(1),rb(5))
TOKJOINT_SetPositionWorld axle4,.5,1.5,-.7
TOKJOINT_SetType axle4,axletype
TOKJOINT_Enable axle4,True
Centerpivot = CreatePivot()
light=CreateLight()
PositionEntity light,7,15,-5
PointEntity light,Centerpivot
rot#=0
period=1000/FPS
time=MilliSecs()-period
imptime=MilliSecs()
; 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.0/FPS)
If rot#>360 Then rot#=0
;PositionEntity camera,camx#,40,camz#
PointEntity camera,centerpivot
UpdateWorld
Next
; Not sure wether to put this here or inside the for/next above...
For i=1 To 5
If TOKRB_IsIdle(rb(i)) Then
EntityAlpha obj(i),0.5
Else
EntityAlpha obj(i),1.0
EndIf
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 KeyDown(57) Then
; i=Rnd(1,ENTS)
; TOKRB_ApplyImpulse rb(i),Rnd(-3.0,3.0),Rnd(15,30),Rnd(-3.0,3.0)
; TOKRB_ApplyImpulse2 rb(i),0,30,0,TOKRB_GetX#(rb(i))+0.5,TOKRB_GetY#(rb(i))-0.5,TOKRB_GetZ#(rb(i))+0.5
TOKRB_ApplyTwist rb(2),1,0,0
TOKRB_ApplyTwist rb(3),1,0,0
TOKRB_ApplyTwist rb(4),1,0,0
TOKRB_ApplyTwist rb(5),1,0,0
; TOKRB_SetForce rb(i),0,0,-10
; TOKRB_SetForce2 rb(i),0,0,-10,TOKRB_GetX#(rb(i))+0.5,TOKRB_GetY#(rb(i))-1.5,TOKRB_GetZ#(rb(i))+0.5
; For i=1 To ENTS
;TOKRB_SetTorque rb(i),0,60,0
; Next
EndIf
RenderWorld tween
Text 0,0,"Physics Time:"+TOKSIM_GetPhysicsTime()*1000.0+ " milliseconds"
Text 0,10,"Render Time:"+Str(elapsed)+ " milliseconds"
Flip False
Wend
TOKSIM_DestroySimulator()
End
[/CODE]
Have fun!
Tom