Class: DistanceConstraint
physics/constraints/distance.DistanceConstraint
Represents a distance/pin joint between two CollisionObjects or a CollisionObject and a point.
This constraint will maintain a set distance between the two anchor points.
Hierarchy
โณ
DistanceConstraint
Constructors
constructor
โข new DistanceConstraint(a
, b
, length
)
Creates a new DistanceConstraint between two bodies.
Parameters
Name | Type | Description |
---|---|---|
a | CollisionObject | The first body |
b | CollisionObject | The second body |
length | number | The distance to maintain between the bodies |
Overrides
Defined in
src/physics/constraints/distance.ts:34
โข new DistanceConstraint(opts
)
Creates a new Constraint with the given options.
Parameters
Name | Type | Description |
---|---|---|
opts | DistanceConstraintOptions | The constraint options |
Overrides
Defined in
src/physics/constraints/distance.ts:41
โข new DistanceConstraint(a
, point
, length
)
Creates a new DistanceConstraint between a body and a point.
Parameters
Name | Type | Description |
---|---|---|
a | CollisionObject | The body to constrain |
point | vec2 | A point in world space |
length | number | The distance to maintain between the body and point. |
Overrides
Defined in
src/physics/constraints/distance.ts:50
Properties
a
โข a: CollisionObject
Inherited from
Defined in
src/physics/constraints/constraint.ts:22
anchorA
โข anchorA: vec2
Inherited from
Defined in
src/physics/constraints/constraint.ts:23
anchorB
โข anchorB: vec2
Inherited from
Defined in
src/physics/constraints/constraint.ts:27
b
โข b: CollisionObject
Inherited from
Defined in
src/physics/constraints/constraint.ts:26
bias
โข bias: number
Defined in
src/physics/constraints/distance.ts:22
errorBias
โข errorBias: number
Inherited from
Defined in
src/physics/constraints/constraint.ts:32
jnAcc
โข jnAcc: number
Defined in
src/physics/constraints/distance.ts:25
length
โข length: number
Defined in
src/physics/constraints/distance.ts:20
maxBias
โข maxBias: number
= Infinity
Inherited from
Defined in
src/physics/constraints/constraint.ts:33
maxForce
โข maxForce: number
= Infinity
Inherited from
Defined in
src/physics/constraints/constraint.ts:35
nDelta
โข nDelta: vec2
Defined in
src/physics/constraints/distance.ts:23
nMass
โข nMass: number
Defined in
src/physics/constraints/distance.ts:24
point
โข point: vec2
Inherited from
Defined in
src/physics/constraints/constraint.ts:30
rotA
โข rotA: number
= 0
Inherited from
Defined in
src/physics/constraints/constraint.ts:24
rotB
โข rotB: number
= 0
Inherited from
Defined in
src/physics/constraints/constraint.ts:28
Methods
applyImpulses
โธ Protected
applyImpulses(impulse
, direction
): void
Parameters
Name | Type |
---|---|
impulse | number |
direction | vec2 |
Returns
void
Inherited from
Defined in
src/physics/constraints/constraint.ts:111
โธ Protected
applyImpulses(impulse
): void
Parameters
Name | Type |
---|---|
impulse | vec2 |
Returns
void
Inherited from
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
Inherited from
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
Inherited from
Constraint.calculateRelativeVelocity
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.
Inherited from
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
Inherited from
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
Inherited from
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
Inherited from
Defined in
src/physics/constraints/constraint.ts:220
postSolve
โธ postSolve(): void
Applies the cached impulse.
Returns
void
Overrides
Defined in
src/physics/constraints/distance.ts:128
preSolve
โธ preSolve(dt
): void
Prepares for constraint solving.
Parameters
Name | Type |
---|---|
dt | number |
Returns
void
Overrides
Defined in
src/physics/constraints/distance.ts:73
solve
โธ solve(dt
): void
Computes and applies the impulse to keep the bodies at the joint's length.
Parameters
Name | Type | Description |
---|---|---|
dt | number | The time since the last update |
Returns
void
Overrides
Defined in
src/physics/constraints/distance.ts:105
updateAnchors
โธ Protected
updateAnchors(): void
Updates the constraint's anchor points to match the rotations of their bodies.
Returns
void
Inherited from
Defined in
src/physics/constraints/constraint.ts:141