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.
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
bodiesSequence of all bodies in the world, sorted by name. cfmCurrent global CFM value. erpCurrent global ERP value. gravityCurrent gravity vector in the world. jointsSequence 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
BodyOne 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
BodyOne 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 :
BodyThe created body object.
-
erp¶ Current global ERP value.
-
get_body(key)[source]¶ Get a body by key.
Parameters: key : str, None, or
BodyThe key for looking up a body. If this is None or a
Bodyinstance, the key itself will be returned.Returns: body :
BodyThe 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 :
JointThe 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
BodyThe 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, optionalIf given, identifies the second body to join together with
body_a. If not given,body_ais 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 :
JointThe 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_aonbody_awill be coincident with the location described byoffset_bonbody_b.Parameters: body_a : str or
BodyThe 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
BodyThe 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. SeeBody.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.
-
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).
-
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().
-