Esempio n. 1
0
    def __init__(self):
        super(ApplyForce, self).__init__()
        self.world.gravity = (0.0, 0.0)

        # The boundaries
        ground = self.world.CreateBody(position=(0, 20))
        ground.CreateEdgeChain(
            [(-20, -20),
             (-20, 20),
             (20, 20),
             (20, -20),
             (-20, -20)]
        )

        #  TODO: make note of transform.R.set() -> transform.angle =
        xf1 = b2Transform()
        xf1.angle = 0.3524 * b2_pi
        xf1.position = xf1.R * (1.0, 0.0)

        xf2 = b2Transform()
        xf2.angle = -0.3524 * b2_pi
        xf2.position = xf2.R * (-1.0, 0.0)
        self.body = self.world.CreateDynamicBody(
            position=(0, 2),
            angle=b2_pi,
            angularDamping=5,
            linearDamping=0.1,
            shapes=[b2PolygonShape(vertices=[xf1 * (-1, 0), xf1 * (1, 0),
                                             xf1 * (0, .5)]),
                    b2PolygonShape(vertices=[xf2 * (-1, 0), xf2 * (1, 0),
                                             xf2 * (0, .5)])],
            shapeFixture=b2FixtureDef(density=2.0),
        )

        gravity = 10.0
        fixtures = b2FixtureDef(shape=b2PolygonShape(box=(0.5, 0.5)),
                                density=1, friction=0.3)
        for i in range(10):
            body = self.world.CreateDynamicBody(
                position=(0, 5 + 1.54 * i), fixtures=fixtures)

            # For a circle: I = 0.5 * m * r * r ==> r = sqrt(2 * I / m)
            r = sqrt(2.0 * body.inertia / body.mass)

            self.world.CreateFrictionJoint(
                bodyA=ground,
                bodyB=body,
                localAnchorA=(0, 0),
                localAnchorB=(0, 0),
                collideConnected=True,
                maxForce=body.mass * gravity,
                maxTorque=body.mass * r * gravity
            )
Esempio n. 2
0
    def __init__(self):
        super(ApplyForce, self).__init__()
        self.world.gravity = (0.0, 0.0)

        # The boundaries
        ground = self.world.CreateBody(position=(0, 20))
        ground.CreateEdgeChain(
            [(-20, -20),
             (-20, 20),
             (20, 20),
             (20, -20),
             (-20, -20)]
        )

        #  TODO: make note of transform.R.set() -> transform.angle =
        xf1 = b2Transform()
        xf1.angle = 0.3524 * b2_pi
        xf1.position = xf1.R * (1.0, 0.0)

        xf2 = b2Transform()
        xf2.angle = -0.3524 * b2_pi
        xf2.position = xf2.R * (-1.0, 0.0)
        self.body = self.world.CreateDynamicBody(
            position=(0, 2),
            angle=b2_pi,
            angularDamping=5,
            linearDamping=0.1,
            shapes=[b2PolygonShape(vertices=[xf1 * (-1, 0), xf1 * (1, 0),
                                             xf1 * (0, .5)]),
                    b2PolygonShape(vertices=[xf2 * (-1, 0), xf2 * (1, 0),
                                             xf2 * (0, .5)])],
            shapeFixture=b2FixtureDef(density=2.0),
        )

        gravity = 10.0
        fixtures = b2FixtureDef(shape=b2PolygonShape(box=(0.5, 0.5)),
                                density=1, friction=0.3)
        for i in range(10):
            body = self.world.CreateDynamicBody(
                position=(0, 5 + 1.54 * i), fixtures=fixtures)

            # For a circle: I = 0.5 * m * r * r ==> r = sqrt(2 * I / m)
            r = sqrt(2.0 * body.inertia / body.mass)

            self.world.CreateFrictionJoint(
                bodyA=ground,
                bodyB=body,
                localAnchorA=(0, 0),
                localAnchorB=(0, 0),
                collideConnected=True,
                maxForce=body.mass * gravity,
                maxTorque=body.mass * r * gravity
            )
    def __init__(self):
        super(Distance, self).__init__()
        # Transform A -- a simple translation/offset of (0,-0.2)
        self.transformA = b2Transform()
        self.transformA.SetIdentity()
        self.transformA.position = (0, -0.2)

        # Transform B -- a translation and a rotation
        self.transformB = b2Transform()
        self.positionB = b2Vec2(12.017401, 0.13678508)
        self.angleB = -0.0109265
        self.transformB.Set(self.positionB, self.angleB)

        # The two shapes, transformed by the respective transform[A,B]
        self.polygonA = b2PolygonShape(box=(10, 0.2))
        self.polygonB = b2PolygonShape(box=(2, 0.1))
Esempio n. 4
0
    def __init__(self):
        super(Distance, self).__init__()
        # Transform A -- a simple translation/offset of (0,-0.2)
        self.transformA = b2Transform()
        self.transformA.SetIdentity()
        self.transformA.position = (0, -0.2)

        # Transform B -- a translation and a rotation
        self.transformB = b2Transform()
        self.positionB = b2Vec2(12.017401, 0.13678508)
        self.angleB = -0.0109265
        self.transformB.Set(self.positionB, self.angleB)

        # The two shapes, transformed by the respective transform[A,B]
        self.polygonA = b2PolygonShape(box=(10, 0.2))
        self.polygonB = b2PolygonShape(box=(2, 0.1))