Class pymunk.Space

Methods

  __init__(self, iterations=10)
  __del__(self)
  add(self, *objs)
Add one or many shapes, bodies or joints to the space
  add_static(self, *objs)
Add one or many static shapes to the space
  remove(self, *objs)
Remove one or many shapes, bodies or joints from the space
  remove_static(self, *os)
Remove one or many static shapes from the space
  resize_static_hash(self, dim=100.0, count=1000)
The spatial hashes used by Chipmunk's collision detection are fairly size sensitive.
  resize_active_hash(self, dim=100.0, count=1000)
The spatial hashes used by Chipmunk's collision detection are fairly size sensitive.
  rehash_static(self)
Rehashes the shapes in the static spatial hash.
  step(self, dt)
Update the space for the given time step.
  add_collisionpair_func(self, a, b, func, data=None)
Register func to be called when a collision is found between a shapes with collision_type fields that match a and b.
  remove_collisionpair_func(self, a, b)
Remove the collision pair function between the shapes a and b
  set_default_collisionpair_func(self, func, data=None)
Sets the default collsion pair function.
  point_query(self, point, func, data=None)
Query the space for collisions between a point and its shapes (both static and nonstatic shapes)
  static_point_query(self, point, func, data=None)
Query the space for collisions between a point and the static shapes in the space
  nonstatic_point_query(self, point, func, data=None)
Query the space for collisions between a point and the non static shapes in the space

Properties

  shapes
  static_shapes
  bodies
  gravity
  damping
  stamp
Time stamp.
  arbiters
List of active arbiters for the impulse solver.

Method Details

resize_static_hash

resize_static_hash(self, dim=100.0, count=1000)

The spatial hashes used by Chipmunk's collision detection are fairly size sensitive. dim is the size of the hash cells. Setting dim to the average objects size is likely to give the best performance.

count is the suggested minimum number of cells in the hash table. Bigger is better, but only to a point. Setting count to ~10x the number of objects in the hash is probably a good starting point.

resize_active_hash

resize_active_hash(self, dim=100.0, count=1000)

The spatial hashes used by Chipmunk's collision detection are fairly size sensitive. dim is the size of the hash cells. Setting dim to the average objects size is likely to give the best performance.

count is the suggested minimum number of cells in the hash table. Bigger is better, but only to a point. Setting count to ~10x the number of objects in the hash is probably a good starting point.

rehash_static

rehash_static(self)
Rehashes the shapes in the static spatial hash. You only need to call this if you move one of the static shapes.

step

step(self, dt)
Update the space for the given time step. Using a fixed time step is highly recommended. Doing so will increase the efficiency of the contact persistence, requiring an order of magnitude fewer iterations to resolve the collisions in the usual case.

add_collisionpair_func

add_collisionpair_func(self, a, b, func, data=None)

Register func to be called when a collision is found between a shapes with collision_type fields that match a and b. Pass None as func to reject any collision with the given collision type pair.

func(shapeA, shapeB, contacts, normal_coef, data) -> bool

shapeA, shapeB is the colliding shapes contacts is a list of contacts normal_coef is a float :) data is the data argument sent to the add_collisionpair_func function

WARNING: It is not safe for collision pair functions to remove or free shapes or bodies from a space. Doing so will likely end in a segfault as an earlier collision may already be referencing the shape or body. You must wait until after the step() function returns.

set_default_collisionpair_func

set_default_collisionpair_func(self, func, data=None)
Sets the default collsion pair function. Passing None as func will reset it to default.. :)

point_query

point_query(self, point, func, data=None)

Query the space for collisions between a point and its shapes (both static and nonstatic shapes)

func(shape, data)

shape is the colliding shape data is the data argument sent to the point_query function

static_point_query

static_point_query(self, point, func, data=None)

Query the space for collisions between a point and the static shapes in the space

func(shape, data)

shape is the colliding shape data is the data argument sent to the point_query function

nonstatic_point_query

nonstatic_point_query(self, point, func, data=None)

Query the space for collisions between a point and the non static shapes in the space

func(shape, data)

shape is the colliding shape data is the data argument sent to the point_query function


Property Details

shapes

static_shapes

bodies

gravity

damping

stamp

Time stamp. Is incremented on every call to step()

arbiters

List of active arbiters for the impulse solver.