''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Car Body
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim escalaCoche As Int = 3
Dim bd As lgBox2DBodyDef
bd.Position.Set(18, 2)
bd.Type = World.BODYTYPE_Dynamic
Dim fd As lgBox2DFixtureDef
fd.Density = 5
fd.Friction = 0.8
fd.Restitution = 0.2
fd.filter.groupIndex = -1
cocheBody= World.CreateBody (bd)
Loader.AttachFixture(cocheBody,"coche",fd,escalaCoche)
cocheTextura.Initialize("body2.png")
cocheSprite.InitializeWithTexture(cocheTextura)
cocheSprite.SetSize(escalaCoche, escalaCoche * cocheSprite.Height / cocheSprite.Width)
Dim Origin As lgMathVector2
Origin = Loader.GetOrigin("coche", escalaCoche)
cocheSprite.SetOrigin(Origin.X, Origin.Y)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Axis
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim axleShape As lgBox2DPolygonShape
Dim V1, V2 As lgMathVector2
axleShape.SetAsBox(0.2,0.2)
Dim axleFixture As lgBox2DFixtureDef
axleFixture.Density = 0.5
axleFixture.Friction = 3
axleFixture.Restitution = 0.1
axleFixture.shape = axleShape
axleFixture.filter.groupIndex = -1
Dim axleBodyDef As lgBox2DBodyDef
axleBodyDef.Type = World.BODYTYPE_Dynamic
'Eje trasero
Dim punto As lgMathVector2
punto.Set(0.13* escalaCoche,0.045* escalaCoche)
axleBodyDef.position.Set2(cocheBody.getWorldPoint(punto))
Dim rearAxle As lgBox2DBody = World.createBody(axleBodyDef)
rearAxle.createFixture(axleFixture)
'Eje delantero
punto.Set(0.81* escalaCoche,0.045* escalaCoche)
axleBodyDef.position.Set2(cocheBody.getWorldPoint(punto))
Dim frontAxle As lgBox2DBody = World.createBody(axleBodyDef)
frontAxle.createFixture(axleFixture)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Wheels
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim escalaRuedas As Float = 1
texturaRuedas.Initialize("rueda.png")
Dim fd As lgBox2DFixtureDef
fd.Density = 5
fd.Friction = 5
fd.Restitution = 0.1
fd.filter.groupIndex = -1
Dim wheelBodyDef As lgBox2DBodyDef
wheelBodyDef.Type = World.BODYTYPE_Dynamic
wheelBodyDef.angularDamping = 1.0
Dim punto As lgMathVector2
'la trasera
punto.Set(0.13* escalaCoche,0.045* escalaCoche)
wheelBodyDef.position.Set2(cocheBody.getWorldPoint(punto))
rearWheel = World.CreateBody (wheelBodyDef)
Loader.AttachFixture(rearWheel,"rueda",fd,escalaRuedas)
'la delantera
punto.Set(0.81* escalaCoche,0.045* escalaCoche)
wheelBodyDef.position.Set2(cocheBody.getWorldPoint(punto))
frontWheel = World.CreateBody (wheelBodyDef)
Loader.AttachFixture(frontWheel,"rueda",fd,escalaRuedas)
'los sprites de las ruedas
For i=0 To 1
ruedasSprite(i).InitializeWithTexture(texturaRuedas)
ruedasSprite(i).SetSize(escalaRuedas, escalaRuedas * ruedasSprite(i).Height / ruedasSprite(i).Width)
Dim Origin As lgMathVector2
Origin = Loader.GetOrigin("rueda", escalaRuedas)
ruedasSprite(i).SetOrigin(Origin.X, Origin.Y)
Next
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Revolute Joints
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim punto As lgMathVector2
punto.Set(0,0)
Dim rearWheelRevoluteJointDef As lgBox2DRevoluteJointDef
Dim frontWheelRevoluteJointDef As lgBox2DRevoluteJointDef
rearWheelRevoluteJointDef.Initialize(rearWheel,rearAxle,rearWheel.GetWorldPoint(punto))
rearWheelRevoluteJointDef.enableMotor=True
rearWheelRevoluteJointDef.maxMotorTorque=70
rearWheelRevoluteJoint=World.CreateJoint(rearWheelRevoluteJointDef)
' Dim frontWheelRevoluteJointDef As lgBox2DRevoluteJointDef
Dim punto As lgMathVector2
punto.Set(0,0)
frontWheelRevoluteJointDef.Initialize(frontWheel,frontAxle,frontWheel.GetWorldPoint(punto))
frontWheelRevoluteJointDef.enableMotor=True
frontWheelRevoluteJointDef.maxMotorTorque=20
frontWheelRevoluteJoint =World.CreateJoint(frontWheelRevoluteJointDef)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Prismatic Joints
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim axlePrismaticJointDef As lgBox2DPrismaticJointDef
axlePrismaticJointDef.lowerTranslation = -0.3
axlePrismaticJointDef.upperTranslation = 0.05
axlePrismaticJointDef.enableLimit = True
axlePrismaticJointDef.enableMotor = True
' front axle
punto.Set(0,0)
Dim direccion As lgMathVector2
direccion.Set(-0.5,1)
direccion.nor
axlePrismaticJointDef.Initialize(cocheBody,frontAxle,frontAxle.GetWorldPoint(punto),direccion)
frontAxlePrismaticJoint = World.CreateJoint(axlePrismaticJointDef)
' rear axle
direccion.Set(0.5,1)
direccion.nor
axlePrismaticJointDef.Initialize(cocheBody,rearAxle,rearAxle.GetWorldPoint(punto),direccion)
rearAxlePrismaticJoint = World.CreateJoint(axlePrismaticJointDef)