|
Post by Constantine on Jul 15, 2004 0:19:14 GMT
Hi there. I've made this Rope Demo , please feel free to drop any comments so I can make it better. (code start) Const FPS=60 ;========================= Const number = 40 ;Number of rope points Const Ydistance = 3 ;This also defines the resolution of the rope. \\ Adjust the height of the mesh and RidigBody scale manually if you change it. ;========================= Graphics3D 800,600,0,2 SetBuffer BackBuffer() WireFrame False camera = CreateCamera() PositionEntity camera,0,2,-150 CameraClsColor camera,82,134,172 light=CreateLight() PositionEntity light,7,15,-5 TOKSIM_CreateSimulator(0,-20,0) ;======================== Dim mesh (number) Dim rb (number) Dim joint(number) ;create the hook hookPivot = CreatePivot() PositionEntity hookpivot,0,20,0 hook = CreateSphere() PositionEntity hook,EntityX#(hookPivot),EntityY#(hookPivot),EntityZ#(hookPivot) EntityAlpha hook,.5 ;======================== TOKSIM_SetRigidBodiesCount number+1 TOKSIM_SetAnimatedBodiesCount 1 TOKSIM_SetGeometriesCount number+2 TOKSIM_CreateSimulator(0,-10,0) For i=1 To number mesh(i) = CreateCylinder() ScaleEntity mesh(i),1,1.7,1 EntityColor mesh(i),0,0,0 rb(i) = TOKRB_Create() TOKRB_AddCylinder rb(i),2.14,2 TOKRB_SetPosition rb(i),EntityX#(hookPivot),EntityY#(hookPivot)-(i*Ydistance),EntityZ#(hookPivot) TOKRB_SetLinearDamping rb(i),0.0001 TOKRB_SetAngularDamping rb(i),0.0 TOKRB_SetMass rb(i),1 TOKRB_SetBoxInertiaTensor rb(i),2.0,2.0,2.0,2 TOKRB_SetMass rb(i),20 TOKRB_CollideConnected rb(i),True If i=1 joint(i) = TOKJOINT_Create(1,rb(i),0) TOKJOINT_SetPositionAndRotationWorld(joint(i),0.0,EntityY#(hookPivot)-(i*(Ydistance/2)),0.0,0,0,90) Else joint(i) = TOKJOINT_Create(2,rb(i-1),rb(i)) TOKJOINT_SetPositionAndRotationWorld(joint(i),0.0,TOKRB_GetY(rb(i-1))-1.5,0.0,0,0,90) EndIf TOKJOINT_SetType(joint(i),1) TOKJOINT_SetLowerLimit joint(i),3.14*0.0 TOKJOINT_SetUpperLimit joint(i),3.14*0.8 TOKJOINT_EnableLimit joint(i),True TOKJOINT_Enable(joint(i),True) TOKJOINT_SetDampingFactor joint(i),80.0 Next period=1000/FPS time=MilliSecs()-period ; 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.9/FPS,2) UpdateWorld Next For i=1 To number PositionEntity mesh(i),TOKRB_GetX#(rb(i)),TOKRB_GetY#(rb(i)),TOKRB_GetZ#(rb(i)) RotateEntity mesh(i),TOKRB_GetPitch#(rb(i)),TOKRB_GetYaw#(rb(i)),TOKRB_GetRoll#(rb(i)) If KeyDown( 208 )=True Then TOKRB_ApplyImpulse rb(number),0,0,-.1 If KeyDown( 200 )=True Then TOKRB_ApplyImpulse rb(number),0,0,.1 If KeyDown( 203 )=True Then TOKRB_ApplyImpulse rb(number),-.1,0,0 If KeyDown( 205 )=True Then TOKRB_ApplyImpulse rb(number),.1,0,0 Next 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
|
|
|
Post by botbuilder on Jul 15, 2004 19:47:50 GMT
Sweet. I might just have a use for this as well.... ;D
|
|
|
Post by dillpickle79 on Jul 15, 2004 22:38:03 GMT
awesome! That's exactly what I was planning for my system ;D
|
|
|
Post by dillpickle79 on Jul 15, 2004 23:59:46 GMT
Look at what I just did! I've added rope breaking like in farcry. So if you shoot the rope by clicking on it it breaks. You can also bounce it by right-clicking. It's quite fun to play with this. I have also added a box at the end to simulate clinging to objects.
Um, I hope you can find out what I did, it's not commented.
Const FPS=60 ;========================= Const number = 40 ;Number of rope points Const Ydistance = 3 ;This also defines the resolution of the rope. \\ Adjust the height of the mesh and RidigBody scale manually if you change it.
Global Lastnumber = number
;========================= Graphics3D 800,600,0,2 SetBuffer BackBuffer()
WireFrame False
camera = CreateCamera() PositionEntity camera,0,2,-150 CameraClsColor camera,82,134,172 light=CreateLight() PositionEntity light,7,15,-5
TOKSIM_CreateSimulator(0,-20,0) ;========================
Dim mesh (number) Dim rb (number) Dim joint(number)
;create the hook hookPivot = CreatePivot() PositionEntity hookpivot,0,20,0
hook = CreateSphere() PositionEntity hook,EntityX#(hookPivot),EntityY#(hookPivot),EntityZ#(hookPivot) EntityAlpha hook,.5
;========================
TOKSIM_SetRigidBodiesCount number+1 TOKSIM_SetAnimatedBodiesCount 1 TOKSIM_SetGeometriesCount number+2 TOKSIM_CreateSimulator(0,-10,0)
For i=1 To number - 1
mesh(i) = CreateCylinder() ScaleEntity mesh(i),1,1.7,1 EntityColor mesh(i),0,0,0 EntityPickMode mesh(i),2 NameEntity mesh(i),i
rb(i) = TOKRB_Create() TOKRB_AddCylinder rb(i),2.14,2 TOKRB_SetPosition rb(i),EntityX#(hookPivot),EntityY#(hookPivot)-(i*Ydistance),EntityZ#(hookPivot) TOKRB_SetLinearDamping rb(i),0.0001 TOKRB_SetAngularDamping rb(i),0.0 TOKRB_SetMass rb(i),1 TOKRB_SetBoxInertiaTensor rb(i),2.0,2.0,2.0,2 TOKRB_SetMass rb(i),20 TOKRB_CollideConnected rb(i),True
If i=1 joint(i) = TOKJOINT_Create(1,rb(i),0) TOKJOINT_SetPositionAndRotationWorld(joint(i),0.0,EntityY#(hookPivot)-(i*(Ydistance/2)),0.0,0,0,90) Else joint(i) = TOKJOINT_Create(2,rb(i-1),rb(i)) TOKJOINT_SetPositionAndRotationWorld(joint(i),0.0,TOKRB_GetY(rb(i-1))-1.5,0.0,0,0,90) EndIf
TOKJOINT_SetType(joint(i),1) TOKJOINT_SetLowerLimit joint(i),3.14*0.0 TOKJOINT_SetUpperLimit joint(i),3.14*0.8 TOKJOINT_EnableLimit joint(i),True TOKJOINT_Enable(joint(i),True) TOKJOINT_SetDampingFactor joint(i),80.0
Next
;the last section that it is holding (test) i = number
mesh(i) = CreateCube() ScaleEntity mesh(i),20,10,15,True EntityColor mesh(i),255,0,0 EntityPickMode mesh(i),2 NameEntity mesh(i),i
rb(i) = TOKRB_Create() TOKRB_AddBox rb(i),40,20,30 TOKRB_SetPosition rb(i),EntityX#(hookPivot),EntityY#(hookPivot)-(i*Ydistance),EntityZ#(hookPivot) TOKRB_SetLinearDamping rb(i),0.0001 TOKRB_SetAngularDamping rb(i),0.0 TOKRB_SetMass rb(i),100 TOKRB_SetBoxInertiaTensor rb(i),2.0,2.0,2.0,2 TOKRB_SetMass rb(i),200 TOKRB_CollideConnected rb(i),True
joint(i) = TOKJOINT_Create(2,rb(i-1),rb(i)) TOKJOINT_SetPositionAndRotationWorld(joint(i),0.0,TOKRB_GetY(rb(i-1))-1.5,0.0,0,0,90)
TOKJOINT_SetType(joint(i),1) TOKJOINT_SetLowerLimit joint(i),3.14*0.0 TOKJOINT_SetUpperLimit joint(i),3.14*0.8 TOKJOINT_EnableLimit joint(i),True TOKJOINT_Enable(joint(i),True) TOKJOINT_SetDampingFactor joint(i),80.0
period=1000/FPS time=MilliSecs()-period
; 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.9/FPS,2) UpdateWorld Next
; destroying sections If MouseDown(1) CameraPick(camera,MouseX(),MouseY()) If Not PickedEntity() = False Jnumber = EntityName(PickedEntity()) If Jnumber = number TOKRB_ApplyImpulse2 rb(Jnumber),0,0,.1,PickedX() * 2,PickedY() * 2,PickedZ() * 2 Lastnumber = JNumber - 1 Else TOKRB_ApplyImpulse2 rb(Jnumber),0,0,.1 ,PickedX() * 2,PickedY() * 2,PickedZ() * 2 If Not joint(JNumber) = False TOKJOINT_Free joint(Jnumber) Lastnumber = JNumber - 1 EndIf EndIf EndIf EndIf
;bouncing sections If MouseDown(2) CameraPick(camera,MouseX(),MouseY()) If Not PickedEntity() = False Jnumber = EntityName(PickedEntity()) TOKRB_ApplyImpulse2 rb(Jnumber),0,0,.1 ,PickedX() * 2,PickedY() * 2,PickedZ() * 2 EndIf EndIf
For i=1 To number PositionEntity mesh(i),TOKRB_GetX#(rb(i)),TOKRB_GetY#(rb(i)),TOKRB_GetZ#(rb(i)) RotateEntity mesh(i),TOKRB_GetPitch#(rb(i)),TOKRB_GetYaw#(rb(i)),TOKRB_GetRoll#(rb(i))
If KeyDown( 208 )=True Then TOKRB_ApplyImpulse rb(Lastnumber),0,0,-.1 If KeyDown( 200 )=True Then TOKRB_ApplyImpulse rb(Lastnumber),0,0,.1 If KeyDown( 203 )=True Then TOKRB_ApplyImpulse rb(Lastnumber),-.1,0,0 If KeyDown( 205 )=True Then TOKRB_ApplyImpulse rb(Lastnumber),.1,0,0 Next
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
|
|
|
Post by botbuilder on Jul 16, 2004 4:47:03 GMT
Cool!
some small changes -
Const FPS=60 ;========================= Const number = 40 ;Number of rope points Const Ydistance = 3 ;This also defines the resolution of the rope. \\ Adjust the height of the mesh and RidigBody scale manually if you change it.
Global Lastnumber = number
;========================= Graphics3D 800,600,0,2 SetBuffer BackBuffer()
WireFrame False
campiv=CreatePivot()
camera = CreateCamera(campiv) PositionEntity camera,0,2,-170 RotateEntity camera,30,0,0 CameraClsColor camera,82,134,172 light=CreateLight() PositionEntity light,7,15,-5
TOKSIM_CreateSimulator(0,-20,0) ;========================
Dim mesh (number) Dim rb (number) Dim joint(number)
;create the hook hookPivot = CreatePivot() PositionEntity hookpivot,0,20,0
hook = CreateSphere() PositionEntity hook,EntityX#(hookPivot),EntityY#(hookPivot),EntityZ#(hookPivot) EntityAlpha hook,.5
;========================
TOKSIM_SetRigidBodiesCount number+1 TOKSIM_SetAnimatedBodiesCount 1 TOKSIM_SetGeometriesCount number+2 TOKSIM_CreateSimulator(0,-10,0)
For i=1 To number - 1
mesh(i) = CreateCylinder() ScaleEntity mesh(i),1,1.7,1 EntityColor mesh(i),0,0,0 EntityPickMode mesh(i),2 NameEntity mesh(i),i
rb(i) = TOKRB_Create() TOKRB_AddCylinder rb(i),2.14,2 TOKRB_SetPosition rb(i),EntityX#(hookPivot),EntityY#(hookPivot)-(i*Ydistance),EntityZ#(hookPivot) TOKRB_SetLinearDamping rb(i),0.0001 TOKRB_SetAngularDamping rb(i),0.0 TOKRB_SetMass rb(i),.1 TOKRB_SetBoxInertiaTensor rb(i),2.0,2.0,2.0,2 TOKRB_SetMass rb(i),20 TOKRB_CollideConnected rb(i),True
If i=1 joint(i) = TOKJOINT_Create(1,rb(i),0) TOKJOINT_SetPositionAndRotationWorld(joint(i),0.0,EntityY#(hookPivot)-(i*(Ydistance/2)),0.0,0,0,90) Else joint(i) = TOKJOINT_Create(2,rb(i-1),rb(i)) TOKJOINT_SetPositionAndRotationWorld(joint(i),0.0,TOKRB_GetY(rb(i-1))-1.5,0.0,0,0,90) EndIf
TOKJOINT_SetType(joint(i),1) TOKJOINT_SetLowerLimit joint(i),3.14*0.0 TOKJOINT_SetUpperLimit joint(i),3.14*0.8 TOKJOINT_EnableLimit joint(i),True TOKJOINT_Enable(joint(i),True) TOKJOINT_SetDampingFactor joint(i),80.0
Next
ground=TOKAB_Create() TOKAB_AddBox ground,200,1,200 TOKAB_SetPosition ground,0,-120,0 gr=CreateCube() ScaleEntity gr,100,.5,100 PositionEntity gr,0,-120,0 ;the last section that it is holding (test) i = number
mesh(i) = CreateCube() ScaleEntity mesh(i),20,10,15,True EntityColor mesh(i),255,0,0 EntityPickMode mesh(i),2 NameEntity mesh(i),i
rb(i) = TOKRB_Create() TOKRB_AddBox rb(i),40,20,30 TOKRB_SetPosition rb(i),EntityX#(hookPivot),EntityY#(hookPivot)-(i*Ydistance),EntityZ#(hookPivot) TOKRB_SetLinearDamping rb(i),0.0001 TOKRB_SetAngularDamping rb(i),0.0 TOKRB_SetMass rb(i),100 TOKRB_SetBoxInertiaTensor rb(i),20.0,10.0,15.0,100 TOKRB_SetMass rb(i),200 TOKRB_CollideConnected rb(i),True
joint(i) = TOKJOINT_Create(2,rb(i-1),rb(i)) TOKJOINT_SetPositionAndRotationWorld(joint(i),0.0,TOKRB_GetY(rb(i-1))-1.5,0.0,0,0,90)
TOKJOINT_SetType(joint(i),1) TOKJOINT_SetLowerLimit joint(i),3.14*0.0 TOKJOINT_SetUpperLimit joint(i),3.14*0.8 TOKJOINT_EnableLimit joint(i),True TOKJOINT_Enable(joint(i),True) TOKJOINT_SetDampingFactor joint(i),80.0
period=1000/FPS time=MilliSecs()-period
; MainLoop While Not KeyHit(1) TurnEntity campiv,0,.1,0 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.9/FPS,2) UpdateWorld Next
; destroying sections If MouseDown(1) CameraPick(camera,MouseX(),MouseY()) If Not PickedEntity() = False Jnumber = EntityName(PickedEntity()) If Jnumber = number TOKRB_ApplyImpulse2 rb(Jnumber),0,0,.1,PickedX() * 2,PickedY() * 2,PickedZ() * 2 Lastnumber = JNumber - 1 Else TOKRB_ApplyImpulse2 rb(Jnumber),0,0,.1 ,PickedX() * 2,PickedY() * 2,PickedZ() * 2 If Not joint(JNumber) = False TOKJOINT_Free joint(Jnumber) Lastnumber = JNumber - 1 EndIf EndIf EndIf EndIf
;bouncing sections If MouseDown(2) CameraPick(camera,MouseX(),MouseY()) If Not PickedEntity() = False Jnumber = EntityName(PickedEntity()) TOKRB_ApplyImpulse2 rb(Jnumber),0,0,10 ,PickedX() * 2,PickedY() * 2,PickedZ() * 2 EndIf EndIf
For i=1 To number PositionEntity mesh(i),TOKRB_GetX#(rb(i)),TOKRB_GetY#(rb(i)),TOKRB_GetZ#(rb(i)) RotateEntity mesh(i),TOKRB_GetPitch#(rb(i)),TOKRB_GetYaw#(rb(i)),TOKRB_GetRoll#(rb(i))
If KeyDown( 208 )=True Then TOKRB_ApplyImpulse rb(Lastnumber),0,0,-.1 If KeyDown( 200 )=True Then TOKRB_ApplyImpulse rb(Lastnumber),0,0,.1 If KeyDown( 203 )=True Then TOKRB_ApplyImpulse rb(Lastnumber),-.1,0,0 If KeyDown( 205 )=True Then TOKRB_ApplyImpulse rb(Lastnumber),.1,0,0 Next
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
|
|
|
Post by dillpickle79 on Jul 16, 2004 5:12:23 GMT
I think I may have fixed the error where it freezes with too many joints being freed at once. This is getting pretty cool Const FPS=60 ;========================= Const number = 40 ;Number of rope points Const Ydistance = 3 ;This also defines the resolution of the rope. \\ Adjust the height of the mesh and RidigBody scale manually if you change it. Global Lastnumber = number ;========================= Graphics3D 800,600,0,2 SetBuffer BackBuffer() WireFrame False campiv=CreatePivot() camera = CreateCamera(campiv) PositionEntity camera,0,2,-170 RotateEntity camera,30,0,0 CameraClsColor camera,82,134,172 light=CreateLight() PositionEntity light,7,15,-5 TOKSIM_CreateSimulator(0,-20,0) ;======================== Dim mesh (number) Dim rb (number) Dim joint(number) ;create the hook hookPivot = CreatePivot() PositionEntity hookpivot,0,20,0 hook = CreateSphere() PositionEntity hook,EntityX#(hookPivot),EntityY#(hookPivot),EntityZ#(hookPivot) EntityAlpha hook,.5 ;======================== TOKSIM_SetRigidBodiesCount number+1 TOKSIM_SetAnimatedBodiesCount 1 TOKSIM_SetGeometriesCount number+2 TOKSIM_CreateSimulator(0,-10,0) ;ground material TOKSIM_SetMaterial 0,0.8,0.1 For i=1 To number - 1 mesh(i) = CreateCylinder() ScaleEntity mesh(i),1,1.7,1 EntityColor mesh(i),0,0,0 EntityPickMode mesh(i),2 NameEntity mesh(i),i rb(i) = TOKRB_Create() TOKRB_AddCylinder rb(i),2.14,2 TOKRB_SetPosition rb(i),EntityX#(hookPivot),EntityY#(hookPivot)-(i*Ydistance),EntityZ#(hookPivot) TOKRB_SetLinearDamping rb(i),0.0001 TOKRB_SetAngularDamping rb(i),0.0 TOKRB_SetMass rb(i),.1 TOKRB_SetBoxInertiaTensor rb(i),2.0,2.0,2.0,2 TOKRB_SetMass rb(i),20 TOKRB_CollideConnected rb(i),True If i=1 joint(i) = TOKJOINT_Create(1,rb(i),0) TOKJOINT_SetPositionAndRotationWorld(joint(i),0.0,EntityY#(hookPivot)-(i*(Ydistance/2)),0.0,0,0,90) Else joint(i) = TOKJOINT_Create(2,rb(i-1),rb(i)) TOKJOINT_SetPositionAndRotationWorld(joint(i),0.0,TOKRB_GetY(rb(i-1))-1.5,0.0,0,0,90) EndIf TOKJOINT_SetType(joint(i),1) TOKJOINT_SetLowerLimit joint(i),3.14*0.0 TOKJOINT_SetUpperLimit joint(i),3.14*0.8 TOKJOINT_EnableLimit joint(i),True TOKJOINT_Enable(joint(i),True) TOKJOINT_SetDampingFactor joint(i),80.0 Next GroundA=TOKAB_Create() GroundGeom = TOKAB_AddBox(GroundA,200,1,200) TOKGEOM_SetMaterialIndex GroundGeom,0 TOKAB_SetPosition GroundA,0,-120,0 gr=CreateCube() ScaleEntity gr,100,.5,100 PositionEntity gr,0,-120,0 ;the last section that it is holding (test) i = number mesh(i) = CreateCube() ScaleEntity mesh(i),20,10,15,True EntityColor mesh(i),255,0,0 EntityPickMode mesh(i),2 NameEntity mesh(i),i rb(i) = TOKRB_Create() TOKRB_AddBox rb(i),40,20,30 TOKRB_SetPosition rb(i),EntityX#(hookPivot),EntityY#(hookPivot)-(i*Ydistance),EntityZ#(hookPivot) TOKRB_SetLinearDamping rb(i),0.0001 TOKRB_SetAngularDamping rb(i),0.0 TOKRB_SetMass rb(i),100 TOKRB_SetBoxInertiaTensor rb(i),20.0,10.0,15.0,100 TOKRB_SetMass rb(i),200 TOKRB_CollideConnected rb(i),True joint(i) = TOKJOINT_Create(2,rb(i-1),rb(i)) TOKJOINT_SetPositionAndRotationWorld(joint(i),0.0,TOKRB_GetY(rb(i-1))-1.5,0.0,0,0,90) TOKJOINT_SetType(joint(i),1) TOKJOINT_SetLowerLimit joint(i),3.14*0.0 TOKJOINT_SetUpperLimit joint(i),3.14*0.8 TOKJOINT_EnableLimit joint(i),True TOKJOINT_Enable(joint(i),True) TOKJOINT_SetDampingFactor joint(i),80.0 period=1000/FPS time=MilliSecs()-period ; MainLoop While Not KeyHit(1) TurnEntity campiv,0,.1,0 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.9/FPS,2) UpdateWorld Next ; destroying sections If MouseDown(1) And SAllowed = True CameraPick(camera,MouseX(),MouseY()) If Not PickedEntity() = False Sallowed = False Jnumber = EntityName(PickedEntity()) If Jnumber = number TOKRB_ApplyImpulse2 rb(Jnumber),0,0,.1,PickedX() * 2,PickedY() * 2,PickedZ() * 2 Lastnumber = JNumber - 1 Else TOKRB_ApplyImpulse2 rb(Jnumber),0,0,.1 ,PickedX() * 2,PickedY() * 2,PickedZ() * 2 If Not joint(JNumber) = False TOKJOINT_Free joint(Jnumber) Lastnumber = JNumber - 1 EndIf EndIf EndIf Else If Not MouseDown(1) Then SAllowed = True EndIf ;bouncing sections If MouseDown(2) CameraPick(camera,MouseX(),MouseY()) If Not PickedEntity() = False Jnumber = EntityName(PickedEntity()) TOKRB_ApplyImpulse2 rb(Jnumber),0,0,10 ,PickedX() * 2,PickedY() * 2,PickedZ() * 2 EndIf EndIf For i=1 To number PositionEntity mesh(i),TOKRB_GetX#(rb(i)),TOKRB_GetY#(rb(i)),TOKRB_GetZ#(rb(i)) RotateEntity mesh(i),TOKRB_GetPitch#(rb(i)),TOKRB_GetYaw#(rb(i)),TOKRB_GetRoll#(rb(i)) If KeyDown( 208 )=True Then TOKRB_ApplyImpulse rb(Lastnumber),0,0,-.1 If KeyDown( 200 )=True Then TOKRB_ApplyImpulse rb(Lastnumber),0,0,.1 If KeyDown( 203 )=True Then TOKRB_ApplyImpulse rb(Lastnumber),-.1,0,0 If KeyDown( 205 )=True Then TOKRB_ApplyImpulse rb(Lastnumber),.1,0,0 Next 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
|
|
|
Post by botbuilder on Jul 16, 2004 8:02:50 GMT
|
|
|
Post by dillpickle79 on Jul 16, 2004 13:59:34 GMT
I just thought of a way to implement this into a game without too many problems ;D I think I'll try making a bridge demo with this...
|
|
|
Post by Constantine on Jul 18, 2004 13:22:37 GMT
Nice modifications!
|
|
DC
New Member
Posts: 1
|
Post by DC on Jul 18, 2004 14:55:16 GMT
There seems to be some weird propulsion problems. If the big block falls on top of some the rope, it springs back unrealistically after a few seconds. Is this fixable?
|
|
|
Post by dillpickle79 on Jul 20, 2004 14:10:09 GMT
Yah, I noticed that. I'm going to fiddle with the settings in the joints and collisions there to see if I can get it right...
|
|
gus
New Member
Posts: 24
|
Post by gus on Jul 30, 2004 1:53:32 GMT
Why it crashes when I exit? what's wrong with the TOKSIM_DestroySimulator() Function m8s?!
|
|
saad
New Member
Posts: 16
|
Post by saad on Sept 15, 2004 13:44:39 GMT
Hello everybody some littles changes disabling joints instead of freeing them...(simpliest code and shortest) If Not PickedEntity() = False... thats the kind of logic that kill me but which maybe just mean that i'm not a very good coder, but otherwise i think that the simplest things are always the best see you soon bye bye
;RopeTok Demo v.6 ;Rope tokamak demo originally by Souled, modified by dillpickle79 and Bot_builder and saad ;)
Const FPS=60 ;========================= Const number = 40 ;Number of rope points Const Ydistance = 3 ;This also defines the resolution of the rope. \\ Adjust the height of the mesh and RidigBody scale manually if you change it.
Global Lastnumber = number
;========================= Graphics3D 800,600,0,2 SetBuffer BackBuffer()
campiv=CreatePivot()
camera = CreateCamera(campiv) PositionEntity camera,0,2,-170 RotateEntity camera,30,0,0 CameraClsColor camera,82,134,172 light=CreateLight() PositionEntity light,7,15,-5
Dim mesh (number) Dim rb (number) Dim joint(number)
;create the hook hookPivot = CreatePivot() PositionEntity hookpivot,0,20,0
hook = CreateSphere() PositionEntity hook,EntityX#(hookPivot),EntityY#(hookPivot),EntityZ#(hookPivot) EntityAlpha hook,.5
TOKSIM_CreateSimulator(0,-10,0)
TOKSIM_SetRigidBodiesCount number+1 TOKSIM_SetAnimatedBodiesCount 1 TOKSIM_SetGeometriesCount number+2
;ground material TOKSIM_SetMaterial 0,0.8,0.1
For i=1 To number - 1
mesh(i) = CreateCylinder() ScaleEntity mesh(i),1,1.7,1 EntityColor mesh(i),196,118,2 EntityPickMode mesh(i),2 NameEntity mesh(i),i
rb(i) = TOKRB_Create() TOKRB_AddCylinder rb(i),2.14,1 TOKRB_SetPosition rb(i),EntityX#(hookPivot),EntityY#(hookPivot)-(i*Ydistance),EntityZ#(hookPivot) TOKRB_SetLinearDamping rb(i),0.0001 TOKRB_SetAngularDamping rb(i),0.0 TOKRB_SetMass rb(i),20 TOKRB_SetCylinderInertiaTensor rb(i),2.14,1,20
TOKRB_CollideConnected rb(i),True
If i=1 joint(i) = TOKJOINT_Create(1,rb(i),0) TOKJOINT_SetPositionAndRotationWorld(joint(i),0.0,EntityY#(hookPivot)-(i*(Ydistance/2)),0.0,0,0,90) Else joint(i) = TOKJOINT_Create(2,rb(i-1),rb(i)) TOKJOINT_SetPositionAndRotationWorld(joint(i),0.0,TOKRB_GetY(rb(i-1))-1.5,0.0,0,0,90) EndIf
TOKJOINT_SetType(joint(i),1) TOKJOINT_SetLowerLimit joint(i),3.14*0.0 TOKJOINT_SetUpperLimit joint(i),3.14*0.8 TOKJOINT_EnableLimit joint(i),True TOKJOINT_Enable(joint(i),True) TOKJOINT_SetDampingFactor joint(i),80.0
Next
GroundA=TOKAB_Create() GroundGeom = TOKAB_AddBox(GroundA,200,1,200) TOKGEOM_SetMaterialIndex GroundGeom,0 TOKAB_SetPosition GroundA,0,-150,0 gr=CreateCube() ScaleEntity gr,100,.5,100 PositionEntity gr,0,-150,0
;the last section that it is holding (test) i = number
mesh(i) = CreateSphere(16) ScaleEntity mesh(i),20,20,20 EntityAlpha mesh(i),.5 EntityPickMode mesh(i),2 NameEntity mesh(i),i lamp = CreateSphere(8,mesh(i)) EntityColor lamp,125,125,0 ScaleEntity lamp,.3,.3,.3
rb(i) = TOKRB_Create() TOKRB_AddSphere rb(i),40 TOKRB_SetPosition rb(i),EntityX#(hookPivot),EntityY#(hookPivot)-(i*Ydistance),EntityZ#(hookPivot) TOKRB_SetLinearDamping rb(i),0.0001 TOKRB_SetAngularDamping rb(i),0.0 TOKRB_SetMass rb(i),100 TOKRB_SetSphereInertiaTensor rb(i),40,100 TOKRB_CollideConnected rb(i),True
joint(i) = TOKJOINT_Create(2,rb(i-1),rb(i)) TOKJOINT_SetPositionAndRotationWorld(joint(i),0.0,TOKRB_GetY(rb(i-1))-1.5,0.0,0,0,90)
TOKJOINT_SetType(joint(i),1) TOKJOINT_SetLowerLimit joint(i),3.14*0.0 TOKJOINT_SetUpperLimit joint(i),3.14*0.8 TOKJOINT_EnableLimit joint(i),True TOKJOINT_Enable(joint(i),True) TOKJOINT_SetDampingFactor joint(i),80.0
period=1000/FPS time=MilliSecs()-period
; MainLoop While Not KeyHit(1) TurnEntity campiv,0,.1,0 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.9/FPS,2) UpdateWorld Next ; destroying sections If MouseDown(1) CameraPick(camera,MouseX(),MouseY()) For i=1 To number If PickedEntity()=mesh(i) Then TOKJOINT_Enable joint(i),False Next EndIf ;bouncing sections If MouseDown(2) CameraPick(camera,MouseX(),MouseY()) If Not PickedEntity() = False Jnumber = EntityName(PickedEntity()) TOKRB_ApplyImpulse2 rb(Jnumber),0,0,50 ,PickedX() * 2,PickedY() * 2,PickedZ() * 2 EndIf EndIf For i=1 To number PositionEntity mesh(i),TOKRB_GetX#(rb(i)),TOKRB_GetY#(rb(i)),TOKRB_GetZ#(rb(i)) RotateEntity mesh(i),TOKRB_GetPitch#(rb(i)),TOKRB_GetYaw#(rb(i)),TOKRB_GetRoll#(rb(i)) If KeyDown( 208 )=True Then TOKRB_ApplyImpulse rb(Lastnumber),0,0,-1 If KeyDown( 200 )=True Then TOKRB_ApplyImpulse rb(Lastnumber),0,0,1 If KeyDown( 203 )=True Then TOKRB_ApplyImpulse rb(Lastnumber),-1,0,0 If KeyDown( 205 )=True Then TOKRB_ApplyImpulse rb(Lastnumber),1,0,0 Next 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
|
|
|
Post by dillpickle79 on Oct 19, 2004 14:41:28 GMT
OMG! I think I did that mess of logical operators. What was I thinking...
|
|
danny
New Member
Posts: 33
|
Post by danny on Nov 17, 2004 9:52:26 GMT
All awesome stuff!
but... how can you MOVE the base of the rope?
And ofcourse keep all the dynamics?! I want to parent the base of a rope (a chain) to a blitz object.
I've been trying to figure this out but have not been very succesfull...
Pushing my luck here... would it be possible to constrain BOTH ENDS of the rope to a given position?
Any help very much appreciated!!!
Danny.
|
|