Package pymunk :: Class Space
[frames] | no frames]

Class Space

object --+
         |
        Space

Spaces are the basic unit of simulation. You add rigid bodies, shapes and joints to it and then step them all forward together through time.
Instance Methods
 
__init__(self, iterations=10)
Create a new instace of the Space
 
__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 shapes with collision_type fields that match a and b.
 
remove_collisionpair_func(self, a, b)
Remove the collision pair function between shapes with collision_type which match 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

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

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

Inherited from object: __class__

Method Details

__init__(self, iterations=10)
(Constructor)

 
Create a new instace of the Space
Parameters:
  • iterations (int) - Number of iterations to use in the impulse solver to solve contacts.
Overrides: object.__init__

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(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(self)

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

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(self, a, b, func, data=None)

 

Register func to be called when a collision is found between 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

Parameters
shapeA : Shape
The first shape
shapeB : Shape
The second shape
contacts : [Contact]
A list of contacts
normal_coef : float
The normal coefficient
data : any
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.

remove_collisionpair_func(self, a, b)

 
Remove the collision pair function between shapes with collision_type which match a and b.
Parameters:
  • a (int) - The collision_type for the first shape
  • b (int) - The collision_type for the second shape

set_default_collisionpair_func(self, func, data=None)

 
Sets the default collsion pair function. Passing None as func will reset it to default. See add_collisionpair_func for a details on func

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

 
Query the space for collisions between a point and its shapes (both static and nonstatic shapes)
Parameters:
  • point ((x,y) or Vec2d) - Define where to check for collision in the space.
  • func (func(shape, data)) - Called when a collision is found
  • shape (Shape) - The colliding shape
  • data (any) - Data argument sent to the point_query function

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

 
Query the space for collisions between a point and the static shapes in the space. Call the callback function when a colliosion is found.
Parameters:
  • point ((x,y) or Vec2d) - Define where to check for collision in the space.
  • func (func(shape, data)) - The callback function.
  • shape (Shape) - The colliding shape
  • data (any) - Data argument sent to the point_query function

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

 
Query the space for collisions between a point and the non static shapes in the space
Parameters:
  • point ((x,y) or Vec2d) - Define where to check for collision in the space.
  • func (func(shape, data)) - Called when a collision is found
  • shape (Shape) - The colliding shape
  • data (any) - Data argument sent to the point_query function

Property Details

shapes

Get Method:
_get_shapes(self)

static_shapes

Get Method:
_get_static_shapes(self)

bodies

Get Method:
_get_bodies(self)

gravity

Get Method:
_get_gravity(self)
Set Method:
_set_gravity(self, gravvec)

damping

Get Method:
_get_damping(self)
Set Method:
_set_damping(self, damping)

stamp

Time stamp. Is incremented on every call to step()
Get Method:
_get_stamp(self)

arbiters

List of active arbiters for the impulse solver.
Get Method:
_get_arbiters(self)