# README
cp
Go port of Chipmunk2D physics library.
import "github.com/jakecoffman/cp/v2"
Project status
Stable -- most features are implemented and the demos are very close to Chipmunk2D demos.
Examples
- github.com/jakecoffman/cp-examples contains the port of all of the Chipmunk2D demos.
- github.com/hajimehoshi/ebiten/blob/main/examples/chipmunk/main.go is an example using Ebitengine
- github.com/gen2brain/raylib-go/blob/master/examples/physics/chipmunk/main.go is an example with raylib's Go port
Documentation
The official chipmunk docs are a really good place to start: https://chipmunk-physics.net/release/ChipmunkLatest-Docs/
Features
Same features as Chipmunk2D:
- Designed specifically for 2D video games.
- Circle, convex polygon, and beveled line segment collision primitives.
- Multiple collision primitives can be attached to a single rigid body.
- Fast broad phase collision detection by using a bounding box tree with great temporal coherence or a spatial hash.
- Extremely fast impulse solving by utilizing Erin Catto’s contact persistence algorithm.
- Supports sleeping objects that have come to rest to reduce the CPU load.
- Support for collision event callbacks based on user definable object types types.
- Flexible collision filtering system with layers, exclusion groups and callbacks.
- Can be used to create all sorts of effects like one way platforms or buoyancy areas. (Examples included)
- Supports nearest point, segment (raycasting), shape and bounding box queries to the collision detection system.
- Collision impulses amounts can be retrieved for gameplay effects, sound effects, etc.
- Large variety of joints – easily make vehicles, ragdolls, and more.
- Joint callbacks.
- Can be used to easily implement breakable or animated joints. (Examples included)
- Maintains a contact graph of all colliding objects.
- No external dependencies.
- Many language bindings available.
- Simple, read the documentation and see!
- Unrestrictive MIT license
# Functions
No description provided by the author
No description provided by the author
AreaForCircle returns area of a hollow circle.
AreaForPoly calculates the signed area of a polygon.
AreaForSegment calculates the area of a fattened (capsule shaped) line segment.
BodyUpdatePosition is default position integration function.
BodyUpdateVelocity is default velocity integration function.
No description provided by the author
CentroidForPoly calculates the natural centroid of a polygon.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Collide performs a collision between two shapes.
No description provided by the author
No description provided by the author
ContactPoints finds contact point pairs on two support edges' surfaces.
No description provided by the author
QuickHull seemed like a neat algorithm, and efficient-ish for large input sets.
DebugInfo returns info of space.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Recursive function used by cpPolylineSimplifyCurves().
No description provided by the author
No description provided by the author
No description provided by the author
EPA is called from GJK when two shapes overlap.
EPARecurse implementation of the EPA loop.
No description provided by the author
ForAngle returns the unit length vector for the given angle (in radians).
GJK finds the closest points between two shapes using the GJK algorithm.
GJKRecurse implementation of the GJK loop.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
The looping and sample caching code is shared between cpMarchHard() and cpMarchSoft().
No description provided by the author
Trace an aliased curve of an image along a particular threshold.
Trace an anti-aliased contour of an image along a particular threshold.
MomentForBox calculates the moment of inertia for a solid box.
MomentForBox2 calculates the moment of inertia for a solid box.
MomentForCircle calculates the moment of inertia for a circle.
MomentForPoly calculates the moment of inertia for a solid polygon shape assuming it's center of gravity is at it's centroid.
MomentForSegment calculates the moment of inertia for a line segment.
No description provided by the author
NewBB is convenience constructor for BB structs.
NewBBForCircle constructs a BB for a circle with the given position and radius.
NewBBForExtents constructs a BB centered on a point with the given extents (half sizes).
No description provided by the author
NewBody Initializes a rigid body with the given mass and moment of inertia.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
NewHashSet is a HashSet constructor.
NewKinematicBody allocates and initializes a Body, and set it as a kinematic body.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
NewShapeFilter creates a new collision filter.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
NewStaticBody allocates and initializes a Body, and set it as a static body.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Add a segment to a polyline set.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
SpaceArbiterSetFilter throws away old arbiters.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# Constants
Body types.
Body types.
Body types.
No description provided by the author
Collison is no longer active.
Arbiter is active and its the first collision.
Collision has been explicitly ignored.
Collison arbiter is invalid because one of the shapes was removed.
Arbiter is active and its not the first collision.
No description provided by the author
Draw flags.
Draw flags.
Draw flags.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# Variables
Value for Shape layers signifying that a shape is in every layer.
No description provided by the author
No description provided by the author
No description provided by the author
Value for group signifying that a shape is in no group.
SHAPE_FILTER_ALL is s collision filter value for a shape that will collide with anything except SHAPE_FILTER_NONE.
SHAPE_FILTER_NONE is a collision filter value for a shape that does not collide with anything.
No description provided by the author
No description provided by the author
No description provided by the author
# Structs
Arbiter struct tracks pairs of colliding shapes.
No description provided by the author
BB is Chipmunk's axis-aligned 2D bounding box type.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
CollisionHandler is struct that holds function callback pointers to configure custom collision handling.
CollisionInfo collision info struct.
No description provided by the author
No description provided by the author
No description provided by the author
ContactPointSet wraps up the important collision data for an arbiter.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
16 bytes.
No description provided by the author
No description provided by the author
No description provided by the author
HashSet implements a hash set.
HashSetBin implements a linked list.
No description provided by the author
No description provided by the author
Mat2x2 is a 2x2 matrix type used for tensors and such.
MinkowskiPoint is a point on the surface of two shapes' minkowski difference.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
PointQueryInfo is point query info struct.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
SegmentQueryInfo is segment query info struct.
No description provided by the author
ShapeFilter is fast collision filtering type that is used to determine if two objects collide before calling collision or query callbacks.
ShapeMassInfo is mass info struct.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
# Interfaces
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
SpatialIndexer implemented by BBTree.
# Type aliases
No description provided by the author
BodyPositionFunc is rigid body position update function type.
BodyVelocityFunc is rigid body velocity update function type.
CollisionBeginFunc is collision begin event function callback type.
No description provided by the author
CollisionPostSolveFunc is collision post-solve event function callback type.
CollisionPreSolveFunc is collision pre-solve event function callback type.
CollisionSeparateFunc is collision separate event function callback type.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
This is a user defined function that gets passed every single point from the bounding box the user passes into the March process - you can use this to sample an image and check for alpha values or really any 2d matrix you define like a tile map.
This is a user defined function that gets passed in to the Marching process the user establishes a PolyLineSet, passes a pointer to their function, and they populate it.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author