Skip to main content

Class: MouseConstraint

physics/constraints/mouse.MouseConstraint

Constrains an CollisionObject's position to the mouse's world position in the current Camera's view.

Hierarchy

Constructors

constructor

โ€ข new MouseConstraint(obj)

Creates an MouseConstraint.

Parameters

NameTypeDescription
objCollisionObjectThe object to constrain

Overrides

PivotConstraint.constructor

Defined in

src/physics/constraints/mouse.ts:16

Properties

a

โ€ข a: CollisionObject

Inherited from

PivotConstraint.a

Defined in

src/physics/constraints/constraint.ts:22


anchorA

โ€ข anchorA: vec2

Inherited from

PivotConstraint.anchorA

Defined in

src/physics/constraints/constraint.ts:23


anchorB

โ€ข anchorB: vec2

Inherited from

PivotConstraint.anchorB

Defined in

src/physics/constraints/constraint.ts:27


b

โ€ข b: CollisionObject

Inherited from

PivotConstraint.b

Defined in

src/physics/constraints/constraint.ts:26


bias

โ€ข bias: vec2

Inherited from

PivotConstraint.bias

Defined in

src/physics/constraints/pivot.ts:18


errorBias

โ€ข errorBias: number

Inherited from

PivotConstraint.errorBias

Defined in

src/physics/constraints/constraint.ts:32


jAcc

โ€ข jAcc: vec2

Inherited from

PivotConstraint.jAcc

Defined in

src/physics/constraints/pivot.ts:19


k

โ€ข k: mat2

Inherited from

PivotConstraint.k

Defined in

src/physics/constraints/pivot.ts:20


maxBias

โ€ข maxBias: number = Infinity

Inherited from

PivotConstraint.maxBias

Defined in

src/physics/constraints/constraint.ts:33


maxForce

โ€ข maxForce: number = Infinity

Inherited from

PivotConstraint.maxForce

Defined in

src/physics/constraints/constraint.ts:35


point

โ€ข point: vec2

Inherited from

PivotConstraint.point

Defined in

src/physics/constraints/constraint.ts:30


rotA

โ€ข rotA: number = 0

Inherited from

PivotConstraint.rotA

Defined in

src/physics/constraints/constraint.ts:24


rotB

โ€ข rotB: number = 0

Inherited from

PivotConstraint.rotB

Defined in

src/physics/constraints/constraint.ts:28

Methods

applyImpulses

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

Parameters

NameType
impulsenumber
directionvec2

Returns

void

Inherited from

PivotConstraint.applyImpulses

Defined in

src/physics/constraints/constraint.ts:111

โ–ธ Protected applyImpulses(impulse): void

Parameters

NameType
impulsevec2

Returns

void

Inherited from

PivotConstraint.applyImpulses

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

Inherited from

PivotConstraint.biasCoef

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

Inherited from

PivotConstraint.calculateRelativeVelocity

Defined in

src/physics/constraints/constraint.ts:164


getMousePosition

โ–ธ Private getMousePosition(): vec2

Gets the mouse's world position in the current camera's view.

Returns

vec2

Defined in

src/physics/constraints/mouse.ts:44


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

PivotConstraint.isBodyToPoint

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

Inherited from

PivotConstraint.kScalar

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

Inherited from

PivotConstraint.kScalarBody

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

Inherited from

PivotConstraint.kTensor

Defined in

src/physics/constraints/constraint.ts:220


mouseListener

โ–ธ Private mouseListener(): void

Returns

void

Defined in

src/physics/constraints/mouse.ts:36


postSolve

โ–ธ postSolve(): void

Applies the cached impulse.

Returns

void

Inherited from

PivotConstraint.postSolve

Defined in

src/physics/constraints/pivot.ts:119


preSolve

โ–ธ preSolve(dt): void

Prepares for constraint solving.

Parameters

NameType
dtnumber

Returns

void

Inherited from

PivotConstraint.preSolve

Defined in

src/physics/constraints/pivot.ts:65


remove

โ–ธ remove(): void

Removes the mouse constraint's listeners from the canvas.

Returns

void

Defined in

src/physics/constraints/mouse.ts:32


solve

โ–ธ solve(dt): void

Computes and applies the impulse to keep the bodies at the joint's length.

see Chipmunk2D Pin Joint

see MatterJS Constraint

see Dyn4j Distance Constraint

see Constraints and Solvers

Parameters

NameTypeDescription
dtnumberThe time since the last update

Returns

void

Inherited from

PivotConstraint.solve

Defined in

src/physics/constraints/pivot.ts:95


updateAnchors

โ–ธ Protected updateAnchors(): void

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

Returns

void

Inherited from

PivotConstraint.updateAnchors

Defined in

src/physics/constraints/constraint.ts:141