pagoda.physics.World

class pagoda.physics.World(dt=0.016666666666666666, max_angular_speed=20)[source]

A wrapper for an ODE World object, for running in a simulator.

__init__(dt=0.016666666666666666, max_angular_speed=20)[source]

Methods

__init__([dt, max_angular_speed])
are_connected(body_a, body_b) Determine whether the given bodies are currently connected.
create_body(shape[, name]) Create a new body.
get_body(key) Get a body by key.
get_body_states() Return the complete state of all bodies in the world.
get_joint(key) Get a joint by key.
join(shape, body_a[, body_b, name]) Create a new joint that connects two bodies together.
move_next_to(body_a, body_b, offset_a, offset_b) Move one body to be near another one.
needs_reset() Return True iff the world needs to be reset.
on_collision(args, geom_a, geom_b) Callback function for the collide() method.
on_key_press(key, modifiers, keymap) Handle an otherwise unhandled keypress event (from a GUI).
reset() Reset the state of the world.
set_body_states(states) Set the states of some bodies in the world.
step([substeps]) Step the world forward by one frame.

Attributes

bodies Sequence of all bodies in the world, sorted by name.
cfm Current global CFM value.
erp Current global ERP value.
gravity Current gravity vector in the world.
joints Sequence of all joints in the world, sorted by name.
are_connected(body_a, body_b)[source]

Determine whether the given bodies are currently connected.

Parameters:

body_a : str or Body

One body to test for connectedness. If this is a string, it is treated as the name of a body to look up.

body_b : str or Body

One body to test for connectedness. If this is a string, it is treated as the name of a body to look up.

Returns:

connected : bool

Return True iff the two bodies are connected.

bodies

Sequence of all bodies in the world, sorted by name.

cfm

Current global CFM value.

create_body(shape, name=None, **kwargs)[source]

Create a new body.

Parameters:

shape : str

The “shape” of the body to be created. This should name a type of body object, e.g., “box” or “cap”.

name : str, optional

The name to use for this body. If not given, a default name will be constructed of the form “{shape}{# of objects in the world}”.

Returns:

body : Body

The created body object.

erp

Current global ERP value.

get_body(key)[source]

Get a body by key.

Parameters:

key : str, None, or Body

The key for looking up a body. If this is None or a Body instance, the key itself will be returned.

Returns:

body : Body

The body in the world with the given key.

get_body_states()[source]

Return the complete state of all bodies in the world.

Returns:

states : list of state information tuples

A list of body state information for each body in the world. See Body.state().

get_joint(key)[source]

Get a joint by key.

Parameters:

key : str

The key for a joint to look up.

Returns:

joint : Joint

The joint in the world with the given key, or None if there is no such joint.

gravity

Current gravity vector in the world.

join(shape, body_a, body_b=None, name=None, **kwargs)[source]

Create a new joint that connects two bodies together.

Parameters:

shape : str

The “shape” of the joint to use for joining together two bodies. This should name a type of joint, such as “ball” or “piston”.

body_a : str or Body

The first body to join together with this joint. If a string is given, it will be used as the name of a body to look up in the world.

body_b : str or Body, optional

If given, identifies the second body to join together with body_a. If not given, body_a is joined to the world.

name : str, optional

If given, use this name for the created joint. If not given, a name will be constructed of the form “{body_a.name}^{shape}^{body_b.name}”.

Returns:

joint : Joint

The joint object that was created.

joints

Sequence of all joints in the world, sorted by name.

move_next_to(body_a, body_b, offset_a, offset_b)[source]

Move one body to be near another one.

After moving, the location described by offset_a on body_a will be coincident with the location described by offset_b on body_b.

Parameters:

body_a : str or Body

The body to use as a reference for moving the other body. If this is a string, it is treated as the name of a body to look up in the world.

body_b : str or Body

The body to move next to body_a. If this is a string, it is treated as the name of a body to look up in the world.

offset_a : 3-tuple of float

The offset of the anchor point, given as a relative fraction of the size of body_a. See Body.relative_offset_to_world().

offset_b : 3-tuple of float

The offset of the anchor point, given as a relative fraction of the size of body_b.

Returns:

anchor : 3-tuple of float

The location of the shared point, which is often useful to use as a joint anchor.

needs_reset()[source]

Return True iff the world needs to be reset.

on_collision(args, geom_a, geom_b)[source]

Callback function for the collide() method.

Parameters:

args : None

Arguments passed when the callback was registered. Not used.

geom_a : ODE geometry

The geometry object of one of the bodies that has collided.

geom_b : ODE geometry

The geometry object of one of the bodies that has collided.

on_key_press(key, modifiers, keymap)[source]

Handle an otherwise unhandled keypress event (from a GUI).

reset()[source]

Reset the state of the world.

set_body_states(states)[source]

Set the states of some bodies in the world.

Parameters:

states : sequence of states

A complete state tuple for one or more bodies in the world. See get_body_states().

step(substeps=2)[source]

Step the world forward by one frame.

Parameters:

substeps : int, optional

Split the step into this many sub-steps. This helps to prevent the time delta for an update from being too large.