Shapes
abstract class CP::Shape
inherits Reference
#
Defines the shape of a rigid body.
Direct known subclasses
CP::Shape::Circle
CP::Shape::Poly
CP::Shape::Segment
Methods#
#bb : BB
#
Get the bounding box that contains the shape given its current position and angle.
Only guaranteed to be valid after cache_bb
or Space#step
is called.
Moving a body that a shape is connected to does not update its bounding box.
For shapes used for queries that aren't attached to bodies, you can also use update
.
#body=(body : Body | Nil)
#
Set the Body
this shape is added to.
Can only be used if the shape is not currently added to a space.
#cache_bb : BB
#
Update, cache and return the bounding box of a shape based on the body it's attached to.
#collision_type : CollisionType
#
User defined collision type for the shape.
See Space#add_collision_handler
for more information.
#density : Float64
#
Get the density of the shape if you are having Chipmunk calculate mass properties for you.
#density=(density : Number)
#
Set the density of this shape to have Chipmunk calculate mass properties for you.
#elasticity : Float64
#
The elasticity of this shape.
A value of 0.0 gives no bounce, while a value of 1.0 will give a 'perfect' bounce. However due to inaccuracies in the simulation using 1.0 or greater is not recommended.
#friction : Float64
#
The friction of this shape.
Chipmunk uses the Coulomb friction model, a value of 0.0 is frictionless. A value over 1.0 is also perfectly fine.
#mass : Float64
#
Get the mass of the shape if you are having Chipmunk calculate mass properties for you.
#mass=(mass : Number)
#
Set the mass of this shape to have Chipmunk calculate mass properties for you.
#point_query(p : Vect) : PointQueryInfo
#
Perform a nearest point query. It finds the closest point on the surface of shape to a specific point.
#segment_query(a : Vect, b : Vect, radius : Number = 0) : SegmentQueryInfo | Nil
#
Perform a segment query against a shape: check if the line segment from start to end intersects the shape.
#sensor? : Bool
#
Is the shape set to be a sensor or not?
Sensors only call collision callbacks, and never generate real collisions.
#surface_velocity : Vect
#
The surface velocity of this shape.
Useful for creating conveyor belts or players that move around. This value is only used when calculating friction, not resolving the collision.
#update(transform : Transform) : BB
#
Update, cache and return the bounding box of a shape with an explicit transformation.
Useful if you have a shape without a body and want to use it for querying.
struct CP::ShapeFilter
inherits Struct
#
Fast collision filtering type that is used to determine if two objects collide before calling collision or query callbacks.
Chipmunk has two primary means of ignoring collisions: groups and category masks.
Groups are used to ignore collisions between parts on a complex object. A ragdoll is a good example. When jointing an arm onto the torso, you'll want them to allow them to overlap. Groups allow you to do exactly that. Shapes that have the same group don't generate collisions. So by placing all of the shapes in a ragdoll in the same group, you'll prevent it from colliding against other parts of itself.
Category masks allow you to mark which categories an object belongs to and which categories it collidies with. By default, objects exist in every category and collide with every category.
The type of categories and mask in ShapeFilter
is UInt32
.
There is one last way of filtering collisions using collision handlers. See the section on callbacks for more information. Collision handlers can be more flexible, but can be slower. Fast collision filtering rejects collisions before running the expensive collision detection code, so using groups or category masks is preferred.
Constants#
ALL = new(NO_GROUP, ALL_CATEGORIES, ALL_CATEGORIES)
#
Collision filter value for a shape that will collide with anything except NONE
.
ALL_CATEGORIES = ~(Bitmask.new(0))
#
Value for signifying that a shape is in every category.
NO_GROUP = Group.new(0)
#
Value signifying that a shape is in no group.
NONE = new(NO_GROUP, ~ALL_CATEGORIES, ~ALL_CATEGORIES)
#
Collision filter value for a shape that does not collide with anything.
Constructors#
.new(group : Int = NO_GROUP, categories : Int = ALL_CATEGORIES, mask : Int = ALL_CATEGORIES)
#
Methods#
#categories : Bitmask
#
A bitmask of user definable categories that this object belongs to.
The category/mask combinations of both objects in a collision must agree for a collision to occur.
#group : Group
#
Two objects with the same non-zero group value do not collide.
This is generally used to group objects in a composite object together to disable self collisions.
#mask : Bitmask
#
A bitmask of user definable category types that this object object collides with.
The category/mask combinations of both objects in a collision must agree for a collision to occur.