Tokamak Physics

Blitz3D Forums/Blitz3D Programming/Tokamak Physics

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Dangly 'thing' :)

[code]
; TOKAMAK Dangle demo using Ball&Socket Joints
;
; Credits:
; Tokamak Physics for their cool physics library
; SWEENIE for creating the BB Tokamak Wrapper
; www.tokamakphysics.com to get the SDK
; www.freewebs.com/sweenie for the BB Tokamak Wrapper
;
; you must put TOKAMAK.DLL (from SDK) in system32
; must put sweenies tokamak files in blitz3d/userlibs directory

Graphics3D 800,600,0,2
SetBuffer BackBuffer()

Const ENTS=20
Const FPS=50

camera = CreateCamera()
PositionEntity camera,10,10,-10

Centerpivot = CreatePivot()

light=CreateLight()
PositionEntity light,7,15,-5
PointEntity light,Centerpivot

CreateSimulator(ENTS,1,0,-10,0)

;BB Visible ground
ground = CreateCube()
EntityColor ground,100,100,100
ScaleEntity ground,50,1,50
PositionEntity ground,0,-2,0

;Tokamak ground
abground = CreateAB()
ABAddBox(abground,100.0,1.0,100.0)
ABSetPosition(abground,0.0,-1.0,0.0)

Dim BoxBB(ENTS)
Dim BoxTOK(ENTS)
Dim Joint(ENTS-1)

;Create a chain of Boxes
For i=1 To ENTS
BoxBB(i) = CreateCube()
ScaleEntity BoxBB(i),.4,.4,.4
PositionEntity BoxBB(i),0,2,i
BoxTOK(i) = CreateRB()
RBAddBox BoxTOK(i),.4,.4,.4
RBCollideConnected BoxTOK(i),True
RBSetPosition(BoxTOK(i),0,2,i)
RBSetLinearDamping BoxTOK(i),0.003
RBSetAngularDamping BoxTOK(i),.03
RBSetMass BoxTOK(i),2.0
RBSetBoxInertiaTensor BoxTOK(i),.4,.4,.4,2.0
EntityColor BoxBB(i),Rnd(100,230),Rnd(100,230),Rnd(100,230)
Next

;Create a Ball/Socket Joint between each Box
For i=1 To ENTS-1
Joint(i) = CreateJointRB2RB(BoxTOK(i),BoxTOK(i+1))
JOINTSetPositionGlobal(Joint(i),0,2,i + .5)
JOINTSetTypeBallSocket(Joint(i))
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
Advance(2.0/FPS)
UpdateWorld
Next

For i=1 To ENTS
PositionEntity BoxBB(i),RBGetX#(BoxTOK(i)),RBGetY#(BoxTOK(i)),RBGetZ#(BoxTOK(i))
RotateEntity BoxBB(i),RBGetPitch#(BoxTOK(i)),RBGetYaw#(BoxTOK(i)),RBGetRoll#(BoxTOK(i)),False
Next

If KeyDown(57) RBApplyImpulse BoxTOK(1),0,.6,0
If KeyDown(203) RBApplyImpulse BoxTOK(1),-.5,0,0
If KeyDown(205) RBApplyImpulse BoxTOK(1),.5,0,0
If KeyDown(200) RBApplyImpulse BoxTOK(1),0,0,.5
If KeyDown(208) RBApplyImpulse BoxTOK(1),0,0,-.5

RenderWorld tween

Color 215,0,0
Rect 586,0,180,12
Color 255,255,255
Text 0,0,"Physics Time (Ms):"+GetPhysicsTime()*1000.0
Text 0,10,"Render Time (Ms):"+Str(elapsed)
Text 0,20,"Use Cursors to move, Space to lift"
Text 500,0,"Powered by WWW.TOKAMAKPHYSICS.COM"


Flip False
Wend
DestroySimulator()
End
[/CODE]

Tom