Jaahah... Joku menee kyllä nyt pahasti pieleen cb:n kääntämisessä... Kun koitan laittaa tälläistä
Code: Select all
If b2DynamicBodyCount = 0 Then Return
Tässä kuitenkin koodi:
Code: Select all
Const BOX2D_DLL = "cbBox2D.dll"
Type b2Bodies
Field x#
Field y#
Field angle#
Field velocityX#
Field velocityY#
Field angularVelocity#
Field id
Field fixtures //memblock
Field t As Byte
EndType
Global b2DynamicBodyCount As Integer
b2DynamicBodyCount = 0
Type b2Fixtures
Field id
Field posAng#
Field posLen#
Field shape
Field density#
Field restitution#
Field friction#
Field obj
EndType
Const b2PACKET_CREATE_BODY = 1
Const b2PACKET_CREATE_FIXTURE = 2
Const b2CREATE_BODY_FLAG_NO_FLAGS = 0
Const b2CREATE_BODY_FLAG_BULLET = 1
Const b2CREATE_BODY_FLAG_FIXED_ROTATION = 2
Const b2CREATE_BODY_FLAG_BULLET_AND_FIXED_ROTATION = 3
Const b2BODY_TYPE_STATIC = 0
Const b2BODY_TYPE_KINEMATIC = 1
Const b2BODY_TYPE_DYNAMIC = 2
Const b2SHAPE_CIRCLE = 1
Const b2SHAPE_BOX = 2
Const b2SHAPE_CUSTOM = 3
Function b2Init(gravX#,gravY#)
Print "T4"
mem = MakeMEMBlock(8)
PokeFloat mem,0,gravX
PokeFloat mem,4,gravY
Print "T6"
CallDLL BOX2D_DLL,"init",mem
Print "T5"
EndFunction
Function b2Destroy()
CallDLL BOX2D_DLL,"destroy"
EndFunction
Function b2Update(timestep#,velocityupdates = 3,positionupdates = 3)
mem = MakeMEMBlock(12)
PokeFloat mem,0,timestep
PokeInt mem,4,velocityupdates
PokeInt mem,8,positionupdates
CallDLL BOX2D_DLL,"update",mem
DeleteMEMBlock mem
EndFunction
Function b2WaitForUpdate()
CallDLL BOX2D_DLL,"waitforfinish"
EndFunction
Function b2GetData()
//Alempi rivi bugaa...
//If b2DynamicBodyCount = 0 Then Return
ret = MakeMEMBlock(b2DynamicBodyCount*28)
CallDLL BOX2D_DLL,"getdata",0,ret
index = 0
For i = 1 To b2DynamicBodyCount
b.b2Bodies = ConvertToType(PeekInt(ret,index))
b\x = PeekFloat(ret,index+4)
b\y = PeekFloat(ret,index+8)
b\angle = PeekFloat(ret,index+12)
b\velocityX = PeekFloat(ret,index+16)
b\velocityY = PeekFloat(ret,index+20)
b\angularVelocity = PeekFloat(ret,index+24)
If b\fixtures Then
fixtures = MEMBlockSize(b\fixtures)/4-1
For fi = 0 To fixtures
f.b2Fixtures = ConvertToType(PeekInt(b\fixtures,fi*4))
If (f\obj) Then
RotateObject f\obj,b\angle
TranslateObject f\obj,Cos(b\angle+f\posAng)*f\posLen,Sin(b\angle+f\posAng)*f\posLen
EndIf
Next fi
EndIf
index + 28
Next i
EndFunction
Function b2CreatePositionData(x# = 0,y# = 0,ang# = 0, velocityX# = 0, velocityY = 0,angularVelocity# = 0)
mem = MakeMEMBlock(24)
PokeFloat mem,0,x
PokeFloat mem,4,y
PokeFloat mem,8,ang
PokeFloat mem,12,velocityX
PokeFloat mem,16,velocityY
PokeFloat mem,20,angularVelocity
Return mem
EndFunction
Function b2CreateBody(t As Byte,positionData = 0,flags As Byte = b2CREATE_BODY_FLAG_NO_FLAGS,angulardamping# = 0.01,lineardamping# = 0.01)
Print "T3"
Print "Type:"+t
If positionData Then
x# = PeekFloat(positionData,0)
y# = PeekFloat(positionData,4)
ang# = PeekFloat(positionData,8)
velocityX# = PeekFloat(positionData,12)
velocityY = PeekFloat(positionData,16)
angularVelocity# = PeekFloat(positionData,20)
Else
x# = 0
y# = 0
ang# = 0
velocityX# = 0
velocityY = 0
angularVelocity# = 0
EndIf
body.b2Bodies = New(b2Bodies)
body\x = x
body\y = y
body\angle = ang#
body\t = t
body\velocityX = velocityX
body\velocityY = velocityY
body\angularVelocity = angularVelocity
body\fixtures = 0
If t = b2BODY_TYPE_DYNAMIC Then b2DynamicBodyCount = b2DynamicBodyCount+ 1
mem = MakeMEMBlock(40)
PokeShort mem,0,b2PACKET_CREATE_BODY
PokeFloat mem,2,ang#
PokeFloat mem,6,angulardamping
PokeFloat mem,10,angularvelocity
PokeByte mem,14,flags
PokeByte mem,15,t
PokeFloat mem,16,lineardamping
PokeFloat mem,20,velocityX
PokeFloat mem,24,velocityY
PokeFloat mem,28,x
PokeFloat mem,32,y
PokeInt mem,36,ConvertToInteger(body)
ret = MakeMEMBlock(4)
CallDLL BOX2D_DLL,"packet",mem,ret
body\id = PeekInt(ret,0)
Return ConvertToInteger(body)
EndFunction
Function b2CreateBoxShape(w#,h#,angle# = 0)
mem = MakeMEMBlock(13)
PokeByte mem,0,b2SHAPE_BOX
PokeFloat mem,1,w
PokeFloat mem,5,h
PokeFloat mem,9,angle
Return mem
EndFunction
Function b2CreateCircleShape(radius#)
mem = MakeMEMBlock(5)
PokeByte mem,0,b2SHAPE_BOX
PokeFloat mem,1,radius#
Return mem
EndFunction
Function b2CreateFixture(body,shape,density# = 1,restitution# = 0.3,friction# = 0.8,posX# = 0,posY# = 0,obj = 0)
Print "T2"
b.b2Bodies = ConvertToType(body)
fixture.b2Fixtures = New(b2Fixtures)
fixture\shape = shape
fixture\posLen = Sqrt(posX*posX+posY*posY)
fixture\posAng = GetAngle(0,0,posX,posY)
fixture\density = density
fixture\restitution = restirution
fixture\friction = friction
fixture\obj = obj
If b\fixtures = 0 Then
b\fixtures = MakeMEMBlock(4)
PokeInt b\fixtures,0,ConvertToInteger(fixture)
Else
memsize = MEMBlockSize(b\fixtures)
ResizeMEMBlock b\fixtures,memsize + 4
PokeInt b\fixtures,memsize,ConvertToInteger(fixture)
EndIf
shapeSize = MEMBlockSize(shape)
mem = MakeMEMBlock(shapesize + 30)
PokeShort mem,0,b2PACKET_CREATE_FIXTURE
PokeInt mem,2,b\id
MemCopy shape,0,mem,6,shapeSize
index = 6 + shapeSize
PokeFloat mem,index,posX
PokeFloat mem,index+4,posY
PokeFloat mem,index+8,density
PokeFloat mem,index+12,restitution
PokeFloat mem,index+16,friction
PokeInt mem,index+20,ConvertToInteger(fixture)
ret = MakeMEMBlock(4)
CallDLL BOX2D_DLL,"packet",mem,ret
fixture\id = PeekInt(ret,0)
Return ConvertToInteger(fixture)
EndFunction
Print b2BODY_TYPE_DYNAMIC
Print b2BODY_TYPE_STATIC
b2Init(0,-10)
circleBody = b2CreateBody(2,0,0)
circleShape = b2CreateCircleShape(20)
circleFixture = b2CreateFixture(circleBody,circleShape)
Print b2DynamicBodyCount
boxPosData = b2CreatePositionData(0,-200)
boxBody = b2CreateBody(0,boxPosData)
boxShape = b2CreateBoxShape(100,20)
boxFixture = b2CreateFixture(boxBody,boxShape,0)
Print "T1"
circleT.b2Bodies = ConvertToType(circleBody)
FrameLimit 60
Print "Running"
Repeat
Print "Waiting"
b2WaitForUpdate()
Print "Getting"
b2GetData()
Print "Updating"
b2Update(1.0/60.0)
Print "Drawing"
DrawCircle(circleT\x,circleT\y,20)
DrawScreen
Forever
Function DrawCircle(x,y,radius#)
Circle x-radius,y-radius,radius*2
EndFunction
Niin sitten noista print debuggaus jutuista vielä sen verran, että niiden "Type:" juttujen pitäisi olla 2 ja 0.