2024-12-20 15:08:27 +03:30

4.3 KiB

Class: PolygonShape

A convex polygon. It is assumed that the interior of the polygon is to the left of each edge. Polygons have a maximum number of vertices equal to Settings.maxPolygonVertices. In most cases you should not need many vertices for a convex polygon. extends Shape

Extends

Extended by

Constructors

new PolygonShape()

new PolygonShape(vertices?): PolygonShape

Parameters

• vertices?: Vec2Value[]

Returns

PolygonShape

Overrides

Shape.constructor

Properties

style

style: Style = {}

Styling for dev-tools.

Inherited from

Shape.style


TYPE

static TYPE: "polygon"

Methods

computeAABB()

computeAABB(aabb, xf, childIndex): void

Given a transform, compute the associated axis aligned bounding box for a child shape.

Parameters

• aabb: AABBValue

Returns the axis aligned box.

• xf: TransformValue

The world transform of the shape.

• childIndex: number

The child shape

Returns

void

Overrides

Shape.computeAABB


computeDistanceProxy()

computeDistanceProxy(proxy): void

Parameters

• proxy: DistanceProxy

Returns

void

Overrides

Shape.computeDistanceProxy


computeMass()

computeMass(massData, density): void

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

Parameters

• massData: MassData

Returns the mass data for this shape.

• density: number

The density in kilograms per meter squared.

Returns

void

Overrides

Shape.computeMass


getChildCount()

getChildCount(): 1

Get the number of child primitives.

Returns

1

Overrides

Shape.getChildCount


getRadius()

getRadius(): number

Returns

number

Overrides

Shape.getRadius


getType()

getType(): "polygon"

Get the type of this shape. You can use this to down cast to the concrete shape.

Returns

"polygon"

the shape type.

Overrides

Shape.getType


rayCast()

rayCast(output, input, xf, childIndex): boolean

Cast a ray against a child shape.

Parameters

• 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

Overrides

Shape.rayCast


testPoint()

testPoint(xf, p): boolean

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

Parameters

• xf: TransformValue

The shape world transform.

• p: Vec2Value

A point in world coordinates.

Returns

boolean

Overrides

Shape.testPoint


validate()

validate(): boolean

Validate convexity. This is a very time consuming operation.

Returns

boolean

true if valid


isValid()

static isValid(obj): boolean

Parameters

• obj: any

Returns

boolean

Inherited from

Shape.isValid