Пример #1
0
        def make_world(forces, mass):
            bodies = []
            joints = []

            # make chain of rectangles
            r = Rect([300, 50], [20, 60])
            bodies.append(r)
            joints.append(Joint(r, None, [300, 30]))
            for i in range(1, 10):
                if i < 9:
                    r = Rect([300, 50 + 50 * i], [20, 60])
                else:
                    r = Rect([300, 50 + 50 * i], [20, 60], mass=mass)
                bodies.append(r)
                joints.append(Joint(bodies[-1], bodies[-2],
                                    [300, 25 + 50 * i]))
                bodies[-1].add_no_collision(bodies[-2])
            bodies[-1].add_force(ExternalForce(down_force, multiplier=100))

            # make projectile
            m = 13
            c1 = Circle([50, 500], 20)
            bodies.append(c1)
            for f in forces:
                c1.add_force(ExternalForce(f, multiplier=100 * m))

            world = World(bodies, joints, dt=DT)
            return world, r
Пример #2
0
def make_world(forces, mass, num_links=10):
    bodies = []
    joints = []

    # make chain of rectangles
    link_mass = mass / num_links
    r = Rect([300, 50], [20, 60], mass=link_mass)
    bodies.append(r)
    joints.append(Joint(r, None, [300, 30]))
    for i in range(1, num_links):
        if i < num_links - 1:
            r = Rect([300, 50 + 50 * i], [20, 60], mass=link_mass)
        else:
            r = Rect([300, 50 + 50 * i], [20, 60], mass=link_mass)
        r.add_force(Gravity(g=100))
        bodies.append(r)
        joints.append(Joint(bodies[-1], bodies[-2], [300, 25 + 50 * i]))
        bodies[-1].add_no_contact(bodies[-2])

    # make projectile
    m = 3
    c_pos = torch.tensor([50, bodies[-1].pos[1]])  # same Y as last chain link
    c = Circle(c_pos, 20, restitution=1.)
    bodies.append(c)
    for f in forces:
        c.add_force(ExternalForce(f, multiplier=500 * m))

    world = World(bodies, joints, dt=DT, post_stab=True)
    return world, r
Пример #3
0
def make_world(forces, mass, num_links=10):
    bodies = []
    joints = []

    # make chain of rectangles
    r = Rect([300, 50], [20, 60])
    bodies.append(r)
    joints.append(Joint(r, None, [300, 30]))
    for i in range(1, num_links):
        if i < num_links - 1:
            r = Rect([300, 50 + 50 * i], [20, 60])
        else:
            r = Rect([300, 50 + 50 * i], [20, 60], mass=mass)
        bodies.append(r)
        joints.append(Joint(bodies[-1], bodies[-2], [300, 25 + 50 * i]))
        bodies[-1].add_no_collision(bodies[-2])
    bodies[-1].add_force(Gravity(g=100))

    # make projectile
    m = 13
    c1 = Circle([50, bodies[-1].pos.data[1]], 20)  # same Y as last chain link
    bodies.append(c1)
    for f in forces:
        c1.add_force(ExternalForce(f, multiplier=100 * m))

    world = World(bodies, joints, dt=DT)
    return world, r
Пример #4
0
    def testChain(self):
        bodies = []
        joints = []

        # make chain of rectangles
        r = Rect([300, 50], [20, 60])
        bodies.append(r)
        joints.append(XConstraint(r))
        joints.append(YConstraint(r))
        for i in range(1, 10):
            r = Rect([300, 50 + 50 * i], [20, 60])
            bodies.append(r)
            joints.append(Joint(bodies[-1], bodies[-2], [300, 25 + 50 * i]))
            bodies[-1].add_no_collision(bodies[-2])
        bodies[-1].add_force(ExternalForce(down_force, multiplier=100))

        # make projectile
        c = Circle([50, 500], 20, restitution=1)
        bodies.append(c)
        c.add_force(ExternalForce(hor_impulse, multiplier=1000))

        recorder = None
        # recorder = Recorder(DT, self.screen)
        world = World(bodies, joints, dt=DT)
        run_world(world, run_time=TIME, screen=self.screen, recorder=recorder)
Пример #5
0
def chain_demo(screen):
    bodies = []
    joints = []
    restitution = 0.9

    # make chain of rectangles
    r = Rect([300, 50], [20, 60], restitution=restitution)
    bodies.append(r)
    joints.append(XConstraint(r))
    joints.append(YConstraint(r))
    for i in range(1, 10):
        r = Rect([300, 50 + 50 * i], [20, 60], restitution=restitution)
        bodies.append(r)
        joints.append(Joint(bodies[-1], bodies[-2], [300, 25 + 50 * i]))
        bodies[-1].add_no_contact(bodies[-2])
        bodies[-1].add_force(Gravity(g=100))

    # make projectile
    c = Circle([50, 500], 20, restitution=restitution)
    bodies.append(c)
    c.add_force(ExternalForce(hor_impulse, multiplier=2000))

    clock = Circle([975, 575], 20, vel=[1, 0, 0])
    bodies.append(clock)

    recorder = None
    # recorder = Recorder(DT, screen)
    world = World(bodies, joints, dt=DT, post_stab=True)
    run_world(world, run_time=TIME * 2, screen=screen, recorder=recorder)
Пример #6
0
    def testDemo(self):
        bodies = []
        joints = []
        # Ball hitting object constrained by 1 joint
        for i in range(1, 3):
            c = Circle([150, 150 + 80 * (i - 1)], 20)
            if i == 1:
                c.add_force(ExternalForce(vert_impulse, multiplier=500))
            bodies.append(c)
        joints.append(Joint(bodies[-1], None, [140, 220]))

        # Ball bouncing on body fixed in place
        for i in range(1, 3):
            c = Circle([300 + 1 * (i - 1), 150 + 80 * (i - 1)], 20)
            if i == 1:
                c.add_force(ExternalForce(down_force, multiplier=100))
            bodies.append(c)
        joints.append(TotalConstraint(bodies[-1]))

        # 2 free ball collision angled
        for i in range(1, 3):
            c = Circle([225 - 10 * (i - 1), 300 + 80 * (i - 1)], 20)
            if i == 1:
                c.add_force(ExternalForce(down_force, multiplier=100))
            bodies.append(c)

        # 2 free ball collision straight
        for i in range(1, 3):
            c = Circle([375, 300 + 80 * (i - 1)], 20)
            if i == 1:
                c.add_force(ExternalForce(vert_impulse, multiplier=500))
            bodies.append(c)

        r = Rect([300, 500], [40, 40])
        r.add_force(ExternalForce(down_force, multiplier=-100))
        r.v[0] = -1
        bodies.append(r)

        r = Rect([300, 50], [40, 40])
        r.add_force(ExternalForce(down_force, multiplier=100))
        r.v[0] = -1
        for b in bodies:
            b.add_no_collision(r)
        # bodies.append(r)

        world = World(bodies, joints, dt=DT)
        run_world(world, run_time=10, screen=self.screen)
Пример #7
0
def debug_demo(screen):
    bodies = []
    joints = []
    # Ball hitting object constrained by 1 joint
    for i in range(1, 3):
        c = Circle([150, 150 + 80 * (i - 1)], 20)
        if i == 1:
            c.add_force(ExternalForce(vert_impulse, multiplier=500))
        bodies.append(c)
    joints.append(Joint(bodies[-1], None, [140, 220]))

    # Ball bouncing on body fixed in place
    for i in range(1, 3):
        c = Circle([300 + 1 * (i - 1), 150 + 80 * (i - 1)], 20)
        if i == 1:
            c.add_force(Gravity(g=100))
        # else:
        #     c.add_force(ExternalForce(neg_gravity, multiplier=100))
        bodies.append(c)
    joints.append(TotalConstraint(bodies[-1]))

    # 2 free ball collision angled
    for i in range(1, 3):
        c = Circle([225 - 10 * (i - 1), 300 + 80 * (i - 1)], 20)
        if i == 1:
            c.add_force(Gravity(g=100))
        bodies.append(c)

    # 2 free ball collision straight
    for i in range(1, 3):
        c = Circle([375, 300 + 80 * (i - 1)], 20)
        if i == 1:
            c.add_force(ExternalForce(vert_impulse, multiplier=500))
        bodies.append(c)

    r = Rect([300, 500], [40, 40], vel=[-1, 0, 0])
    r.add_force(Gravity(g=-100))
    bodies.append(r)

    clock = Circle([975, 575], 20, vel=[1, 0, 0])
    bodies.append(clock)

    world = World(bodies, joints, dt=DT, post_stab=True)
    run_world(world, run_time=10, screen=screen)