class CP::Space
- CP::Space
- Reference
- Object
Overview
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.
Defined in:
chipmunk/debug_draw.crchipmunk/space.cr
Constructors
Instance Method Summary
-
#add(body : Body) : Body
Add a body to the simulation.
-
#add(shape : Shape) : Shape
Add a shape to the simulation.
-
#add(constraint : Constraint) : Constraint
Add a constraint to the simulation.
-
#add(*items : Shape | Body | Constraint)
Add multiple items
-
#add_collision_handler(a : Int, b : Int, handler : CollisionHandler) : CollisionHandler
Whenever shapes with collision types a and b collide, this handler will be used to process the collision events.
-
#add_collision_handler(type : Int, handler : CollisionHandler) : CollisionHandler
Set a wildcard collision handler for the specified type.
-
#add_collision_handler(handler : CollisionHandler) : CollisionHandler
Set a collision handler that is called for all collisions that are not handled by a more specific collision handler.
-
#bb_query(bb : BB, filter : ShapeFilter = ShapeFilter::ALL, &block : Shape -> )
Perform a fast rectangle query on the space, yielding each shape found.
-
#bb_query(bb : BB, filter : ShapeFilter = ShapeFilter::ALL) : Array(Shape)
Perform a fast rectangle query on the space, yielding each shape found.
-
#bodies : Set(Body)
Get all the bodies that are added to the space.
-
#collision_bias : Float64
Determines how fast overlapping shapes are pushed apart.
- #collision_bias=(collision_bias : Number)
-
#collision_persistence : Timestamp
Number of frames that contact information should persist.
- #collision_persistence=(collision_persistence : Timestamp)
-
#collision_slop : Float64
Amount of encouraged penetration between colliding shapes.
- #collision_slop=(collision_slop : Number)
-
#constraints : Set(Constraint)
Get all the constraints that are added to the space.
-
#contains?(body : Body) : Bool
Test if a body has been added to the space.
-
#contains?(shape : Shape) : Bool
Test if a shape has been added to the space.
-
#contains?(constraint : Constraint) : Bool
Test if a constraint has been added to the space.
-
#current_time_step : Float64
Returns the current (or most recent) time step used with the given space.
-
#damping : Float64
Damping rate expressed as the fraction of velocity bodies retain each second.
- #damping=(damping : Number)
-
#each_body(&block : Body -> )
Yield each body in the space.
-
#each_constraint(&block : Constraint -> )
Yield each constraint in the space.
-
#each_shape(&block : Shape -> )
Yield each shape in the space.
-
#gravity : Vect
Gravity to pass to rigid bodies when integrating velocity.
- #gravity=(gravity : Vect)
-
#idle_speed_threshold : Float64
Speed threshold for a body to be considered idle.
- #idle_speed_threshold=(idle_speed_threshold : Number)
-
#iterations : Int32
Number of iterations to use in the impulse solver to solve contacts and other constraints.
- #iterations=(iterations : Int)
-
#locked? : Bool
Returns true from inside a callback when objects cannot be added/removed.
-
#point_query(point : Vect, max_distance : Number = 0, filter : ShapeFilter = ShapeFilter::ALL, &block : PointQueryInfo -> )
Query the space at a point for shapes within the given distance range.
-
#point_query(point : Vect, max_distance : Number = 0, filter : ShapeFilter = ShapeFilter::ALL) : Array(PointQueryInfo)
Query the space at a point for shapes within the given distance range.
-
#point_query_nearest(point : Vect, max_distance : Number = 0, filter : ShapeFilter = ShapeFilter::ALL) : PointQueryInfo | Nil
Query the space at a point and return the nearest shape found.
-
#reindex(shape : Shape)
Update the collision detection data for a specific shape in the space.
-
#reindex_shapes_for(body : Body)
Update the collision detection data for all shapes attached to a body.
-
#reindex_static
Update the collision detection info for the static shapes in the space.
-
#remove(body : Body)
Remove a body from the simulation.
-
#remove(shape : Shape)
Remove a shape from the simulation.
-
#remove(constraint : Constraint)
Remove a constraint from the simulation.
-
#remove(*items : Shape | Body | Constraint)
Remove multiple items
-
#segment_query(start : Vect, end end_ : Vect, radius : Number = 0, filter : ShapeFilter = ShapeFilter::ALL, &block : SegmentQueryInfo -> )
Perform a directed line segment query (like a raycast) against the space and yield each shape intersected.
-
#segment_query(start : Vect, end end_ : Vect, radius : Number = 0, filter : ShapeFilter = ShapeFilter::ALL) : Array(SegmentQueryInfo)
Perform a directed line segment query (like a raycast) against the space and yield each shape intersected.
-
#segment_query_first(start : Vect, end end_ : Vect, radius : Number = 0, filter : ShapeFilter = ShapeFilter::ALL) : SegmentQueryInfo | Nil
Perform a directed line segment query (like a raycast) against the space and return the first shape hit.
-
#shape_query(shape : Shape, &block : Shape, ContactPointSet -> )
Query a space for any shapes overlapping the given shape and yield each shape found.
-
#shape_query(shape : Shape) : Array(Shape)
Query a space for any shapes overlapping the given shape and yield each shape found.
-
#shapes : Set(Shape)
Get all the shapes that are added to the space.
-
#sleep_time_threshold : Float64
Time a group of bodies must remain idle in order to fall asleep.
- #sleep_time_threshold=(sleep_time_threshold : Number)
- #static_body : Body
-
#step(dt : Number)
Step the space forward in time by dt seconds.
-
#threads : Int
Returns number of threads for multithreaded physics solver or 0 if the space isn't hasty
-
#threads=(nthreads : Int)
Set number of threads for multithreaded physics solver
-
#use_spatial_hash(dim : Number, count : Int)
Switch the space to use a spatial has as its spatial index.
Constructor Detail
Instance Method Detail
Add a body to the simulation.
If this method is called during a simulation step, the addition will be delayed until the step is finished.
Returns the same Body
, for convenience.
Add a shape to the simulation.
If the collision shape is attached to a static body, it will be added as a static shape.
If this method is called during a simulation step, the addition will be delayed until the step is finished.
Returns the same Shape
, for convenience.
Add a constraint to the simulation.
If this method is called during a simulation step, the addition will be delayed until the step is finished.
Returns the same Constraint
, for convenience.
Whenever shapes with collision types a and b collide, this handler will be used to process the collision events.
If wildcard handlers are used with either of the collision types, it's the responibility of the custom handler to invoke the wildcard handlers.
Set a wildcard collision handler for the specified type.
This handler will be used any time an object with this type collides with another object, regardless of its type.
Set a collision handler that is called for all collisions that are not handled by a more specific collision handler.
Perform a fast rectangle query on the space, yielding each shape found.
Only the shapes' bounding boxes are checked for overlap, not their full shape.
Perform a fast rectangle query on the space, yielding each shape found.
Only the shapes' bounding boxes are checked for overlap, not their full shape.
Determines how fast overlapping shapes are pushed apart.
Expressed as a fraction of the error remaining after each second.
Defaults to (1.0 - 0.1)**60.0
meaning that Chipmunk fixes 10% of overlap each frame at 60Hz.
Number of frames that contact information should persist.
Defaults to 3. There is probably never a reason to change this value.
Amount of encouraged penetration between colliding shapes.
Used to reduce oscillating contacts and keep the collision cache warm. Defaults to 0.1. If you have poor simulation quality, increase this number as much as possible without allowing visible amounts of overlap.
Returns the current (or most recent) time step used with the given space.
Useful from callbacks if your time step is not a compile-time global.
Damping rate expressed as the fraction of velocity bodies retain each second.
A value of 0.9 would mean that each body's velocity will drop 10% per second. The default value is 1.0, meaning no damping is applied.
Note: This damping value is different than those of DampedSpring
and DampedRotarySpring
.
Gravity to pass to rigid bodies when integrating velocity.
Defaults to (0,0).
Speed threshold for a body to be considered idle.
The default value of 0 means to let the space guess a good threshold based on gravity.
Number of iterations to use in the impulse solver to solve contacts and other constraints.
Chipmunk uses an iterative solver to figure out the forces between objects in the space. What this means is that it builds a big list of all of the collisions, joints, and other constraints between the bodies and makes several passes over the list considering each one individually. The number of passes it makes is the iteration count, and each iteration makes the solution more accurate. If you use too many iterations, the physics should look nice and solid, but may use up too much CPU time. If you use too few iterations, the simulation may seem mushy or bouncy when the objects should be solid. Setting the number of iterations lets you balance between CPU usage and the accuracy of the physics. Chipmunk's default of 10 iterations is sufficient for most simple games.
Query the space at a point for shapes within the given distance range.
The filter is applied to the query and follows the same rules as the collision detection. Sensor shapes are included. If a max_distance of 0 is used, the point must lie inside a shape. Negative max_distance is also allowed meaning that the point must be a under a certain depth within a shape to be considered a match.
Query the space at a point for shapes within the given distance range.
The filter is applied to the query and follows the same rules as the collision detection. Sensor shapes are included. If a max_distance of 0 is used, the point must lie inside a shape. Negative max_distance is also allowed meaning that the point must be a under a certain depth within a shape to be considered a match.
Query the space at a point and return the nearest shape found.
Returns nil if no shapes were found.
Update the collision detection data for a specific shape in the space.
Update the collision detection data for all shapes attached to a body.
Remove a body from the simulation.
If this method is called during a simulation step, the removal will be delayed until the step is finished.
Remove a shape from the simulation.
If this method is called during a simulation step, the removal will be delayed until the step is finished.
Remove a constraint from the simulation.
If this method is called during a simulation step, the removal will be delayed until the step is finished.
Perform a directed line segment query (like a raycast) against the space and yield each shape intersected.
The filter is applied to the query and follows the same rules as the collision detection. Sensor shapes are included.
Perform a directed line segment query (like a raycast) against the space and yield each shape intersected.
The filter is applied to the query and follows the same rules as the collision detection. Sensor shapes are included.
Perform a directed line segment query (like a raycast) against the space and return the first shape hit.
Returns nil if no shapes were hit.
Query a space for any shapes overlapping the given shape and yield each shape found.
Query a space for any shapes overlapping the given shape and yield each shape found.
Time a group of bodies must remain idle in order to fall asleep.
Enabling sleeping also implicitly enables the the contact graph. The default value of INFINITY disables the sleeping algorithm.
The Space
provided static body for a given Space
.
This is merely provided for convenience and you are not required to use it.
Returns number of threads for multithreaded physics solver or 0 if the space isn't hasty
Switch the space to use a spatial has as its spatial index.