示例#1
0
    def __init__(self):
        super(Pyramid, self).__init__()
        sd=box2d.b2PolygonDef()
        sd.SetAsBox(50.0, 10.0)

        bd=box2d.b2BodyDef() 
        bd.position.Set(0.0, -10.0)
        ground = self.world.CreateBody(bd) 
        ground.CreateShape(sd)

        sd=box2d.b2PolygonDef() 
        a = 0.5
        sd.SetAsBox(a, a)
        sd.density = 5.0

        x=box2d.b2Vec2(-10.0, 0.75)
        y=box2d.b2Vec2() 
        deltaX=box2d.b2Vec2(0.5625, 2.0)
        deltaY=box2d.b2Vec2(1.125, 0.0)

        for i in range(25):
            y = x.copy()

            for j in range(i, 25):
                bd=box2d.b2BodyDef() 
                bd.position = y
                body = self.world.CreateBody(bd) 
                body.CreateShape(sd)
                body.SetMassFromShapes()
                y += deltaY

            x += deltaX
示例#2
0
    def __init__(self):
        super(DistanceTest, self).__init__()
        sd=box2d.b2PolygonDef() 
        sd.SetAsBox(1.0, 1.0)
        sd.density = 0.0

        bd=box2d.b2BodyDef() 
        bd.position.Set(0.0, 10.0)
        self.m_body1 = self.world.CreateBody(bd)
        self.m_shape1 = self.m_body1.CreateShape(sd)

        sd=box2d.b2PolygonDef() 
        sd.vertexCount = 3
        sd.setVertex(0,-1.0, 0.0)
        sd.setVertex(1,1.0, 0.0)
        sd.setVertex(2,0.0, 15.0)
        sd.density = 1.0
        bd=box2d.b2BodyDef() 
        #bd.position.Set(-48.377853, 0.49244255)
        #bd.rotation = 90.475891
        bd.position.Set(0.0, 10.0)
        self.m_body2 = self.world.CreateBody(bd)
        self.m_shape2 = self.m_body2.CreateShape(sd)
        self.m_body2.SetMassFromShapes()

        self.world.SetGravity(box2d.b2Vec2(0.0, 0.0))
        self.world.SetPositionCorrection(False)
示例#3
0
    def __init__(self):
        super(Chain, self).__init__()
        bd=box2d.b2BodyDef() 
        bd.position.Set(0.0, -10.0)
        ground = self.world.CreateBody(bd)

        sd=box2d.b2PolygonDef() 
        sd.SetAsBox(50.0, 10.0)
        ground.CreateShape(sd)

        sd=box2d.b2PolygonDef() 
        sd.SetAsBox(0.6, 0.125)
        sd.density = 20.0
        sd.friction = 0.2

        jd=box2d.b2RevoluteJointDef() 
        jd.collideConnected = False

        y = 25.0
        prevBody=ground
        for i in range(30):
            bd=box2d.b2BodyDef() 
            bd.position.Set(0.5 + i, y)
            body = self.world.CreateBody(bd) 
            body.CreateShape(sd)
            body.SetMassFromShapes()
            
            anchor=box2d.b2Vec2(i, y)
            jd.Initialize(prevBody, body, anchor)
            self.world.CreateJoint(jd).getAsType()
            
            prevBody = body
示例#4
0
    def __init__(self):
        super(PolyCollision, self).__init__()

        sd=box2d.b2PolygonDef() #box2d.b2PolygonDef sd
        sd.setVertex(0,-9.0, -1.1)
        sd.setVertex(1,7.0, -1.1)
        sd.setVertex(2,5.0, -0.9)
        sd.setVertex(3,-11.0, -0.9)
        sd.vertexCount = 4
        sd.density = 0.0

        bd=box2d.b2BodyDef() #box2d.b2BodyDef bd
        bd.position.Set(0.0, 10.0)
        self.m_body1 = self.world.CreateBody(bd)
        self.m_body1.CreateShape(sd)

        sd=box2d.b2PolygonDef() #box2d.b2PolygonDef sd
        sd.SetAsBox(0.5, 0.5)
        sd.density = 1.0

        bd=box2d.b2BodyDef() #box2d.b2BodyDef bd
        bd.position.Set(0.0, 10.0)
        self.m_body2 = self.world.CreateBody(bd)
        self.m_body2.CreateShape(sd)
        self.m_body2.SetMassFromShapes()

        self.world.SetGravity(box2d.b2Vec2_zero)
        self.world.SetPositionCorrection(False)
示例#5
0
    def __init__(self):
        super(ApplyForce, self).__init__()
        self.world.SetGravity(box2d.b2Vec2(0.0, 0.0))

        k_restitution = 0.4

        bd=box2d.b2BodyDef() 
        bd.position.Set(0.0, 20.0)
        ground = self.world.CreateBody(bd) 

        sd=box2d.b2PolygonDef() 
        sd.density = 0.0
        sd.restitution = k_restitution

        sd.SetAsBox(0.2, 20.0, box2d.b2Vec2(-20.0, 0.0), 0.0)
        ground.CreateShape(sd)

        sd.SetAsBox(0.2, 20.0, box2d.b2Vec2(20.0, 0.0), 0.0)
        ground.CreateShape(sd)

        sd.SetAsBox(0.2, 20.0, box2d.b2Vec2(0.0, -20.0), 0.5 * box2d.b2_pi)
        ground.CreateShape(sd)

        sd.SetAsBox(0.2, 20.0, box2d.b2Vec2(0.0, 20.0), -0.5 * box2d.b2_pi)
        ground.CreateShape(sd)

        xf1 = box2d.b2XForm ()
        xf1.R.Set(0.3524 * box2d.b2_pi)
        xf1.position = box2d.b2Mul(xf1.R, box2d.b2Vec2(1.0, 0.0))

        sd1=box2d.b2PolygonDef() 
        sd1.vertexCount = 3
        sd1.setVertex(0, box2d.b2Mul(xf1, box2d.b2Vec2(-1.0, 0.0)))
        sd1.setVertex(1, box2d.b2Mul(xf1, box2d.b2Vec2(1.0, 0.0)))
        sd1.setVertex(2, box2d.b2Mul(xf1, box2d.b2Vec2(0.0, 0.5)))
        sd1.density = 2.0

        xf2 = box2d.b2XForm ()
        xf2.R.Set(-0.3524 * box2d.b2_pi)
        xf2.position = box2d.b2Mul(xf2.R, box2d.b2Vec2(-1.0, 0.0))

        sd2=box2d.b2PolygonDef() 
        sd2.vertexCount = 3
        sd2.setVertex(0, box2d.b2Mul(xf2, box2d.b2Vec2(-1.0, 0.0)))
        sd2.setVertex(1, box2d.b2Mul(xf2, box2d.b2Vec2(1.0, 0.0)))
        sd2.setVertex(2, box2d.b2Mul(xf2, box2d.b2Vec2(0.0, 0.5)))
        sd2.density = 2.0

        bd=box2d.b2BodyDef() 
        bd.angularDamping = 2.0
        bd.linearDamping = 0.1

        bd.position.Set(0.0, 1.05)
        bd.angle = box2d.b2_pi
        self.m_body = self.world.CreateBody(bd)
        self.m_body.CreateShape(sd1)
        self.m_body.CreateShape(sd2)
        self.m_body.SetMassFromShapes()
示例#6
0
    def __init__(self):
        super(SensorTest, self).__init__()
        bd=box2d.b2BodyDef() 
        bd.position.Set(0.0, -10.0)

        ground = self.world.CreateBody(bd) 

        sd=box2d.b2PolygonDef() 
        sd.SetAsBox(50.0, 10.0)
        ground.CreateShape(sd)

        cd=box2d.b2CircleDef() 
        cd.isSensor = True
        cd.radius = 5.0
        cd.localPosition.Set(0.0, 20.0)
        self.m_sensor = ground.CreateShape(cd)

        sd=box2d.b2CircleDef() 
        sd.radius = 1.0
        sd.density = 1.0

        for i in range(7):
            bd=box2d.b2BodyDef() 
            bd.position.Set(-10.0 + 3.0 * i, 20.0)
            
            body = self.world.CreateBody(bd) 

            body.CreateShape(sd)
            body.SetMassFromShapes()
    def __init__(self):
        super(VaryingRestitution, self).__init__()
        sd=box2d.b2PolygonDef() 
        sd.SetAsBox(50.0, 10.0)

        bd=box2d.b2BodyDef() 
        bd.position.Set(0.0, -10.0)

        ground = self.world.CreateBody(bd) 
        ground.CreateShape(sd)

        sd=box2d.b2CircleDef() 
        sd.radius = 1.0
        sd.density = 1.0

        restitution = [0.0, 0.1, 0.3, 0.5, 0.75, 0.9, 1.0]

        for i in range(7):
            bd=box2d.b2BodyDef() 
            bd.position.Set(-10.0 + 3.0 * i, 20.0)

            body = self.world.CreateBody(bd) 

            sd.restitution = restitution[i]
            body.CreateShape(sd)
            body.SetMassFromShapes()
示例#8
0
    def __init__(self):
        super(Pulleys, self).__init__()
        sd=box2d.b2PolygonDef() 
        sd.SetAsBox(50.0, 10.0)

        bd=box2d.b2BodyDef() 
        bd.position.Set(0.0, -10.0)
        ground = self.world.CreateBody(bd)
        ground.CreateShape(sd)

        a = 2.0
        b = 4.0
        y = 16.0
        L = 12.0

        sd=box2d.b2PolygonDef() 
        sd.SetAsBox(a, b)
        sd.density = 5.0

        bd=box2d.b2BodyDef() 

        bd.position.Set(-10.0, y)
        body1 = self.world.CreateBody(bd) 
        body1.CreateShape(sd)
        body1.SetMassFromShapes()

        bd.position.Set(10.0, y)
        body2 = self.world.CreateBody(bd) 
        body2.CreateShape(sd)
        body2.SetMassFromShapes()

        pulleyDef=box2d.b2PulleyJointDef() 

        anchor1=box2d.b2Vec2(-10.0, y + b)

        anchor2=box2d.b2Vec2(10.0, y + b)

        groundAnchor1=box2d.b2Vec2(-10.0, y + b + L)

        groundAnchor2=box2d.b2Vec2(10.0, y + b + L)
        pulleyDef.Initialize(body1, body2, groundAnchor1, groundAnchor2, anchor1, anchor2, 2.0)

        self.m_joint1 = self.world.CreateJoint(pulleyDef).getAsType() 
示例#9
0
    def __init__(self):
        super(VerticalStack, self).__init__()
        sd=box2d.b2PolygonDef()
        sd.SetAsBox(50.0, 10.0, box2d.b2Vec2(0.0, -10.0), 0.0)

        bd=box2d.b2BodyDef()
        bd.position.Set(0.0, 0.0)
        ground = self.world.CreateBody(bd) 
        ground.CreateShape(sd)

        sd.SetAsBox(0.1, 10.0, box2d.b2Vec2(20.0, 10.0), 0.0)
        ground.CreateShape(sd)

        xs = [0.0, -10.0, -5.0, 5.0, 10.0]

        for j in range(5):
            sd=box2d.b2PolygonDef()
            sd.SetAsBox(0.5, 0.5)
            sd.density = 1.0
            sd.friction = 0.3

            for i in range(12):
                bd=box2d.b2BodyDef()

                # For this test we are using continuous physics for all boxes.
                # This is a stress test, you normally wouldn't do this for
                # performance reasons.
                #bd.isBullet = True
                bd.allowSleep = True

                #x = b2Random(-0.1, 0.1)
                #x = i % 2 == 0 ? -0.025 : 0.025
                bd.position.Set(xs[j], 0.752 + 1.54 * i)
                #bd.position.Set(xs[j], 2.51 + 4.02 * i)
                body = self.world.CreateBody(bd) #

                body.CreateShape(sd)
                body.SetMassFromShapes()

        self.m_bullet = None 
示例#10
0
    def __init__(self):
        super(ShapeEditing, self).__init__()
        sd=box2d.b2PolygonDef()
        sd.SetAsBox(50.0, 10.0)

        bd=box2d.b2BodyDef()
        bd.position.Set(0.0, -10.0)

        ground = self.world.CreateBody(bd) #
        ground.CreateShape(sd)

        bodydef=box2d.b2BodyDef()
        bodydef.position.Set(0.0, 10.0)
        self.m_body = self.world.CreateBody(bodydef)

        sd=box2d.b2PolygonDef()
        sd.SetAsBox(4.0, 4.0, box2d.b2Vec2(0.0, 0.0), 0.0)
        sd.density = 10.0
        self.m_shape1 = self.m_body.CreateShape(sd)
        self.m_body.SetMassFromShapes()

        self.m_shape2 = None
示例#11
0
    def __init__(self):
        super(TimeOfImpact, self).__init__()
        sd=box2d.b2PolygonDef() 
        sd.density = 0.0

        sd.SetAsBox(0.1, 10.0, box2d.b2Vec2(10.0, 0.0), 0.0)

        bd=box2d.b2BodyDef() 
        bd.position.Set(0.0, 20.0)
        bd.angle = 0.0
        self.m_body1 = self.world.CreateBody(bd)
        self.m_shape1 = self.m_body1.CreateShape(sd)

        sd=box2d.b2PolygonDef() 
        sd.SetAsBox(0.25, 0.25)
        sd.density = 1.0

        bd=box2d.b2BodyDef() 
        bd.position.Set(9.6363468, 28.050615)
        bd.angle = 1.6408679
        self.m_body2 = self.world.CreateBody(bd)
        self.m_shape2 = self.m_body2.CreateShape(sd).getAsType()
        self.m_body2.SetMassFromShapes()
示例#12
0
    def __init__(self):
        super(Test_Biped, self).__init__()
        k_restitution = 1.4

        bd=box2d.b2BodyDef()
        bd.position.Set(0.0, 20.0)
        body = self.world.CreateBody(bd)

        sd=box2d.b2PolygonDef()
        sd.density = 0.0
        sd.restitution = k_restitution

        sd.SetAsBox(0.1, 10.0, box2d.b2Vec2(-10.0, 0.0), 0.0)
        body.CreateShape(sd)

        sd.SetAsBox(0.1, 10.0, box2d.b2Vec2(10.0, 0.0), 0.0)
        body.CreateShape(sd)

        sd.SetAsBox(0.1, 10.0, box2d.b2Vec2(0.0, -10.0), 0.5 * box2d.b2_pi)
        body.CreateShape(sd)

        sd.SetAsBox(0.1, 10.0, box2d.b2Vec2(0.0, 10.0), -0.5 * box2d.b2_pi)
        body.CreateShape(sd)

        self.m_biped = Biped(self.world, box2d.b2Vec2(0.0, 20.0))

        for i in range(8):
            bd=box2d.b2BodyDef()
            bd.position.Set(5.0, 20.0 + i)
            bd.isBullet = True
            body = self.world.CreateBody(bd) 
            body.SetLinearVelocity(box2d.b2Vec2(0.0, -100.0))
            body.SetAngularVelocity(box2d.b2Random(-50.0, 50.0))

            sd=box2d.b2CircleDef()
            sd.radius = 0.25
            sd.density = 15.0
            sd.restitution = k_restitution
            body.CreateShape(sd)
            body.SetMassFromShapes()
示例#13
0
    def CreateLeg(self, s, wheelAnchor) :
        p1=box2d.b2Vec2(5.4 * s, -6.1)
        p2=box2d.b2Vec2(7.2 * s, -1.2)
        p3=box2d.b2Vec2(4.3 * s, -1.9)
        p4=box2d.b2Vec2(3.1 * s, 0.8)
        p5=box2d.b2Vec2(6.0 * s, 1.5)
        p6=box2d.b2Vec2(2.5 * s, 3.7)
        
        sd1=box2d.b2PolygonDef()
        sd2=box2d.b2PolygonDef()
        sd1.vertexCount = 3
        sd2.vertexCount = 3
        sd1.filter.groupIndex = -1
        sd2.filter.groupIndex = -1
        sd1.density = 1.0
        sd2.density = 1.0
        
        if s > 0.0:
            sd1.setVertex(0, p1)
            sd1.setVertex(1, p2)
            sd1.setVertex(2, p3)
            
            sd2.setVertex(0, box2d.b2Vec2_zero)
            sd2.setVertex(1, p5 - p4)
            sd2.setVertex(2, p6 - p4)
        else:
            sd1.setVertex(0, p1)
            sd1.setVertex(1, p3)
            sd1.setVertex(2, p2)
            
            sd2.setVertex(0, box2d.b2Vec2_zero)
            sd2.setVertex(1, p6 - p4)
            sd2.setVertex(2, p5 - p4)

        bd1=box2d.b2BodyDef()
        bd2=box2d.b2BodyDef()
        bd1.position = self.m_offset
        bd2.position = p4 + self.m_offset
        
        bd1.angularDamping = 10.0
        bd2.angularDamping = 10.0
        
        body1 = self.world.CreateBody(bd1) 
        body2 = self.world.CreateBody(bd2) 
        
        body1.CreateShape(sd1)
        body2.CreateShape(sd2)
        
        body1.SetMassFromShapes()
        body2.SetMassFromShapes()
        
        djd=box2d.b2DistanceJointDef()
        
        # Using a soft distance constraint can reduce some jitter.
        # It also makes the structure seem a bit more fluid by
        # acting like a suspension system.
        #djd.dampingRatio = 0.5
        #djd.frequencyHz = 10.0
        # svn r149, not usable yet
        
        djd.Initialize(body1, body2, p2 + self.m_offset, p5 + self.m_offset)
        self.world.CreateJoint(djd).getAsType() 
        
        djd.Initialize(body1, body2, p3 + self.m_offset, p4 + self.m_offset)
        self.world.CreateJoint(djd).getAsType() 
        
        djd.Initialize(body1, self.m_wheel, p3 + self.m_offset, wheelAnchor + self.m_offset)
        self.world.CreateJoint(djd).getAsType() 
        
        djd.Initialize(body2, self.m_wheel, p6 + self.m_offset, wheelAnchor + self.m_offset)
        self.world.CreateJoint(djd).getAsType() 
        
        rjd=box2d.b2RevoluteJointDef() 
        
        rjd.Initialize(body2, self.m_chassis, p4 + self.m_offset)
        self.world.CreateJoint(rjd).getAsType() 
示例#14
0
 def __init__(self):
     super(TheoJansen, self).__init__()
     self.m_offset.Set(0.0, 8.0)
     self.m_motorSpeed = 2.0
     self.m_motorOn = True
     pivot=box2d.b2Vec2(0.0, 0.8)
     
     sd=box2d.b2PolygonDef() 
     sd.SetAsBox(50.0, 10.0)
     
     bd=box2d.b2BodyDef() 
     bd.position.Set(0.0, -10.0)
     ground = self.world.CreateBody(bd) 
     ground.CreateShape(sd)
     
     sd.SetAsBox(0.5, 5.0, box2d.b2Vec2(-50.0, 15.0), 0.0)
     ground.CreateShape(sd)
     
     sd.SetAsBox(0.5, 5.0, box2d.b2Vec2(50.0, 15.0), 0.0)
     ground.CreateShape(sd)
     
     for i in range(40):
         sd = box2d.b2CircleDef()
         sd.density = 1.0
         sd.radius = 0.25
         
         bd=box2d.b2BodyDef() 
         bd.position.Set(-40.0 + 2.0 * i, 0.5)
         
         body = self.world.CreateBody(bd) 
         body.CreateShape(sd)
         body.SetMassFromShapes()
     
     sd=box2d.b2PolygonDef() 
     sd.density = 1.0
     sd.SetAsBox(2.5, 1.0)
     sd.filter.groupIndex = -1
     bd=box2d.b2BodyDef() 
     bd.position = pivot + self.m_offset
     self.m_chassis = self.world.CreateBody(bd)
     self.m_chassis.CreateShape(sd)
     self.m_chassis.SetMassFromShapes()
     
     sd = box2d.b2CircleDef()
     sd.density = 1.0
     sd.radius = 1.6
     sd.filter.groupIndex = -1
     bd=box2d.b2BodyDef() 
     bd.position = pivot + self.m_offset
     self.m_wheel = self.world.CreateBody(bd)
     self.m_wheel.CreateShape(sd)
     self.m_wheel.SetMassFromShapes()
 
     jd=box2d.b2RevoluteJointDef() 
     jd.Initialize(self.m_wheel, self.m_chassis, pivot + self.m_offset)
     jd.collideConnected = False
     jd.motorSpeed = self.m_motorSpeed
     jd.maxMotorTorque = 400.0
     jd.enableMotor = self.m_motorOn
     self.m_motorJoint = self.world.CreateJoint(jd).getAsType()
 
     wheelAnchor = pivot + box2d.b2Vec2(0.0, -0.8)
     
     self.CreateLeg(-1.0, wheelAnchor)
     self.CreateLeg(1.0, wheelAnchor)
     
     self.m_wheel.SetXForm(self.m_wheel.GetPosition(), 120.0 * box2d.b2_pi / 180.0)
     self.CreateLeg(-1.0, wheelAnchor)
     self.CreateLeg(1.0, wheelAnchor)
     
     self.m_wheel.SetXForm(self.m_wheel.GetPosition(), -120.0 * box2d.b2_pi / 180.0)
     self.CreateLeg(-1.0, wheelAnchor)
     self.CreateLeg(1.0, wheelAnchor)
示例#15
0
    def __init__(self):
        super(ElasticBody, self).__init__()

        bodies = self.bodies
        for i in range(64):
            bodies.append(None)
        # Bottom static body
        sd = box2d.b2PolygonDef()
        sd.SetAsBox(50.0, 2.0)
        sd.friction = 0.1
        sd.restitution = 0.1
        bd = box2d.b2BodyDef()
        bd.position.Set(-1.0, -7.5)
        self.m_ground = self.world.CreateBody(bd)
        self.m_ground.CreateShape(sd)
        # Upper static body
        sd = box2d.b2PolygonDef()
        sd.SetAsBox(20.0, 0.50, box2d.b2Vec2(0, 0), 0.047 * box2d.b2_pi)
        sd.friction = 0.01
        sd.restitution = 0.001
        bd = box2d.b2BodyDef()
        bd.position.Set(-20, 93.0)
        g = self.world.CreateBody(bd)
        g.CreateShape(sd)
        sd.SetAsBox(15, 0.50, box2d.b2Vec2(-15.0, 12.5), 0.0)
        g.CreateShape(sd)

        sd.SetAsBox(20, 0.5, box2d.b2Vec2(0.0, -25.0), -0.5)
        g.CreateShape(sd)
        # Left channel left wall
        sd = box2d.b2PolygonDef()
        sd.SetAsBox(0.7, 55.0)
        sd.friction = 0.1
        sd.restitution = 0.1
        bd = box2d.b2BodyDef()
        bd.position.Set(-49.3, 50.0)
        g = self.world.CreateBody(bd)
        g.CreateShape(sd)
        # Right wall
        sd = box2d.b2PolygonDef()
        sd.SetAsBox(0.7, 55.0)
        sd.friction = 0.1
        sd.restitution = 0.1
        bd = box2d.b2BodyDef()
        bd.position.Set(45, 50.0)
        g = self.world.CreateBody(bd)
        g.CreateShape(sd)
        # Left channel right upper wall
        sd = box2d.b2PolygonDef()
        sd.SetAsBox(0.5, 20.0)
        sd.friction = 0.05
        sd.restitution = 0.01
        bd = box2d.b2BodyDef()
        bd.position.Set(-42.0, 70.0)
        bd.angle = -0.03 * box2d.b2_pi
        g = self.world.CreateBody(bd)
        g.CreateShape(sd)
        # Left channel right lower wall
        sd = box2d.b2PolygonDef()
        sd.SetAsBox(0.50, 23.0)
        sd.friction = 0.05
        sd.restitution = 0.01
        bd = box2d.b2BodyDef()
        bd.position.Set(-44.0, 27.0)
        g = self.world.CreateBody(bd)
        g.CreateShape(sd)
        # Bottom motors
        cd = box2d.b2CircleDef()
        cd.radius = 3.0
        cd.density = 15.0
        cd.friction = 1
        cd.restitution = 0.2
        # 1.
        bd.position.Set(-40.0, 2.5)
        body = self.world.CreateBody(bd)
        body.CreateShape(cd)
        body.SetMassFromShapes()
        jr = box2d.b2RevoluteJointDef()
        jr.Initialize(g, body, body.GetWorldCenter() + box2d.b2Vec2(0, 1))
        jr.maxMotorTorque = 30000
        jr.enableMotor = True
        jr.motorSpeed = 20
        self.world.CreateJoint(jr).getAsType()
        # 1. left down
        bd.position.Set(-46.0, -2.5)
        cd.radius = 1.5
        jr.motorSpeed = -20
        body = self.world.CreateBody(bd)
        body.CreateShape(cd)
        sd.SetAsBox(2.0, 0.50)
        body.CreateShape(sd)
        body.SetMassFromShapes()
        jr.Initialize(g, body, body.GetWorldCenter())
        self.world.CreateJoint(jr).getAsType()
        # 2.
        cd.radius = 3.0
        jr.motorSpeed = 20
        bd.position.Set(-32.0, 2.5)
        body = self.world.CreateBody(bd)
        body.CreateShape(cd)
        body.SetMassFromShapes()
        jr.Initialize(g, body, body.GetWorldCenter() + box2d.b2Vec2(0, 1))
        self.world.CreateJoint(jr).getAsType()
        # 3.
        jr.motorSpeed = 20
        bd.position.Set(-24.0, 1.5)
        body = self.world.CreateBody(bd)
        body.CreateShape(cd)
        body.SetMassFromShapes()
        jr.Initialize(g, body, body.GetWorldCenter() + box2d.b2Vec2(0, 1))
        self.world.CreateJoint(jr).getAsType()
        # 4.
        bd.position.Set(-16.0, 0.8)
        body = self.world.CreateBody(bd)
        body.CreateShape(cd)
        body.SetMassFromShapes()
        jr.Initialize(g, body, body.GetWorldCenter() + box2d.b2Vec2(0, 1))
        self.world.CreateJoint(jr).getAsType()
        # 5.
        bd.position.Set(-8.0, 0.5)
        body = self.world.CreateBody(bd)
        body.CreateShape(cd)
        body.SetMassFromShapes()
        jr.Initialize(g, body, body.GetWorldCenter() + box2d.b2Vec2(0, 1))
        self.world.CreateJoint(jr).getAsType()
        # 6.
        bd.position.Set(0.0, 0.1)
        body = self.world.CreateBody(bd)
        body.CreateShape(cd)
        body.SetMassFromShapes()
        jr.Initialize(g, body, body.GetWorldCenter() + box2d.b2Vec2(0, 1))
        self.world.CreateJoint(jr).getAsType()
        # 7.
        bd.position.Set(8.0, -0.5)
        body = self.world.CreateBody(bd)
        body.CreateShape(cd)
        sd.SetAsBox(3.7, 0.5)
        body.CreateShape(sd)
        body.SetMassFromShapes()
        jr.Initialize(g, body, body.GetWorldCenter() + box2d.b2Vec2(0, 1))
        self.world.CreateJoint(jr).getAsType()
        # 8. right rotator
        sd.SetAsBox(5, 0.5)
        sd.density = 2.0
        bd.position.Set(18.0, 1)
        rightmotor = self.world.CreateBody(bd)  #
        rightmotor.CreateShape(sd)
        sd.SetAsBox(4.5, 0.5, box2d.b2Vec2(0, 0), box2d.b2_pi / 3)
        rightmotor.CreateShape(sd)
        sd.SetAsBox(4.5, 0.5, box2d.b2Vec2(0, 0), box2d.b2_pi * 2 / 3)
        rightmotor.CreateShape(sd)
        cd.radius = 4.2
        rightmotor.CreateShape(cd)
        rightmotor.SetMassFromShapes()
        jr.Initialize(g, rightmotor, rightmotor.GetWorldCenter())
        jr.maxMotorTorque = 70000
        jr.motorSpeed = -4
        self.world.CreateJoint(jr).getAsType()
        # 9. left rotator
        sd.SetAsBox(8.5, 0.5)
        sd.density = 2.0
        bd.position.Set(-34.0, 17)
        body = self.world.CreateBody(bd)
        body.CreateShape(sd)
        sd.SetAsBox(8.5, 0.5, box2d.b2Vec2(0, 0), box2d.b2_pi * 0.5)
        body.CreateShape(sd)
        cd.radius = 7
        cd.friction = 0.9
        body.CreateShape(cd)
        body.SetMassFromShapes()
        jr.Initialize(g, body, body.GetWorldCenter())
        jr.maxMotorTorque = 100000
        jr.motorSpeed = -5
        self.world.CreateJoint(jr).getAsType()
        # big compressor
        sd.SetAsBox(3.0, 4)
        sd.density = 10.0
        bd.position.Set(-16.0, 17)
        hammerleft = self.world.CreateBody(bd)
        hammerleft.CreateShape(sd)
        hammerleft.SetMassFromShapes()
        jd = box2d.b2DistanceJointDef()
        jd.Initialize(body, hammerleft, body.GetWorldCenter() + box2d.b2Vec2(0, 6), hammerleft.GetWorldCenter())
        self.world.CreateJoint(jd).getAsType()

        bd.position.Set(4.0, 17)
        hammerright = self.world.CreateBody(bd)
        hammerright.CreateShape(sd)
        hammerright.SetMassFromShapes()
        jd.Initialize(body, hammerright, body.GetWorldCenter() - box2d.b2Vec2(0, 6), hammerright.GetWorldCenter())
        self.world.CreateJoint(jd).getAsType()
        # pusher
        sd.SetAsBox(6, 0.75)
        bd.position.Set(-21.0, 9)
        pusher = self.world.CreateBody(bd)  #
        pusher.CreateShape(sd)
        sd.SetAsBox(2, 1.5, box2d.b2Vec2(-5, 0), 0)
        pusher.SetMassFromShapes()
        pusher.CreateShape(sd)
        jd.Initialize(
            rightmotor,
            pusher,
            rightmotor.GetWorldCenter() + box2d.b2Vec2(-8.0, 0),
            pusher.GetWorldCenter() + box2d.b2Vec2(5.0, 0),
        )
        self.world.CreateJoint(jd).getAsType()
        # Static bodies above motors
        sd = box2d.b2PolygonDef()
        cd = box2d.b2CircleDef()
        sd.SetAsBox(9.0, 0.5)
        sd.friction = 0.05
        sd.restitution = 0.01
        bd = box2d.b2BodyDef()
        bd.position.Set(-15.5, 12)
        bd.angle = 0.0
        g = self.world.CreateBody(bd)
        g.CreateShape(sd)

        sd.SetAsBox(8, 0.5, box2d.b2Vec2(23, 0), 0)
        g.CreateShape(sd)
        # compressor statics
        sd.SetAsBox(7.0, 0.5, box2d.b2Vec2(-2, 9), 0)
        g.CreateShape(sd)
        sd.SetAsBox(9.0, 0.5, box2d.b2Vec2(22, 9), 0)
        g.CreateShape(sd)

        sd.SetAsBox(19.0, 0.5, box2d.b2Vec2(-9, 15), -0.05)
        g.CreateShape(sd)
        sd.SetAsBox(4.7, 0.5, box2d.b2Vec2(15, 11.5), -0.5)
        g.CreateShape(sd)
        # below compressor
        sd.SetAsBox(26.0, 0.3, box2d.b2Vec2(17, -4.4), -0.02)
        g.CreateShape(sd)
        cd.radius = 1.0
        cd.friction = 1.0
        cd.localPosition = box2d.b2Vec2(29, -6)
        g.CreateShape(cd)
        cd.radius = 0.7
        cd.localPosition = box2d.b2Vec2(-2, -4.5)
        g.CreateShape(cd)
        # Elevator
        bd = box2d.b2BodyDef()
        cd = box2d.b2CircleDef()
        sd = box2d.b2PolygonDef()

        bd.position.Set(40.0, 4.0)
        self.m_elev = self.world.CreateBody(bd)

        sd.SetAsBox(0.5, 2.5, box2d.b2Vec2(3.0, -3.0), 0)
        sd.density = 1
        sd.friction = 0.01
        self.m_elev.CreateShape(sd)
        sd.SetAsBox(7.0, 0.5, box2d.b2Vec2(-3.5, -5.5), 0)
        self.m_elev.CreateShape(sd)
        sd.SetAsBox(0.5, 2.5, box2d.b2Vec2(-11, -3.5), 0)
        self.m_elev.CreateShape(sd)
        self.m_elev.SetMassFromShapes()

        jp = box2d.b2PrismaticJointDef()
        jp.Initialize(self.m_ground, self.m_elev, bd.position, box2d.b2Vec2(0.0, 1.0))
        jp.lowerTranslation = 0.0
        jp.upperTranslation = 100.0
        jp.enableLimit = True
        jp.enableMotor = True
        jp.maxMotorForce = 10000
        jp.motorSpeed = 0
        self.m_joint_elev = self.world.CreateJoint(jp).getAsType()

        # Korb
        sd.SetAsBox(2.3, 0.5, box2d.b2Vec2(1, 0.0), 0.0)
        sd.density = 0.5
        bd.position.Set(29.0, 6.5)
        body = self.world.CreateBody(bd)  #
        body.CreateShape(sd)
        sd.SetAsBox(2.5, 0.5, box2d.b2Vec2(3.0, -2), box2d.b2_pi / 2)
        body.CreateShape(sd)
        sd.SetAsBox(4.6, 0.5, box2d.b2Vec2(7.8, -4.0), 0)
        body.CreateShape(sd)
        sd.SetAsBox(0.5, 4.5, box2d.b2Vec2(12, 0.0), 0)
        body.CreateShape(sd)

        sd.SetAsBox(0.5, 0.5, box2d.b2Vec2(13, 4.0), 0)
        body.CreateShape(sd)

        cd.radius = 0.7
        cd.density = 1
        cd.friction = 0.01
        cd.localPosition = box2d.b2Vec2(0, 0)
        body.CreateShape(cd)
        body.SetMassFromShapes()

        jr = box2d.b2RevoluteJointDef()
        jr.Initialize(self.m_elev, body, bd.position)
        jr.enableLimit = True
        jr.lowerAngle = -0.2
        jr.upperAngle = box2d.b2_pi * 1.1
        jr.collideConnected = True
        self.world.CreateJoint(jr).getAsType()
        # upper body exit
        sd.SetAsBox(14.0, 0.5, box2d.b2Vec2(-3.5, -10.0), 0.0)
        bd.position.Set(17.5, 96.0)
        body = self.world.CreateBody(bd)
        body.CreateShape(sd)
        # "Elastic body" 64 bodies - something like a lin. elastic compound
        # connected via dynamic forces (springs)
        sd = box2d.b2PolygonDef()
        sd.SetAsBox(0.55, 0.55)
        sd.density = 1.5
        sd.friction = 0.01
        sd.filter.groupIndex = -1
        startpoint = box2d.b2Vec2(30, 20)
        bd = box2d.b2BodyDef()
        bd.isBullet = False
        bd.allowSleep = False
        for i in range(8):
            for j in range(8):
                bd.position.Set(j * 1.02, 2.51 + 1.02 * i)
                bd.position += startpoint
                body = self.world.CreateBody(bd)  #
                bodies[8 * i + j] = body
                body.CreateShape(sd)
                body.SetMassFromShapes()
示例#16
0
    def __init__(self):
        super(MotorsAndLimits, self).__init__()
        sd=box2d.b2PolygonDef() 
        sd.SetAsBox(50.0, 10.0)

        bd=box2d.b2BodyDef() 
        bd.position.Set(0.0, -10.0)
        ground = self.world.CreateBody(bd)
        ground.CreateShape(sd)

        sd=box2d.b2PolygonDef() 
        sd.SetAsBox(2.0, 0.5)
        sd.density = 5.0
        sd.friction = 0.05

        bd=box2d.b2BodyDef() 

        rjd=box2d.b2RevoluteJointDef() 

        prevBody=ground
        y = 8.0

        bd.position.Set(3.0, y)
        body = self.world.CreateBody(bd)
        body.CreateShape(sd)
        body.SetMassFromShapes()

        rjd.Initialize(prevBody, body, box2d.b2Vec2(0.0, y))
        rjd.motorSpeed = 1.0 * box2d.b2_pi
        rjd.maxMotorTorque = 10000.0
        rjd.enableMotor = True

        self.m_joint1 = self.world.CreateJoint(rjd).getAsType()

        prevBody = body

        bd.position.Set(9.0, y)
        body = self.world.CreateBody(bd)
        body.CreateShape(sd)
        body.SetMassFromShapes()

        rjd.Initialize(prevBody, body, box2d.b2Vec2(6.0, y))
        rjd.motorSpeed = 0.5 * box2d.b2_pi
        rjd.maxMotorTorque = 2000.0
        rjd.enableMotor = True
        rjd.lowerAngle = - 0.5 * box2d.b2_pi
        rjd.upperAngle = 0.5 * box2d.b2_pi
        rjd.enableLimit = True

        self.m_joint2 = self.world.CreateJoint(rjd).getAsType()

        bd.position.Set(-10.0, 10.0)
        bd.angle = 0.5 * box2d.b2_pi
        body = self.world.CreateBody(bd)
        body.CreateShape(sd)
        body.SetMassFromShapes()

        pjd=box2d.b2PrismaticJointDef() 
        pjd.Initialize(ground, body, box2d.b2Vec2(-10.0, 10.0), box2d.b2Vec2(1.0, 0.0))
        pjd.motorSpeed = 10.0
        pjd.maxMotorForce = 1000.0
        pjd.enableMotor = True
        pjd.lowerTranslation = 0.0
        pjd.upperTranslation = 20.0
        pjd.enableLimit = True

        self.m_joint3 = self.world.CreateJoint(pjd).getAsType()
示例#17
0
    def __init__(self):
        super(Car, self).__init__()
        # car body
        poly1=box2d.b2PolygonDef()
        poly2=box2d.b2PolygonDef()

        # bottom half
        poly1.vertexCount = 5
        poly1.setVertex(4,-2.2,-0.74)
        poly1.setVertex(3,-2.2,0)
        poly1.setVertex(2,1.0,0)
        poly1.setVertex(1,2.2,-0.2)
        poly1.setVertex(0,2.2,-0.74)
        poly1.filter.groupIndex = -1

        poly1.density		= 20.0
        poly1.friction		= 0.68
        poly1.filter.groupIndex	= -1

        # top half
        poly2.vertexCount = 4
        poly2.setVertex(3,-1.7,0)
        poly2.setVertex(2,-1.3,0.7)
        poly2.setVertex(1,0.5,0.74)
        poly2.setVertex(0,1.0,0)
        poly2.filter.groupIndex = -1

        poly2.density		= 5.0
        poly2.friction		= 0.68
        poly2.filter.groupIndex	= -1

        bd=box2d.b2BodyDef() 
        bd.position.Set(-35.0, 2.8)

        self.m_vehicle = self.world.CreateBody(bd)
        self.m_vehicle.CreateShape(poly1)
        self.m_vehicle.CreateShape(poly2)
        self.m_vehicle.SetMassFromShapes()

        # vehicle wheels
        circ = box2d.b2CircleDef()
        circ.density = 40.0
        circ.radius = 0.38608
        circ.friction = 0.8
        circ.filter.groupIndex = -1

        bd=box2d.b2BodyDef() 
        bd.allowSleep = False
        bd.position.Set(-33.8, 2.0)

        self.m_rightWheel = self.world.CreateBody(bd)
        self.m_rightWheel.CreateShape(circ)
        self.m_rightWheel.SetMassFromShapes()

        bd.position.Set(-36.2, 2.0)
        self.m_leftWheel = self.world.CreateBody(bd)
        self.m_leftWheel.CreateShape(circ)
        self.m_leftWheel.SetMassFromShapes()

        # join wheels to chassis
        anchor=box2d.b2Vec2() 
        jd=box2d.b2RevoluteJointDef() 
        jd.Initialize(self.m_vehicle, self.m_leftWheel, self.m_leftWheel.GetWorldCenter())
        jd.collideConnected = False
        jd.enableMotor = True
        jd.maxMotorTorque = 10.0
        jd.motorSpeed = 0.0
        self.m_leftJoint = self.world.CreateJoint(jd).getAsType() 

        jd.Initialize(self.m_vehicle, self.m_rightWheel, self.m_rightWheel.GetWorldCenter())
        jd.collideConnected = False
        self.m_rightJoint = self.world.CreateJoint(jd).getAsType() 

        # ground
        box=box2d.b2PolygonDef() 
        box.SetAsBox(19.5, 0.5)
        box.friction = 0.62

        bd=box2d.b2BodyDef() 
        bd.position.Set(-25.0, 1.0)

        ground = self.world.CreateBody(bd) 
        ground.CreateShape(box)

        # more ground
        box=box2d.b2PolygonDef() 
        bd=box2d.b2BodyDef() 

        box.SetAsBox(9.5, 0.5, box2d.b2Vec2_zero, 0.1 * box2d.b2_pi)
        box.friction = 0.62
        bd.position.Set(27.0 - 30.0, 3.1)

        ground = self.world.CreateBody(bd) 
        ground.CreateShape(box)

        # more ground
        box=box2d.b2PolygonDef() 
        bd=box2d.b2BodyDef() 

        box.SetAsBox(9.5, 0.5, box2d.b2Vec2_zero, -0.1 * box2d.b2_pi)
        box.friction = 0.62
        bd.position.Set(55.0 - 30.0, 3.1)

        ground = self.world.CreateBody(bd) 
        ground.CreateShape(box)

        # more ground
        box=box2d.b2PolygonDef() 
        bd=box2d.b2BodyDef() 

        box.SetAsBox(9.5, 0.5, box2d.b2Vec2_zero, 0.03 * box2d.b2_pi)
        box.friction = 0.62
        bd.position.Set(41.0, 2.0)

        ground = self.world.CreateBody(bd) 
        ground.CreateShape(box)

        # more ground
        box=box2d.b2PolygonDef() 
        bd=box2d.b2BodyDef() 

        box.SetAsBox(5.0, 0.5, box2d.b2Vec2_zero, 0.15 * box2d.b2_pi)
        box.friction = 0.62
        bd.position.Set(50.0, 4.0)

        ground = self.world.CreateBody(bd) 
        ground.CreateShape(box)

        # more ground
        box=box2d.b2PolygonDef() 
        bd=box2d.b2BodyDef() 

        box.SetAsBox(20.0, 0.5)
        box.friction = 0.62
        bd.position.Set(85.0, 2.0)

        ground = self.world.CreateBody(bd) 
        ground.CreateShape(box)
示例#18
0
    def __init__(self):
        super(PolyShapes, self).__init__()
        # Ground body
        sds = self.sds

        sd=box2d.b2PolygonDef() 
        sd.SetAsBox(50.0, 10.0)
        sd.friction = 0.3
        sd.filter.categoryBits = 0x0001

        for i in range(4):
            sds.append(box2d.b2PolygonDef())

        bd=box2d.b2BodyDef() 
        bd.position.Set(0.0, -10.0)
        ground = self.world.CreateBody(bd) 
        ground.CreateShape(sd)
        sds[0].vertexCount = 3
        sds[0].setVertex(0,-0.5, 0.0)
        sds[0].setVertex(1,0.5, 0.0)
        sds[0].setVertex(2,0.0, 1.5)
        sds[0].density = 1.0
        sds[0].friction = 0.3
        sds[0].filter.categoryBits = 0x0002
        #sds[0].maskBits = 0x0003

        sds[1].vertexCount = 3
        sds[1].setVertex(0,-0.1, 0.0)
        sds[1].setVertex(1,0.1, 0.0)
        sds[1].setVertex(2,0.0, 1.5)
        sds[1].density = 1.0
        sds[1].friction = 0.3
        sds[1].filter.categoryBits = 0x0004

        sds[2].vertexCount = 8
        w = 1.0
        b = w / (2.0 + math.sqrt(2.0))
        s = math.sqrt(2.0) * b
        sds[2].setVertex(0,0.5 * s, 0.0)
        sds[2].setVertex(1,0.5 * w, b)
        sds[2].setVertex(2,0.5 * w, b + s)
        sds[2].setVertex(3,0.5 * s, w)
        sds[2].setVertex(4,-0.5 * s, w)
        sds[2].setVertex(5,-0.5 * w, b + s)
        sds[2].setVertex(6,-0.5 * w, b)
        sds[2].setVertex(7,-0.5 * s, 0.0)
        sds[2].density = 1.0
        sds[2].friction = 0.3
        sds[2].filter.categoryBits = 0x0004

        #sds[3].SetAsBox(15.0, 15.0) # svn r153
        sds[3].vertexCount = 4
        sds[3].setVertex(0,-0.5, 0.0)
        sds[3].setVertex(1,0.5, 0.0)
        sds[3].setVertex(2,0.5, 1.0)
        sds[3].setVertex(3,-0.5, 1.0)
        sds[3].density = 1.0
        sds[3].friction = 0.3
        sds[3].filter.categoryBits = 0x0004

        self.circleDef.radius = 0.5
        self.circleDef.density = 1.0

        self.bodyIndex = 0
    def __init__(self):
        super(CollisionFiltering, self).__init__()
        # Ground body
        sd=box2d.b2PolygonDef()
        sd.SetAsBox(50.0, 10.0)
        sd.friction = 0.3

        bd=box2d.b2BodyDef()
        bd.position.Set(0.0, -10.0)

        ground = self.world.CreateBody(bd)
        ground.CreateShape(sd)

        # Small triangle
        triangleShapeDef=box2d.b2PolygonDef()
        triangleShapeDef.vertexCount = 3
        triangleShapeDef.setVertex(0,-1.0, 0.0)
        triangleShapeDef.setVertex(1,1.0, 0.0)
        triangleShapeDef.setVertex(2,0.0, 2.0)
        triangleShapeDef.density = 1.0

        triangleShapeDef.filter.groupIndex = self.k_smallGroup
        triangleShapeDef.filter.categoryBits = self.k_triangleCategory
        triangleShapeDef.filter.maskBits = self.k_triangleMask

        triangleBodyDef=box2d.b2BodyDef()
        triangleBodyDef.position.Set(-5.0, 2.0)

        body1 = self.world.CreateBody(triangleBodyDef)
        body1.CreateShape(triangleShapeDef)
        body1.SetMassFromShapes()

        # Large triangle (recycle definitions)
        triangleShapeDef.setVertex(0, 2.0*triangleShapeDef.getVertex(0))
        triangleShapeDef.setVertex(1, 2.0*triangleShapeDef.getVertex(1))
        triangleShapeDef.setVertex(2, 2.0*triangleShapeDef.getVertex(2))
        triangleShapeDef.filter.groupIndex = self.k_largeGroup
        triangleBodyDef.position.Set(-5.0, 6.0)
        triangleBodyDef.fixedRotation = True

        body2 = self.world.CreateBody(triangleBodyDef)
        body2.CreateShape(triangleShapeDef)
        body2.SetMassFromShapes()

        # Small box
        boxShapeDef=box2d.b2PolygonDef()
        boxShapeDef.SetAsBox(1.0, 0.5)
        boxShapeDef.density = 1.0

        boxShapeDef.filter.groupIndex = self.k_smallGroup
        boxShapeDef.filter.categoryBits = self.k_boxCategory
        boxShapeDef.filter.maskBits = self.k_boxMask

        boxBodyDef=box2d.b2BodyDef()
        boxBodyDef.position.Set(0.0, 2.0)

        body3 = self.world.CreateBody(boxBodyDef)
        body3.CreateShape(boxShapeDef)
        body3.SetMassFromShapes()

        # Large box (recycle definitions)
        boxShapeDef.SetAsBox(2.0, 1.0)
        boxShapeDef.filter.groupIndex = self.k_largeGroup
        boxBodyDef.position.Set(0.0, 6.0)

        body4 = self.world.CreateBody(boxBodyDef)
        body4.CreateShape(boxShapeDef)
        body4.SetMassFromShapes()

        # Small circle
        circleShapeDef=box2d.b2CircleDef()
        circleShapeDef.radius = 1.0
        circleShapeDef.density = 1.0

        circleShapeDef.filter.groupIndex = self.k_smallGroup
        circleShapeDef.filter.categoryBits = self.k_circleCategory
        circleShapeDef.filter.maskBits = self.k_circleMask

        circleBodyDef=box2d.b2BodyDef()
        circleBodyDef.position.Set(5.0, 2.0)

        body5 = self.world.CreateBody(circleBodyDef)
        body5.CreateShape(circleShapeDef)
        body5.SetMassFromShapes()

        # Large circle
        circleShapeDef.radius *= 2.0
        circleShapeDef.filter.groupIndex = self.k_largeGroup
        circleBodyDef.position.Set(5.0, 6.0)

        body6 = self.world.CreateBody(circleBodyDef)
        body6.CreateShape(circleShapeDef)
        body6.SetMassFromShapes()
示例#20
0
    def __init__(self):
        super(Bridge, self).__init__()
        
        sd = box2d.b2PolygonDef()
        sd.SetAsBox(50.0, 10.0)

        bd = box2d.b2BodyDef()
        bd.position.Set(0.0, -10.0)
        ground = self.world.CreateBody(bd)
        ground.CreateShape(sd)

        sd = box2d.b2PolygonDef()        
        sd.SetAsBox(0.5, 0.125)
        sd.density = 20.0
        sd.friction = 0.2

        jd = box2d.b2RevoluteJointDef()
        numPlanks = 30

        prevBody = ground
        for i in range(numPlanks):
            bd = box2d.b2BodyDef()
            bd.position.Set(-14.5 + 1.0 * i, 5.0)

            body = self.world.CreateBody(bd)
            body.CreateShape(sd)
            body.SetMassFromShapes()

            anchor=box2d.b2Vec2(-15.0 + 1.0 * i, 5.0)
            jd.Initialize(prevBody, body, anchor)
            self.world.CreateJoint(jd)

            prevBody = body

        anchor = box2d.b2Vec2(-15.0 + 1.0 * numPlanks, 5.0)
        jd.Initialize(prevBody, ground, anchor)
        self.world.CreateJoint(jd)

        for i in range(2):
            sd=box2d.b2PolygonDef()
            sd.vertexCount = 3
            sd.setVertex(0,-0.5, 0.0)
            sd.setVertex(1,0.5, 0.0)
            sd.setVertex(2,0.0, 1.5)
            sd.density = 1.0

            bd=box2d.b2BodyDef()
            bd.position.Set(-8.0 + 8.0 * i, 12.0)
            body = self.world.CreateBody(bd)
            body.CreateShape(sd)
            body.SetMassFromShapes()

        for i in range(3):
            sd=box2d.b2CircleDef()
            sd.radius = 0.5
            sd.density = 1.0

            bd=box2d.b2BodyDef()
            bd.position.Set(-6.0 + 6.0 * i, 10.0)
            body = self.world.CreateBody(bd)
            body.CreateShape(sd)
            body.SetMassFromShapes()
    def __init__(self):
        super(ContactCallbackTest, self).__init__()

        sd=box2d.b2PolygonDef() 
        sd.friction = 0
        sd.vertexCount = 3
        sd.setVertex(0,10,10)
        sd.setVertex(1,9,7)
        sd.setVertex(2,10,0)
        self.world.GetGroundBody().CreateShape(sd)

        sd.setVertex(0,9,7)
        sd.setVertex(1,8,0)
        sd.setVertex(2,10,0)
        self.world.GetGroundBody().CreateShape(sd)

        sd.setVertex(0,9,7)
        sd.setVertex(1,8,5)
        sd.setVertex(2,8,0)
        self.world.GetGroundBody().CreateShape(sd)

        sd.setVertex(0,8,5)
        sd.setVertex(1,7,4)
        sd.setVertex(2,8,0)
        self.world.GetGroundBody().CreateShape(sd)

        sd.setVertex(0,7,4)
        sd.setVertex(1,5,0)
        sd.setVertex(2,8,0)
        self.world.GetGroundBody().CreateShape(sd)

        sd.setVertex(0,7,4)
        sd.setVertex(1,5,3)
        sd.setVertex(2,5,0)
        self.world.GetGroundBody().CreateShape(sd)

        sd.setVertex(0,5,3)
        sd.setVertex(1,2,2)
        sd.setVertex(2,5,0)
        self.world.GetGroundBody().CreateShape(sd)

        sd.setVertex(0,2,2)
        sd.setVertex(1,0,0)
        sd.setVertex(2,5,0)
        self.world.GetGroundBody().CreateShape(sd)

        sd.setVertex(0,2,2)
        sd.setVertex(1,-2,2)
        sd.setVertex(2,0,0)
        self.world.GetGroundBody().CreateShape(sd)

        sd.setVertex(2,-2,2)
        sd.setVertex(1,0,0)
        sd.setVertex(0,-5,0)
        self.world.GetGroundBody().CreateShape(sd)

        sd.setVertex(2,-5,3)
        sd.setVertex(1,-2,2)
        sd.setVertex(0,-5,0)
        self.world.GetGroundBody().CreateShape(sd)

        sd.setVertex(2,-7,4)
        sd.setVertex(1,-5,3)
        sd.setVertex(0,-5,0)
        self.world.GetGroundBody().CreateShape(sd)

        sd.setVertex(2,-7,4)
        sd.setVertex(1,-5,0)
        sd.setVertex(0,-8,0)
        self.world.GetGroundBody().CreateShape(sd)

        sd.setVertex(2,-8,5)
        sd.setVertex(1,-7,4)
        sd.setVertex(0,-8,0)
        self.world.GetGroundBody().CreateShape(sd)

        sd.setVertex(2,-9,7)
        sd.setVertex(1,-8,5)
        sd.setVertex(0,-8,0)
        self.world.GetGroundBody().CreateShape(sd)

        sd.setVertex(2,-9,7)
        sd.setVertex(1,-8,0)
        sd.setVertex(0,-10,0)
        self.world.GetGroundBody().CreateShape(sd)

        sd.setVertex(2,-10,10)
        sd.setVertex(1,-9,7)
        sd.setVertex(0,-10,0)
        self.world.GetGroundBody().CreateShape(sd)

        sd.SetAsBox(.5,6,box2d.b2Vec2(10.5,6),0)
        self.world.GetGroundBody().CreateShape(sd)

        sd.SetAsBox(.5,6,box2d.b2Vec2(-10.5,6),0)
        self.world.GetGroundBody().CreateShape(sd)

        bd=box2d.b2BodyDef() 
        bd.position.Set(9.5,60)
        self.m_ball = self.world.CreateBody( bd ) 

        cd=box2d.b2PolygonDef() 
        cd.vertexCount = 8
        w = 1.0
        b = w / (2.0 + math.sqrt(2.0))
        s = math.sqrt(2.0) * b
        cd.setVertex(0,0.5 * s, 0.0)
        cd.setVertex(1,0.5 * w, b)
        cd.setVertex(2,0.5 * w, b + s)
        cd.setVertex(3,0.5 * s, w)
        cd.setVertex(4,-0.5 * s, w)
        cd.setVertex(5,-0.5 * w, b + s)
        cd.setVertex(6,-0.5 * w, b)
        cd.setVertex(7,-0.5 * s, 0.0)
        cd.density = 1.0

        self.m_ball_shape = self.m_ball.CreateShape(cd)
        self.m_ball.SetMassFromShapes()
    def __init__(self):
        super(CollisionProcessing, self).__init__()

        # Ground body
        sd=box2d.b2PolygonDef()
        sd.SetAsBox(50.0, 10.0)
        sd.friction = 0.3

        bd=box2d.b2BodyDef()
        bd.position.Set(0.0, -10.0)

        ground = self.world.CreateBody(bd)
        ground.CreateShape(sd)

        xLo = -5.0
        xHi = 5.0
        yLo = 2.0
        yHi = 35.0
        # Small triangle
        triangleShapeDef=box2d.b2PolygonDef()
        triangleShapeDef.vertexCount = 3
        triangleShapeDef.setVertex(0,-1.0, 0.0)
        triangleShapeDef.setVertex(1,1.0, 0.0)
        triangleShapeDef.setVertex(2,0.0, 2.0)
        triangleShapeDef.density = 1.0

        triangleBodyDef=box2d.b2BodyDef() 
        triangleBodyDef.position.Set(box2d.b2Random(xLo, xHi), box2d.b2Random(yLo, yHi))

        body1 = self.world.CreateBody(triangleBodyDef) 
        body1.CreateShape(triangleShapeDef)
        body1.SetMassFromShapes()

        # Large triangle (recycle definitions)
        triangleShapeDef.setVertex(0, 2.0*triangleShapeDef.getVertex(0))
        triangleShapeDef.setVertex(1, 2.0*triangleShapeDef.getVertex(1))
        triangleShapeDef.setVertex(2, 2.0*triangleShapeDef.getVertex(2))
        triangleBodyDef.position.Set(box2d.b2Random(xLo, xHi), box2d.b2Random(yLo, yHi))

        body2 = self.world.CreateBody(triangleBodyDef)
        body2.CreateShape(triangleShapeDef)
        body2.SetMassFromShapes()

        # Small box
        boxShapeDef=box2d.b2PolygonDef() 
        boxShapeDef.SetAsBox(1.0, 0.5)
        boxShapeDef.density = 1.0

        boxBodyDef=box2d.b2BodyDef() 
        boxBodyDef.position.Set(box2d.b2Random(xLo, xHi), box2d.b2Random(yLo, yHi))

        body3 = self.world.CreateBody(boxBodyDef) 
        body3.CreateShape(boxShapeDef)
        body3.SetMassFromShapes()

        # Large box (recycle definitions)
        boxShapeDef.SetAsBox(2.0, 1.0)
        boxBodyDef.position.Set(box2d.b2Random(xLo, xHi), box2d.b2Random(yLo, yHi))

        body4 = self.world.CreateBody(boxBodyDef)
        body4.CreateShape(boxShapeDef)
        body4.SetMassFromShapes()

        # Small circle
        circleShapeDef=box2d.b2CircleDef() 
        circleShapeDef.radius = 1.0
        circleShapeDef.density = 1.0

        circleBodyDef=box2d.b2BodyDef() 
        circleBodyDef.position.Set(box2d.b2Random(xLo, xHi), box2d.b2Random(yLo, yHi))

        body5 = self.world.CreateBody(circleBodyDef) 
        body5.CreateShape(circleShapeDef)
        body5.SetMassFromShapes()

        # Large circle
        circleShapeDef.radius *= 2.0
        circleBodyDef.position.Set(box2d.b2Random(xLo, xHi), box2d.b2Random(yLo, yHi))

        body6 = self.world.CreateBody(circleBodyDef) 
        body6.CreateShape(circleShapeDef)
        body6.SetMassFromShapes()
示例#23
0
    def __init__(self):
        super(SliderCrank, self).__init__()
        sd=box2d.b2PolygonDef() 
        sd.SetAsBox(50.0, 10.0)

        bd=box2d.b2BodyDef() 
        bd.position.Set(0.0, -10.0)
        ground = self.world.CreateBody(bd)
        ground.CreateShape(sd)

        # Define crank.
        sd=box2d.b2PolygonDef() 
        sd.SetAsBox(0.5, 2.0)
        sd.density = 1.0

        rjd=box2d.b2RevoluteJointDef() 

        prevBody=ground

        bd=box2d.b2BodyDef() 
        bd.position.Set(0.0, 7.0)
        body = self.world.CreateBody(bd) 
        body.CreateShape(sd)
        body.SetMassFromShapes()

        rjd.Initialize(prevBody, body, box2d.b2Vec2(0.0, 5.0))
        rjd.motorSpeed = 1.0 * box2d.b2_pi
        rjd.maxMotorTorque = 10000.0
        rjd.enableMotor = True
        self.m_joint1 = self.world.CreateJoint(rjd).getAsType()

        prevBody = body

        # Define follower.
        sd.SetAsBox(0.5, 4.0)
        bd.position.Set(0.0, 13.0)
        body = self.world.CreateBody(bd)
        body.CreateShape(sd)
        body.SetMassFromShapes()

        rjd.Initialize(prevBody, body, box2d.b2Vec2(0.0, 9.0))
        rjd.enableMotor = False
        self.world.CreateJoint(rjd).getAsType()

        prevBody = body

        # Define piston
        sd.SetAsBox(1.5, 1.5)
        bd.position.Set(0.0, 17.0)
        body = self.world.CreateBody(bd)
        body.CreateShape(sd)
        body.SetMassFromShapes()

        rjd.Initialize(prevBody, body, box2d.b2Vec2(0.0, 17.0))
        self.world.CreateJoint(rjd).getAsType()

        pjd=box2d.b2PrismaticJointDef() 
        pjd.Initialize(ground, body, box2d.b2Vec2(0.0, 17.0), box2d.b2Vec2(0.0, 1.0))

        pjd.maxMotorForce = 1000.0
        pjd.enableMotor = True

        self.m_joint2 = self.world.CreateJoint(pjd).getAsType()

        # Create a payload
        sd.density = 2.0
        bd.position.Set(0.0, 23.0)
        body = self.world.CreateBody(bd)
        body.CreateShape(sd)
        body.SetMassFromShapes()
示例#24
0
    def __init__(self):
        super(CompoundShapes, self).__init__()
        bd=box2d.b2BodyDef() 
        bd.position.Set(0.0, -10.0)
        body = self.world.CreateBody(bd) 

        sd=box2d.b2PolygonDef() 
        sd.SetAsBox(50.0, 10.0)
        body.CreateShape(sd)

        sd1=box2d.b2CircleDef() 
        sd1.radius = 0.5
        sd1.localPosition.Set(-0.5, 0.5)
        sd1.density = 2.0

        sd2=box2d.b2CircleDef() 
        sd2.radius = 0.5
        sd2.localPosition.Set(0.5, 0.5)
        sd2.density = 0.0 

        for i in range(10):
            x = box2d.b2Random(-0.1, 0.1)
            bd=box2d.b2BodyDef() 
            bd.position.Set(x + 5.0, 1.05 + 2.5 * i)
            bd.angle = box2d.b2Random(-box2d.b2_pi, box2d.b2_pi)
            body = self.world.CreateBody(bd) 
            body.CreateShape(sd1)
            body.CreateShape(sd2)
            body.SetMassFromShapes()

        sd1=box2d.b2PolygonDef() 
        sd1.SetAsBox(0.25, 0.5)
        sd1.density = 2.0

        sd2=box2d.b2PolygonDef() 
        sd2.SetAsBox(0.25, 0.5, box2d.b2Vec2(0.0, -0.5), 0.5 * box2d.b2_pi)
        sd2.density = 2.0

        for i in range(10):
            x = box2d.b2Random(-0.1, 0.1)
            bd=box2d.b2BodyDef() 
            bd.position.Set(x - 5.0, 1.05 + 2.5 * i)
            bd.angle = box2d.b2Random(-box2d.b2_pi, box2d.b2_pi)
            body = self.world.CreateBody(bd) 
            body.CreateShape(sd1)
            body.CreateShape(sd2)
            body.SetMassFromShapes()

        xf1 = box2d.b2XForm()
        xf1.R.Set(0.3524 * box2d.b2_pi)
        xf1.position = box2d.b2Mul(xf1.R, box2d.b2Vec2(1.0, 0.0))

        sd1=box2d.b2PolygonDef() 
        sd1.vertexCount = 3
        sd1.setVertex(0, box2d.b2Mul(xf1, box2d.b2Vec2(-1.0, 0.0)))
        sd1.setVertex(1, box2d.b2Mul(xf1, box2d.b2Vec2(1.0, 0.0)))
        sd1.setVertex(2, box2d.b2Mul(xf1, box2d.b2Vec2(0.0, 0.5)))
        sd1.density = 2.0

        xf2 = box2d.b2XForm()
        xf2.R.Set(-0.3524 * box2d.b2_pi)
        xf2.position = box2d.b2Mul(xf2.R, box2d.b2Vec2(-1.0, 0.0))

        sd2=box2d.b2PolygonDef() 
        sd2.vertexCount = 3
        sd2.setVertex(0, box2d.b2Mul(xf2, box2d.b2Vec2(-1.0, 0.0)))
        sd2.setVertex(1, box2d.b2Mul(xf2, box2d.b2Vec2(1.0, 0.0)))
        sd2.setVertex(2, box2d.b2Mul(xf2, box2d.b2Vec2(0.0, 0.5)))
        sd2.density = 2.0

        for i in range(10):
            x = box2d.b2Random(-0.1, 0.1)
            bd=box2d.b2BodyDef() 
            bd.position.Set(x, 2.05 + 2.5 * i)
            bd.angle = 0.0
            body = self.world.CreateBody(bd) 
            body.CreateShape(sd1)
            body.CreateShape(sd2)
            body.SetMassFromShapes()

        sd_bottom=box2d.b2PolygonDef() 
        sd_bottom.SetAsBox( 1.5, 0.15 )
        sd_bottom.density = 4.0

        sd_left=box2d.b2PolygonDef() 
        sd_left.SetAsBox(0.15, 2.7, box2d.b2Vec2(-1.45, 2.35), 0.2)
        sd_left.density = 4.0

        sd_right=box2d.b2PolygonDef() 
        sd_right.SetAsBox(0.15, 2.7, box2d.b2Vec2(1.45, 2.35), -0.2)
        sd_right.density = 4.0

        bd=box2d.b2BodyDef() 
        bd.position.Set( 0.0, 2.0 )
        body = self.world.CreateBody(bd) 
        body.CreateShape(sd_bottom)
        body.CreateShape(sd_left)
        body.CreateShape(sd_right)
        body.SetMassFromShapes()
示例#25
0
    def __init__(self):
        super(VaryingFriction, self).__init__()
        sd=box2d.b2PolygonDef() 
        sd.SetAsBox(50.0, 20.0)

        bd=box2d.b2BodyDef() 
        bd.position.Set(0.0, -20.0)
        ground = self.world.CreateBody(bd) 
        ground.CreateShape(sd)

        sd=box2d.b2PolygonDef() 
        sd.SetAsBox(13.0, 0.25)

        bd=box2d.b2BodyDef() 
        bd.position.Set(-4.0, 22.0)
        bd.angle = -0.25

        ground = self.world.CreateBody(bd) 
        ground.CreateShape(sd)

        sd=box2d.b2PolygonDef() 
        sd.SetAsBox(0.25, 1.0)

        bd=box2d.b2BodyDef() 
        bd.position.Set(10.5, 19.0)

        ground = self.world.CreateBody(bd) 
        ground.CreateShape(sd)

        sd=box2d.b2PolygonDef() 
        sd.SetAsBox(13.0, 0.25)

        bd=box2d.b2BodyDef() 
        bd.position.Set(4.0, 14.0)
        bd.angle = 0.25

        ground = self.world.CreateBody(bd) 
        ground.CreateShape(sd)

        sd=box2d.b2PolygonDef() 
        sd.SetAsBox(0.25, 1.0)

        bd=box2d.b2BodyDef() 
        bd.position.Set(-10.5, 11.0)

        ground = self.world.CreateBody(bd) 
        ground.CreateShape(sd)

        sd=box2d.b2PolygonDef() 
        sd.SetAsBox(13.0, 0.25)

        bd=box2d.b2BodyDef() 
        bd.position.Set(-4.0, 6.0)
        bd.angle = -0.25

        ground = self.world.CreateBody(bd) 
        ground.CreateShape(sd)

        sd=box2d.b2PolygonDef() 
        sd.SetAsBox(0.5, 0.5)
        sd.density = 25.0

        friction = [0.75, 0.5, 0.35, 0.1, 0.0]

        for i in range(5):
            bd=box2d.b2BodyDef() 
            bd.position.Set(-15.0 + 4.0 * i, 28.0)
            body = self.world.CreateBody(bd) 

            sd.friction = friction[i]
            body.CreateShape(sd)
            body.SetMassFromShapes()
示例#26
0
    def __init__(self):
        super(CCDTest, self).__init__()
        # Note that this test has a lot of commented-out versions that aren't implemented here.
        # See the original source code for more (Box2D/Examples/TestBed/Tests/CCDTest.h)
        k_restitution = 1.4

        bd=box2d.b2BodyDef()
        bd.position.Set(0.0, 20.0)
        body = self.world.CreateBody(bd) 

        sd=box2d.b2PolygonDef() 
        sd.density = 0.0
        sd.restitution = k_restitution

        sd.SetAsBox(0.1, 10.0, box2d.b2Vec2(-10.0, 0.0), 0.0)
        body.CreateShape(sd)

        sd.SetAsBox(0.1, 10.0, box2d.b2Vec2(10.0, 0.0), 0.0)
        body.CreateShape(sd)

        sd.SetAsBox(0.1, 10.0, box2d.b2Vec2(0.0, -10.0), 0.5 * box2d.b2_pi)
        body.CreateShape(sd)

        sd.SetAsBox(0.1, 10.0, box2d.b2Vec2(0.0, 10.0), -0.5 * box2d.b2_pi)
        body.CreateShape(sd)

        sd_bottom=box2d.b2PolygonDef() 
        sd_bottom.SetAsBox( 1.5, 0.15 )
        sd_bottom.density = 4.0

        sd_left=box2d.b2PolygonDef() 
        sd_left.SetAsBox(0.15, 2.7, box2d.b2Vec2(-1.45, 2.35), 0.2)
        sd_left.density = 4.0

        sd_right=box2d.b2PolygonDef() 
        sd_right.SetAsBox(0.15, 2.7, box2d.b2Vec2(1.45, 2.35), -0.2)
        sd_right.density = 4.0

        bd=box2d.b2BodyDef() 
        bd.position.Set( 0.0, 15.0 )
        body = self.world.CreateBody(bd) 
        body.CreateShape(sd_bottom)
        body.CreateShape(sd_left)
        body.CreateShape(sd_right)
        body.SetMassFromShapes()
        
        return

        for i in range(0):
            bd=box2d.b2BodyDef() 
            bd.position.Set(0.0, 15.0 + i)
            bd.isBullet = True
            body = self.world.CreateBody(bd) 
            body.SetAngularVelocity(box2d.b2Random(-50.0, 50.0))

            sd=box2d.b2CircleDef() 
            sd.radius = 0.25
            sd.density = 1.0
            sd.restitution = 0.0
            body.CreateShape(sd)
            body.SetMassFromShapes()
示例#27
0
    def __init__(self):
        super(Gears, self).__init__()
        bd=box2d.b2BodyDef() 
        bd.position.Set(0.0, -10.0)
        ground = self.world.CreateBody(bd)

        sd=box2d.b2PolygonDef() 
        sd.SetAsBox(50.0, 10.0)
        ground.CreateShape(sd)

        circle1=box2d.b2CircleDef() 
        circle1.radius = 1.0
        circle1.density = 5.0

        circle2=box2d.b2CircleDef() 
        circle2.radius = 2.0
        circle2.density = 5.0

        box=box2d.b2PolygonDef() 
        box.SetAsBox(0.5, 5.0)
        box.density = 5.0

        bd1=box2d.b2BodyDef() 
        bd1.position.Set(-3.0, 12.0)
        body1 = self.world.CreateBody(bd1) 
        body1.CreateShape(circle1)
        body1.SetMassFromShapes()

        jd1=box2d.b2RevoluteJointDef() 
        jd1.body1 = ground
        jd1.body2 = body1
        jd1.localAnchor1 = ground.GetLocalPoint(bd1.position)
        jd1.localAnchor2 = body1.GetLocalPoint(bd1.position)
        jd1.referenceAngle = body1.GetAngle() - ground.GetAngle()
        self.m_joint1 = self.world.CreateJoint(jd1).getAsType()

        bd2=box2d.b2BodyDef() 
        bd2.position.Set(0.0, 12.0)
        body2 = self.world.CreateBody(bd2) 
        body2.CreateShape(circle2)
        body2.SetMassFromShapes()

        jd2=box2d.b2RevoluteJointDef() 
        jd2.Initialize(ground, body2, bd2.position)
        self.m_joint2 = self.world.CreateJoint(jd2).getAsType()

        bd3=box2d.b2BodyDef() 
        bd3.position.Set(2.5, 12.0)
        body3 = self.world.CreateBody(bd3) 
        body3.CreateShape(box)
        body3.SetMassFromShapes()

        jd3=box2d.b2PrismaticJointDef() 
        jd3.Initialize(ground, body3, bd3.position, box2d.b2Vec2(0.0, 1.0))
        jd3.lowerTranslation = -5.0
        jd3.upperTranslation = 5.0
        jd3.enableLimit = True

        self.m_joint3 = self.world.CreateJoint(jd3).getAsType()

        jd4=box2d.b2GearJointDef() 
        jd4.body1 = body1
        jd4.body2 = body2
        jd4.joint1 = self.m_joint1
        jd4.joint2 = self.m_joint2
        jd4.ratio = circle2.radius / circle1.radius
        self.m_joint4 = self.world.CreateJoint(jd4).getAsType()

        jd5=box2d.b2GearJointDef() 
        jd5.body1 = body2
        jd5.body2 = body3
        jd5.joint1 = self.m_joint2
        jd5.joint2 = self.m_joint3
        jd5.ratio = -1.0 / circle2.radius
        self.m_joint5 = self.world.CreateJoint(jd5).getAsType()
示例#28
0
    def __init__(self):
        super(Dominos, self).__init__()
        sd=box2d.b2PolygonDef()
        sd.SetAsBox(50.0, 10.0)

        bd=box2d.b2BodyDef()
        bd.position.Set(0.0, -10.0)
        b1 = self.world.CreateBody(bd)
        b1.CreateShape(sd)

        sd=box2d.b2PolygonDef()
        sd.SetAsBox(6.0, 0.25)

        bd=box2d.b2BodyDef()
        bd.position.Set(-1.5, 10.0)
        ground = self.world.CreateBody(bd) 
        ground.CreateShape(sd)

        sd=box2d.b2PolygonDef() 
        sd.SetAsBox(0.1, 1.0)
        sd.density = 20.0
        sd.friction = 0.1

        
        for i in range(10):
            bd=box2d.b2BodyDef() 
            bd.position.Set(-6.0 + 1.0 * i, 11.25)
            body = self.world.CreateBody(bd) 
            body.CreateShape(sd)
            body.SetMassFromShapes()

        sd=box2d.b2PolygonDef() 
        sd.SetAsBox(7.0, 0.25, box2d.b2Vec2_zero, 0.3)

        bd=box2d.b2BodyDef() 
        bd.position.Set(1.0, 6.0)
        ground = self.world.CreateBody(bd) 
        ground.CreateShape(sd)

        
        sd=box2d.b2PolygonDef() 
        sd.SetAsBox(0.25, 1.5)

        bd=box2d.b2BodyDef() 
        bd.position.Set(-7.0, 4.0)
        b2 = self.world.CreateBody(bd)
        b2.CreateShape(sd)

        
        sd=box2d.b2PolygonDef() 
        sd.SetAsBox(6.0, 0.125)
        sd.density = 10.0

        bd=box2d.b2BodyDef() 
        bd.position.Set(-0.9, 1.0)
        bd.angle = -0.15

        b3 = self.world.CreateBody(bd)
        b3.CreateShape(sd)
        b3.SetMassFromShapes()

        jd=box2d.b2RevoluteJointDef() 
        anchor=box2d.b2Vec2() 

        anchor.Set(-2.0, 1.0)
        jd.Initialize(b1, b3, anchor)
        jd.collideConnected = True
        self.world.CreateJoint(jd).getAsType() 

        
        sd=box2d.b2PolygonDef() 
        sd.SetAsBox(0.25, 0.25)
        sd.density = 10.0

        bd=box2d.b2BodyDef() 
        bd.position.Set(-10.0, 15.0)
        b4 = self.world.CreateBody(bd)
        b4.CreateShape(sd)
        b4.SetMassFromShapes()

        anchor.Set(-7.0, 15.0)
        jd.Initialize(b2, b4, anchor)
        self.world.CreateJoint(jd).getAsType() 

        
        bd=box2d.b2BodyDef() 
        bd.position.Set(6.5, 3.0)
        b5 = self.world.CreateBody(bd)

        sd=box2d.b2PolygonDef() 
        sd.density = 10.0
        sd.friction = 0.1

        sd.SetAsBox(1.0, 0.1, box2d.b2Vec2(0.0, -0.9), 0.0)
        b5.CreateShape(sd)

        sd.SetAsBox(0.1, 1.0, box2d.b2Vec2(-0.9, 0.0), 0.0)
        b5.CreateShape(sd)

        sd.SetAsBox(0.1, 1.0, box2d.b2Vec2(0.9, 0.0), 0.0)
        b5.CreateShape(sd)

        b5.SetMassFromShapes()

        anchor.Set(6.0, 2.0)
        jd.Initialize(b1, b5, anchor)
        self.world.CreateJoint(jd).getAsType() 

        
        sd=box2d.b2PolygonDef() 
        sd.SetAsBox(1.0, 0.1)
        sd.density = 30.0
        sd.friction = 0.2

        bd=box2d.b2BodyDef() 
        bd.position.Set(6.5, 4.1)
        b6 = self.world.CreateBody(bd)
        b6.CreateShape(sd)
        b6.SetMassFromShapes()

        anchor.Set(7.5, 4.0)
        jd.Initialize(b5, b6, anchor)
        self.world.CreateJoint(jd).getAsType() 

        
        sd=box2d.b2PolygonDef() 
        sd.SetAsBox(0.1, 1.0)
        sd.density = 10.0

        bd=box2d.b2BodyDef() 
        bd.position.Set(7.4, 1.0)

        b7 = self.world.CreateBody(bd)
        b7.CreateShape(sd)
        b7.SetMassFromShapes()

        djd=box2d.b2DistanceJointDef() 
        djd.body1 = b3
        djd.body2 = b7
        djd.localAnchor1.Set(6.0, 0.0)
        djd.localAnchor2.Set(0.0, -1.0)
        d = djd.body2.GetWorldPoint(djd.localAnchor2) - djd.body1.GetWorldPoint(djd.localAnchor1)
        djd.length = d.Length()
        self.world.CreateJoint(djd).getAsType() 

        sd=box2d.b2CircleDef() 
        sd.radius = 0.2
        sd.density = 10.0

        
        for i in range(4):
            bd=box2d.b2BodyDef() 
            bd.position.Set(5.9 + 2.0 * sd.radius * i, 2.4)
            body = self.world.CreateBody(bd) 
            body.CreateShape(sd)
            body.SetMassFromShapes()