Class: SpringConstraint
physics/constraints/spring.SpringConstraint
Represents a damped spring joint between two CollisionObjects or a CollisionObject and a point.
Hierarchy
โณ
SpringConstraint
Constructors
constructor
โข new SpringConstraint(a, b, length, stiffness, damping?)
Creates a new SpringConstraint between two bodies.
Parameters
| Name | Type | Description |
|---|---|---|
a | CollisionObject | The first body |
b | CollisionObject | The second body |
length | number | The resting length of the spring |
stiffness | number | The stiffness of the spring |
damping? | number | The damping of the spring |
Overrides
Defined in
src/physics/constraints/spring.ts:36
โข new SpringConstraint(opts)
Creates a new SpringConstraint with the given options.
Parameters
| Name | Type | Description |
|---|---|---|
opts | SpringConstraintOptions | The constraint options |
Overrides
Defined in
src/physics/constraints/spring.ts:43
โข new SpringConstraint(a, point, length, stiffness, damping?)
Creates a new SpringConstraint 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 resting length of the spring. |
stiffness | number | The stiffness of the spring |
damping? | number | The damping of the spring |
Overrides
Defined in
src/physics/constraints/spring.ts:54
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
angularStiffness
โข angularStiffness: number
Defined in
src/physics/constraints/spring.ts:18
b
โข b: CollisionObject
Inherited from
Defined in
src/physics/constraints/constraint.ts:26
damping
โข damping: number
Defined in
src/physics/constraints/spring.ts:19
errorBias
โข errorBias: number
Inherited from
Defined in
src/physics/constraints/constraint.ts:32
jAcc
โข jAcc: number
Defined in
src/physics/constraints/spring.ts:25
length
โข length: number
Defined in
src/physics/constraints/spring.ts:16
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/spring.ts:21
nMass
โข nMass: number
Defined in
src/physics/constraints/spring.ts:22
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
stiffness
โข stiffness: number
Defined in
src/physics/constraints/spring.ts:17
targetVrn
โข targetVrn: number
Defined in
src/physics/constraints/spring.ts:23
vCoef
โข vCoef: number
Defined in
src/physics/constraints/spring.ts:24
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
calcForce
โธ Private calcForce(length): number
Parameters
| Name | Type |
|---|---|
length | number |
Returns
number
Defined in
src/physics/constraints/spring.ts:146
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
Performs post solve operations.
Returns
void
Overrides
Defined in
src/physics/constraints/spring.ts:144
preSolve
โธ preSolve(dt): void
Updates the constraints anchors and prepares for solving.
Parameters
| Name | Type | Description |
|---|---|---|
dt | number | The time since the last update |
Returns
void
Overrides
Defined in
src/physics/constraints/spring.ts:92
solve
โธ solve(dt): void
Applies the spring forces to the attached bodies.
Parameters
| Name | Type | Description |
|---|---|---|
dt | number | The time since the last update |
Returns
void
Overrides
Defined in
src/physics/constraints/spring.ts:126
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