Skip to main content

Class: Constraint

physics/constraints/constraint.Constraint

Represents a distance constraint between two bodies or a body and a point.

The constraint points are in local space of their body.

If the constraint is between a body and a point then the given point is in world space.

Hierarchy

Constructors

constructor

โ€ข new Constraint(a, b)

Creates a new Constraint between two bodies.

Parameters

NameTypeDescription
aCollisionObjectThe first body
bCollisionObjectThe second body

Defined in

src/physics/constraints/constraint.ts:43

โ€ข new Constraint(opts)

Creates a new Constraint with the given options.

Parameters

NameTypeDescription
optsConstraintOptionsThe constraint options

Defined in

src/physics/constraints/constraint.ts:50

โ€ข new Constraint(a, point)

Creates a new Constraint between a body and a point.

Parameters

NameTypeDescription
aCollisionObjectThe body to constrain
pointvec2A point in world space

Defined in

src/physics/constraints/constraint.ts:58

Properties

a

โ€ข a: CollisionObject

Defined in

src/physics/constraints/constraint.ts:22


anchorA

โ€ข anchorA: vec2

Defined in

src/physics/constraints/constraint.ts:23


anchorB

โ€ข anchorB: vec2

Defined in

src/physics/constraints/constraint.ts:27


b

โ€ข b: CollisionObject

Defined in

src/physics/constraints/constraint.ts:26


errorBias

โ€ข errorBias: number

Defined in

src/physics/constraints/constraint.ts:32


maxBias

โ€ข maxBias: number = Infinity

Defined in

src/physics/constraints/constraint.ts:33


maxForce

โ€ข maxForce: number = Infinity

Defined in

src/physics/constraints/constraint.ts:35


point

โ€ข point: vec2

Defined in

src/physics/constraints/constraint.ts:30


rotA

โ€ข rotA: number = 0

Defined in

src/physics/constraints/constraint.ts:24


rotB

โ€ข rotB: number = 0

Defined in

src/physics/constraints/constraint.ts:28

Methods

applyImpulses

โ–ธ Protected applyImpulses(impulse, direction): void

Parameters

NameType
impulsenumber
directionvec2

Returns

void

Defined in

src/physics/constraints/constraint.ts:111

โ–ธ Protected applyImpulses(impulse): void

Parameters

NameType
impulsevec2

Returns

void

Defined in

src/physics/constraints/constraint.ts:113


biasCoef

โ–ธ Protected biasCoef(dt): number

Calculates the velocity bias coefficient.

Parameters

NameTypeDescription
dtnumberThe time since the last update

Returns

number

Defined in

src/physics/constraints/constraint.ts:182


calculateRelativeVelocity

โ–ธ Protected calculateRelativeVelocity(pointA, pointB): vec2

Calculate the relative velocity of the bodies in the constraint.

Parameters

NameTypeDescription
pointAvec2The anchor point on body a
pointBvec2The anchor point on body b

Returns

vec2

The relative velocity between body a and b or body a and the anchor point

Defined in

src/physics/constraints/constraint.ts:164


isBodyToPoint

โ–ธ isBodyToPoint(): boolean

Determines wether or not the constraint is between a body and a point.

Returns

boolean

Wether or not the constraint is between a body and a point.

Defined in

src/physics/constraints/constraint.ts:107


kScalar

โ–ธ Protected kScalar(n): number

Computes the k scalar value for the constraint.

Parameters

NameTypeDescription
nvec2The constraint's delta normal

Returns

number

The k scalar value for the constraint

Defined in

src/physics/constraints/constraint.ts:205


kScalarBody

โ–ธ Protected kScalarBody(body, r, n): number

Computes the k scalar value for the given body.

Parameters

NameTypeDescription
bodyCollisionObjectThe body to calculate for
rvec2The anchor point on the body
nvec2The constraint's delta normal

Returns

number

The k scalar value for the given body

Defined in

src/physics/constraints/constraint.ts:194


kTensor

โ–ธ Protected kTensor(): mat2

Computes the k tensor matrix for the constraint.

see Chipmunk2D kTensor

Returns

mat2

k tensor matrix

Defined in

src/physics/constraints/constraint.ts:220


postSolve

โ–ธ Abstract postSolve(dt): void

Performs post solve operations.

Parameters

NameTypeDescription
dtnumberThe time since the last update

Returns

void

Defined in

src/physics/constraints/constraint.ts:100


preSolve

โ–ธ Abstract preSolve(dt): void

Prepares for constraint solving.

Parameters

NameTypeDescription
dtnumberThe time since the last update

Returns

void

Defined in

src/physics/constraints/constraint.ts:86


solve

โ–ธ Abstract solve(dt): void

Solves the constraint.

Parameters

NameTypeDescription
dtnumberThe time since the last update

Returns

void

Defined in

src/physics/constraints/constraint.ts:93


updateAnchors

โ–ธ Protected updateAnchors(): void

Updates the constraint's anchor points to match the rotations of their bodies.

Returns

void

Defined in

src/physics/constraints/constraint.ts:141