11 KiB
Planck.js API Doc › Globals › ChainShape
Class: ChainShape
A chain shape is a free form sequence of line segments. The chain has two-sided collision, so you can use inside and outside collision. Therefore, you may use any winding order. Connectivity information is used to create smooth collisions.
WARNING: The chain will not collide properly if there are self-intersections.
Hierarchy
-
↳ ChainShape
Index
Constructors
Properties
- m_count
- m_hasNextVertex
- m_hasPrevVertex
- m_isLoop
- m_nextVertex
- m_prevVertex
- m_radius
- m_type
- m_vertices
- TYPE
Methods
- computeAABB
- computeDistanceProxy
- computeMass
- getChildCount
- getChildEdge
- getNextVertex
- getPrevVertex
- getRadius
- getType
- getVertex
- isLoop
- rayCast
- setNextVertex
- setPrevVertex
- testPoint
- isValid
Constructors
constructor
+ new ChainShape(vertices?: Vec2[], loop?: boolean): ChainShape
Defined in src/collision/shape/ChainShape.ts:57
Parameters:
| Name | Type |
|---|---|
vertices? |
Vec2[] |
loop? |
boolean |
Returns: ChainShape
Properties
m_count
• m_count: number
Defined in src/collision/shape/ChainShape.ts:51
m_hasNextVertex
• m_hasNextVertex: boolean
Defined in src/collision/shape/ChainShape.ts:55
m_hasPrevVertex
• m_hasPrevVertex: boolean
Defined in src/collision/shape/ChainShape.ts:54
m_isLoop
• m_isLoop: boolean
Defined in src/collision/shape/ChainShape.ts:57
m_nextVertex
• m_nextVertex: Vec2 | null
Defined in src/collision/shape/ChainShape.ts:53
m_prevVertex
• m_prevVertex: Vec2 | null
Defined in src/collision/shape/ChainShape.ts:52
m_radius
• m_radius: number
Defined in src/collision/Shape.ts:39
m_type
• m_type: ShapeType
Defined in src/collision/Shape.ts:38
m_vertices
• m_vertices: Vec2[]
Defined in src/collision/shape/ChainShape.ts:50
Static TYPE
▪ TYPE: "chain" = 'chain' as 'chain'
Defined in src/collision/shape/ChainShape.ts:48
Methods
computeAABB
▸ computeAABB(aabb: AABB, xf: Transform, childIndex: number): void
Overrides Shape.computeAABB
Defined in src/collision/shape/ChainShape.ts:327
Given a transform, compute the associated axis aligned bounding box for a child shape.
Parameters:
| Name | Type | Description |
|---|---|---|
aabb |
AABB | Returns the axis aligned box. |
xf |
Transform | The world transform of the shape. |
childIndex |
number | The child shape |
Returns: void
computeDistanceProxy
▸ computeDistanceProxy(proxy: DistanceProxy, childIndex: number): void
Overrides Shape.computeDistanceProxy
Defined in src/collision/shape/ChainShape.ts:351
Parameters:
| Name | Type |
|---|---|
proxy |
DistanceProxy |
childIndex |
number |
Returns: void
computeMass
▸ computeMass(massData: MassData, density?: number): void
Overrides Shape.computeMass
Defined in src/collision/shape/ChainShape.ts:345
Compute the mass properties of this shape using its dimensions and density. The inertia tensor is computed about the local origin.
Chains have zero mass.
Parameters:
| Name | Type | Description |
|---|---|---|
massData |
MassData | Returns the mass data for this shape. |
density? |
number | The density in kilograms per meter squared. |
Returns: void
getChildCount
▸ getChildCount(): number
Overrides Shape.getChildCount
Defined in src/collision/shape/ChainShape.ts:247
Get the number of child primitives.
Returns: number
getChildEdge
▸ getChildEdge(edge: EdgeShape, childIndex: number): void
Defined in src/collision/shape/ChainShape.ts:253
Parameters:
| Name | Type |
|---|---|
edge |
EdgeShape |
childIndex |
number |
Returns: void
getNextVertex
▸ getNextVertex(): Vec2
Defined in src/collision/shape/ChainShape.ts:222
Returns: Vec2
getPrevVertex
▸ getPrevVertex(): Vec2
Defined in src/collision/shape/ChainShape.ts:209
Returns: Vec2
getRadius
▸ getRadius(): number
Inherited from Shape.getRadius
Defined in src/collision/Shape.ts:62
Returns: number
getType
▸ getType(): ShapeType
Defined in src/collision/Shape.ts:72
Get the type of this shape. You can use this to down cast to the concrete shape.
Returns: ShapeType
the shape type.
getVertex
▸ getVertex(index: number): Vec2
Defined in src/collision/shape/ChainShape.ts:278
Parameters:
| Name | Type |
|---|---|
index |
number |
Returns: Vec2
isLoop
▸ isLoop(): boolean
Defined in src/collision/shape/ChainShape.ts:287
Returns: boolean
rayCast
▸ rayCast(output: RayCastOutput, input: RayCastInput, xf: Transform, childIndex: number): boolean
Defined in src/collision/shape/ChainShape.ts:312
Cast a ray against a child shape.
Parameters:
| Name | Type | Description |
|---|---|---|
output |
RayCastOutput | The ray-cast results. |
input |
RayCastInput | The ray-cast input parameters. |
xf |
Transform | The transform to be applied to the shape. |
childIndex |
number | The child shape index |
Returns: boolean
setNextVertex
▸ setNextVertex(nextVertex: Vec2): void
Defined in src/collision/shape/ChainShape.ts:217
Establish connectivity to a vertex that follows the last vertex. Don't call this for loops.
Parameters:
| Name | Type |
|---|---|
nextVertex |
Vec2 |
Returns: void
setPrevVertex
▸ setPrevVertex(prevVertex: Vec2): void
Defined in src/collision/shape/ChainShape.ts:204
Establish connectivity to a vertex that precedes the first vertex. Don't call this for loops.
Parameters:
| Name | Type |
|---|---|
prevVertex |
Vec2 |
Returns: void
testPoint
▸ testPoint(xf: Transform, p: Vec2): false
Defined in src/collision/shape/ChainShape.ts:300
Test a point for containment in this shape. This only works for convex shapes.
This always return false.
Parameters:
| Name | Type | Description |
|---|---|---|
xf |
Transform | The shape world transform. |
p |
Vec2 | A point in world coordinates. |
Returns: false
Static isValid
▸ isValid(shape: Shape | null | undefined): shape is Shape
Defined in src/collision/Shape.ts:58
Parameters:
| Name | Type |
|---|---|
shape |
Shape | null | undefined |
Returns: shape is Shape