- Source:
Classes
- BB
- BBTree
- Body
- BoxShape
- CircleShape
- CollisionHandler
- PolyShape
- SegmentShape
- Shape
- Space
- SpatialIndex
- Vect
Members
(static, constant) CP_ALL_LAYERS
- Source:
(static, constant) CP_NO_GROUP
- Source:
Methods
(static) areaForCircle(r1, r2) → {number}
- Source:
Calculate area of a hollow circle.
Parameters:
Name | Type | Description |
---|---|---|
r1 |
number | Inner diameter. A solid circle has an inner diameter of 0. |
r2 |
number | Outer diameter. |
Returns:
Area.
- Type
- number
(static) areaForPoly(verts) → {number}
- Source:
Calculate the signed area of a polygon.
A Clockwise winding gives positive area.
This is probably backwards from what you expect, but matches Chipmunk's the winding for poly shapes.
Parameters:
Name | Type | Description |
---|---|---|
verts |
Array.<number> | Array of vertices. |
Returns:
Area.
- Type
- number
(static) areaForSegment(a, b, r) → {number}
- Source:
Calculate the area of a fattened (capsule shaped) line segment.
Parameters:
Name | Type | Description |
---|---|---|
a |
number | One endpoint of segment. |
b |
number | Another endpoint of segment. |
r |
number |
Returns:
- Type
- number
(static) bb(l, b, r, t) → {cp.BB}
Parameters:
Name | Type | Description |
---|---|---|
l |
number | Left. |
b |
number | Bottom. |
r |
number | Right. |
t |
number | Top. |
Returns:
- Type
- cp.BB
(static) BoxShape2(body, box) → {cp.PolyShape}
- Source:
Initialize an offset box shaped polygon shape.
Parameters:
Name | Type | Description |
---|---|---|
body |
cp.Body | |
box |
cp.BB |
Returns:
- Type
- cp.PolyShape
(static) centroidForPoly(verts) → {cp.Vect}
- Source:
Calculate the natural centroid of a polygon.
Parameters:
Name | Type | Description |
---|---|---|
verts |
Array.<number> | Array of vertices. |
Returns:
Centroid point.
- Type
- cp.Vect
(static) collideShapes(a, b) → {Array.<Contact>}
- Source:
Parameters:
Name | Type | Description |
---|---|---|
a |
cp.Shape | |
b |
cp.Shape |
Returns:
- Type
- Array.<Contact>
(static) convexHull(verts, result, tolerance) → {array}
- Source:
Calculate the convex hull of a given set of points.
Parameters:
Name | Type | Description |
---|---|---|
verts |
Array.<number> | |
result |
array | |
tolerance |
number | The allowed amount to shrink the hull when simplifying it. A tolerance of 0.0 creates an exact hull. |
Returns:
- Type
- array
(static) loopIndexes(verts) → {Array.<number>}
- Source:
Parameters:
Name | Type | Description |
---|---|---|
verts |
Array.<number> |
Returns:
- Type
- Array.<number>
(static) momentForBox(m, width, height) → {number}
- Source:
Calculate the moment of inertia for a solid box.
Parameters:
Name | Type | Description |
---|---|---|
m |
number | Mass of the box. |
width |
number | Box width. |
height |
number | Box height. |
Returns:
- Type
- number
(static) momentForBox2(m, box) → {number}
- Source:
Calculate the moment of inertia for a solid box.
Parameters:
Name | Type | Description |
---|---|---|
m |
number | Mass of the box. |
box |
cp.PolyShape | Target box. |
Returns:
- Type
- number
(static) momentForCircle(m, r1, r2, offset) → {number}
- Source:
Calculate the moment of inertia for a circle.
Parameters:
Name | Type | Description |
---|---|---|
m |
number | |
r1 |
number | Inner diameter. A solid circle has an inner diameter of 0. |
r2 |
number | Outer diameter. |
offset |
cp.Vect |
Returns:
Moment.
- Type
- number
(static) momentForPoly(m, verts, offset) → {number}
- Source:
Calculate the moment of inertia for a solid polygon shape assuming it's center of gravity is at it's centroid.
Parameters:
Name | Type | Description |
---|---|---|
m |
number | |
verts |
Array.<number> | Array of vertices. |
offset |
cp.Vect | The offset is added to each vertex. |
Returns:
Moment.
- Type
- number
(static) momentForSegment(m, a, b) → {number}
- Source:
Calculate the moment of inertia for a line segment.
Parameters:
Name | Type | Description |
---|---|---|
m |
number | |
a |
cp.Vect | One endpoint of segment. |
b |
cp.Vect | Another endpoint of segment. |
Returns:
- Type
- number
(static) recenterPoly(verts)
- Source:
Parameters:
Name | Type | Description |
---|---|---|
verts |
Array.<number> | Array of vertices. |
(static) resetShapeIdCounter()
- Source:
(static) v(x, y) → {cp.Vect}
Parameters:
Name | Type | Description |
---|---|---|
x |
number | |
y |
number |
Returns:
- Type
- cp.Vect