コード例 #1
0
ファイル: car.py プロジェクト: shengtu/pypybox2d
    def __init__(self):
        super(Car, self).__init__()

        # The ground -- create some terrain
        ground = self.world.create_static_body(shapes=b2.Edge((-20, 0), (20, 0)))

        x, y1, dx = 20, 0, 5
        vertices = [0.25, 1, 4, 0, 0, -1, -2, -2, -1.25, 0]
        for y2 in vertices * 2:  # iterate through vertices twice
            ground.create_edge_fixture((x, y1), (x + dx, y2), density=0, friction=0.6)
            y1 = y2
            x += dx

        x_offsets = [0, 80, 40, 20, 40]
        x_lengths = [40, 40, 10, 40, 0]
        y2s = [0, 0, 5, 0, 20]
        for x_offset, x_length, y2 in zip(x_offsets, x_lengths, y2s):
            x += x_offset
            ground.create_edge_fixture((x, 0), (x + x_length, y2), density=0, friction=0.6)

        # Teeter
        body = self.world.create_dynamic_body(
            position=(140, 0.90), fixtures=b2.Fixture(shape=b2.Polygon(box=(10, 0.25)), density=1.0)
        )

        self.world.create_revolute_joint(
            ground,
            body,
            anchor=body.position,
            lower_angle=-8.0 * PI / 180.0,
            upper_angle=8.0 * PI / 180.0,
            limit_enabled=True,
        )

        # Bridge
        create_bridge(self.world, ground, (2.0, 0.25), (161.0, -0.125), self.bridge_planks)

        # Boxes
        for y_pos in [0.5, 1.5, 2.5, 3.5, 4.5]:
            self.world.create_dynamic_body(
                position=(230, y_pos), fixtures=b2.Fixture(shape=b2.Polygon(box=(0.5, 0.5)), density=0.5)
            )

        car, wheels, springs = create_car(
            self.world, offset=(0.0, 1.0), wheel_radius=0.4, wheel_separation=2.0, scale=(1, 1)
        )
        self.car = car
        self.wheels = wheels
        self.springs = springs
コード例 #2
0
    def __init__(self):
        Framework.__init__(self)
        
        world = self.world

        ground = world.create_static_body(shapes=b2.Edge((-20, 0),( 20, 0))) 

        controller = world.create_buoyancy_controller(
                                        offset=15, normal=(0, 1), density=2, 
                                        linear_drag=2, angular_drag=1)
       
        # Create a few spheres to bob around
        for i in range(7):
            body = self.world.create_dynamic_body(
                    position=(-10+4.0*i, 20), 
                    fixtures=b2.Fixture(shape=b2.Circle(radius=1.0), 
                                density=1.0)
                    )

            controller.add_body(body)

        # Create a bridge, and add it to the controller
        num_planks = 30
        plank_bodies = create_bridge(self.world, ground, (1.0, 0.25), (-14.5, 5), num_planks, 0.2, 1)
        for body in plank_bodies:
            controller.add_body(body)

        # Create a circle underneath the bridge
        body = self.world.create_dynamic_body(
                position=(-10.0, 0), 
                fixtures=b2.Fixture(shape=b2.Circle(radius=1.0), 
                            density=1.0)
                )

        controller.add_body(body)

        # And finally, some triangles
        for i in range(5):
            body = self.world.create_dynamic_body(
                    position=(-10+3.0*i, 20), 
                    fixtures=b2.Fixture(
                                shape=b2.Polygon(
                                    vertices=[(-0.5,0),(0,-0.5),(0.5, 0.0)]),
                                density=1.0)
                    )

            controller.add_body(body)

        # And (really) finally this time, just something so we can be sure 
        # edges work, too.
        edge = world.create_dynamic_body(
                    fixtures=b2.Fixture(shape=b2.Edge((5, 0),(5, 3)),
                                density=1.0)
                    )
        controller.add_body(edge)
コード例 #3
0
    def __init__(self):
        Framework.__init__(self)
        
        world = self.world

        # Turn off normal gravity
        world.gravity = (0, 0)

        ground = world.create_static_body(shapes=b2.Edge((-20, 0),( 20, 0))) 

        controller = world.create_gravity_controller(G=0.8, inv_sqr=True)
       
        # Create a few spheres to bob around
        for i in range(1,4):
            body = self.world.create_dynamic_body(
                    position=(0.25 * i, 2.0 + 7.5 * i),
                    fixtures=b2.Fixture(shape=b2.Circle(radius=0.25 * i), 
                                density=1.0),
                    bullet=True,
                    )

            controller.add_body(body)

        # Create a bridge, and add it to the controller
        num_planks = 30
        plank_bodies = create_bridge(self.world, ground, (1.0, 0.25), (-14.5, 5), num_planks, 0.2, 10)
        for body in plank_bodies:
            controller.add_body(body)

        # Create a circle underneath the bridge
        body = self.world.create_dynamic_body(
                position=(-10.0, 0), 
                fixtures=b2.Fixture(shape=b2.Circle(radius=1.0), 
                            density=10.0)
                )

        controller.add_body(body)

        # And finally, some triangles
        for i in range(5):
            body = self.world.create_dynamic_body(
                    position=(-10+3.0*i, 20), 
                    fixtures=b2.Fixture(shape=b2.Polygon(vertices=[(-0.5,0),(0,-0.5),(0.5, 0.0)]),
                                density=1.0)
                    )

            controller.add_body(body)
コード例 #4
0
ファイル: car.py プロジェクト: springtangent/pypybox2d
    def __init__(self):
        super(Car, self).__init__()

        # The ground -- create some terrain
        ground=self.world.create_static_body(
                    shapes=b2.Edge((-20,0),(20,0)) 
                )

        x, y1, dx=20, 0, 5
        vertices=[0.25, 1, 4, 0, 0, -1, -2, -2, -1.25, 0] 
        for y2 in vertices*2: # iterate through vertices twice
            ground.create_edge_fixture(
                (x,y1), (x+dx,y2),
                density=0,
                friction=0.6,
                )
            y1=y2
            x += dx
       
        x_offsets=[ 0,80, 40, 20, 40]
        x_lengths=[40,40, 10, 40,  0]
        y2s      =[ 0, 0,  5,  0, 20]
        for x_offset, x_length, y2 in zip(x_offsets, x_lengths, y2s):
            x += x_offset
            ground.create_edge_fixture(
                (x, 0), (x+x_length, y2),
                density=0,
                friction=0.6,
                )

        # Teeter
        body=self.world.create_dynamic_body(
            position=(140, 0.90),
            fixtures=b2.Fixture(
                        shape=b2.Polygon(box=(10,0.25)),
                        density=1.0,
                        )
                )

        self.world.create_revolute_joint(
            ground,
            body,
            anchor=body.position,
            lower_angle=-8.0*PI/180.0,
            upper_angle= 8.0*PI/180.0,
            limit_enabled=True,
            )

        # Bridge
        create_bridge(self.world, ground, (2.0, 0.25), (161.0, -0.125), self.bridge_planks)

        # Boxes
        for y_pos in [0.5, 1.5, 2.5, 3.5, 4.5]:
            self.world.create_dynamic_body(
                position=(230, y_pos),
                fixtures=b2.Fixture(
                            shape=b2.Polygon(box=(0.5,0.5)),
                            density=0.5,
                            )
                    )

        car, wheels, springs=create_car(self.world, offset=(0.0, 1.0), wheel_radius=0.4, wheel_separation=2.0, scale=(1,1))
        self.car=car
        self.wheels=wheels
        self.springs=springs