예제 #1
0
 def __init__(self, control_noise=0.):
     self.control_noise = control_noise
     self.seed()
     self.world = Box2D.b2World(gravity=(0, 0))
     self.pusher = None
     self.box = None
     # Actions: x-movement, y-movement (clipped -1 to 1)
     self.action_space = spaces.Box(np.ones(2) * -1, np.ones(2), dtype=np.float32)
     # State: pusher xy position, box xy position, pusher xy velocity, box xy velocity, goal xy position
     self.observation_space = spaces.Box(np.ones(10) * MIN_COORD, np.ones(10) * MAX_COORD, dtype=np.float32)
     self.reset()
     self.drawer = OpencvDrawFuncs(w=240, h=180, ppm=40)
     self.drawer.install()
예제 #2
0
파일: simple_cv.py 프로젝트: Teslos/pybox2d
# And a static body to hold the ground shape
ground_body = world.CreateStaticBody(
    position=(0, 0),
    shapes=polygonShape(box=(50, 1)),
)

# Create a couple dynamic bodies
bodyc = world.CreateDynamicBody(position=(20, 45))
circle = bodyc.CreateCircleFixture(radius=0.5, density=1, friction=0.3)

bodyb = world.CreateDynamicBody(position=(30, 45), angle=15)
box = bodyb.CreatePolygonFixture(box=(2, 1), density=1, friction=0.3)

world.CreateWeldJoint(bodyA=bodyc, bodyB=bodyb, anchor=bodyb.worldCenter)

drawer = OpencvDrawFuncs(w=640, h=480, ppm=20)
drawer.install()

while True:
    key = 0xFF & cv2.waitKey(int(TIME_STEP * 1000))  # milliseconds
    if key == 27:
        break
    drawer.clear_screen()

    drawer.draw_world(world)

    # Make Box2D simulate the physics of our world for one step.
    world.Step(TIME_STEP, 10, 10)

    # Flip the screen and try to keep at the target FPS
    cv2.imshow("world", drawer.screen)