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
Constraint
โณ
PivotConstraint
โณ
SpringConstraint
Constructors
constructor
โข new Constraint(a
, b
)
Creates a new Constraint between two bodies.
Parameters
Name | Type | Description |
---|---|---|
a | CollisionObject | The first body |
b | CollisionObject | The second body |
Defined in
src/physics/constraints/constraint.ts:43
โข new Constraint(opts
)
Creates a new Constraint with the given options.
Parameters
Name | Type | Description |
---|---|---|
opts | ConstraintOptions | The 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
Name | Type | Description |
---|---|---|
a | CollisionObject | The body to constrain |
point | vec2 | A 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
Name | Type |
---|---|
impulse | number |
direction | vec2 |
Returns
void
Defined in
src/physics/constraints/constraint.ts:111
โธ Protected
applyImpulses(impulse
): void
Parameters
Name | Type |
---|---|
impulse | vec2 |
Returns
void
Defined in
src/physics/constraints/constraint.ts:113
biasCoef
โธ Protected
biasCoef(dt
): number
Calculates the velocity bias coefficient.
Parameters
Name | Type | Description |
---|---|---|
dt | number | The 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
Name | Type | Description |
---|---|---|
pointA | vec2 | The anchor point on body a |
pointB | vec2 | The 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
Name | Type | Description |
---|---|---|
n | vec2 | The 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
Name | Type | Description |
---|---|---|
body | CollisionObject | The body to calculate for |
r | vec2 | The anchor point on the body |
n | vec2 | The 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.
Returns
mat2
k tensor matrix
Defined in
src/physics/constraints/constraint.ts:220
postSolve
โธ Abstract
postSolve(dt
): void
Performs post solve operations.
Parameters
Name | Type | Description |
---|---|---|
dt | number | The 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
Name | Type | Description |
---|---|---|
dt | number | The time since the last update |
Returns
void
Defined in
src/physics/constraints/constraint.ts:86
solve
โธ Abstract
solve(dt
): void
Solves the constraint.
Parameters
Name | Type | Description |
---|---|---|
dt | number | The 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