2021-05-11 18:30:36 -07:00

5.4 KiB
Raw Permalink Blame History

Planck.js API Doc › Globals › Shape

Class: Shape

A shape is used for collision detection. You can create a shape however you like. Shapes used for simulation in World are created automatically when a Fixture is created. Shapes may encapsulate one or more child shapes.

Hierarchy

Index

Properties

Methods

Properties

m_radius

• m_radius: number

Defined in src/collision/Shape.ts:39


m_type

• m_type: ShapeType

Defined in src/collision/Shape.ts:38

Methods

Abstract computeAABB

▸ computeAABB(aabb: AABB, xf: Transform, childIndex: number): void

Defined in src/collision/Shape.ts:116

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


Abstract computeDistanceProxy

▸ computeDistanceProxy(proxy: DistanceProxy, childIndex: number): void

Defined in src/collision/Shape.ts:127

Parameters:

Name Type
proxy DistanceProxy
childIndex number

Returns: void


Abstract computeMass

▸ computeMass(massData: MassData, density?: number): void

Defined in src/collision/Shape.ts:125

Compute the mass properties of this shape using its dimensions and density. The inertia tensor is computed about the local origin.

Parameters:

Name Type Description
massData MassData Returns the mass data for this shape.
density? number The density in kilograms per meter squared.

Returns: void


Abstract getChildCount

▸ getChildCount(): number

Defined in src/collision/Shape.ts:87

Get the number of child primitives.

Returns: number


getRadius

▸ getRadius(): number

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.


Abstract rayCast

▸ rayCast(output: RayCastOutput, input: RayCastInput, xf: Transform, childIndex: number): boolean

Defined in src/collision/Shape.ts:106

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


Abstract testPoint

▸ testPoint(xf: Transform, p: Vec2): boolean

Defined in src/collision/Shape.ts:96

Test a point for containment in this shape. This only works for convex shapes.

Parameters:

Name Type Description
xf Transform The shape world transform.
p Vec2 A point in world coordinates.

Returns: boolean


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