Skip to content

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#

#area : Float64#

Get the calculated area of this shape.

View source

#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.

View source

#body : Body | ::Nil#

The Body this shape is added to.

View source

#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.

View source

#cache_bb : BB#

Update, cache and return the bounding box of a shape based on the body it's attached to.

View source

#center_of_gravity : Vect#

Get the centroid of this shape.

View source

#collide(b : Shape) : ContactPointSet#

Return contact information about two shapes.

View source

#collision_type : CollisionType#

User defined collision type for the shape.

See Space#add_collision_handler for more information.

View source

#collision_type=(collision_type : Int)#

View source

#density : Float64#

Get the density of the shape if you are having Chipmunk calculate mass properties for you.

View source

#density=(density : Number)#

Set the density of this shape to have Chipmunk calculate mass properties for you.

View source

#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.

View source

#elasticity=(elasticity : Number)#

View source

#filter : ShapeFilter#

The collision filtering parameters of this shape.

View source

#filter=(filter : ShapeFilter)#

View source

#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.

View source

#friction=(friction : Number)#

View source

#mass : Float64#

Get the mass of the shape if you are having Chipmunk calculate mass properties for you.

View source

#mass=(mass : Number)#

Set the mass of this shape to have Chipmunk calculate mass properties for you.

View source

#moment : Float64#

Get the calculated moment of inertia for this shape.

View source

#point_query(p : Vect) : PointQueryInfo#

Perform a nearest point query. It finds the closest point on the surface of shape to a specific point.

View source

#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.

View source

#sensor=(sensor : Bool)#

View source

#sensor? : Bool#

Is the shape set to be a sensor or not?

Sensors only call collision callbacks, and never generate real collisions.

View source

#space : Space | ::Nil#

The Space this shape is added to.

View source

#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.

View source

#surface_velocity=(surface_velocity : Vect)#

View source

#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.

View source

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)#

View source

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.

View source

#categories=(categories : Bitmask)#

View source

#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.

View source

#group=(group : Group)#

View source

#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.

View source

#mask=(mask : Bitmask)#

View source