CollisionManifold

View source

Stores the collision and solver state for one pair of 2D bodies.

Collision detection exposes the current manifolds through the Contacts resource. Each manifold combines the pair’s CollisionData with the Jacobians, material values, and accumulated impulses used by prepare and solve.

Examples

import { CollisionManifold, Contacts } from '@wimaengine/narrowphase'

const manifold = world.getResource(Contacts)[0]
if (manifold) {
  CollisionManifold.prepare(
    manifold,
    positionA,
    positionB,
    velocityA,
    velocityB,
    rotationA,
    rotationB,
    1 / deltaTime
  )
  CollisionManifold.solve(manifold)
}

Constructor


constructor(a: EntityHandle, b: EntityHandle, pA: Vector2, pB: Vector2, vA: Vector2, vB: Vector2, rA: Angle, rB: Angle)

View source

Creates a manifold for a pair of bodies.

The entity, position, velocity, and rotation arguments are stored by reference. Collision geometry and body properties remain at their field defaults until the narrowphase fills them before prepare runs.

Parameters

NameDescriptionDefault
a

Entity handle for body A.

—
b

Entity handle for body B.

—
pA

Position associated with body A.

—
pB

Position associated with body B.

—
vA

Mutable linear velocity for body A.

—
vB

Mutable linear velocity for body B.

—
rA

Mutable rotational value for body A.

—
rB

Mutable rotational value for body B.

—

Properties


velocityA: Vector2

View source

Mutable linear velocity used for body A while the solver applies impulses.

velocityB: Vector2

View source

Mutable linear velocity used for body B while the solver applies impulses.

rotationA: Angle

View source

Mutable rotational value used for body A by the solver.

rotationB: Angle

View source

Mutable rotational value used for body B by the solver.

positionA: Vector2

View source

Position associated with body A when this manifold is created.

positionB: Vector2

View source

Position associated with body B when this manifold is created.

contactData: CollisionData

View source

Geometric result supplied by the narrowphase for this pair.

prepare reads its contact axis, tangent, overlap, points, and contact count. A new manifold starts with a new CollisionData instance.

Default: ...

impulse: number[]

View source

Normal impulse accumulated or calculated for each contact point.

solve uses this as accumulated state when impulse accumulation is enabled, and as the current normal impulse otherwise.

Default: ...

tImpulse: number[]

View source

Tangential impulse accumulated or calculated for each contact point.

Default: ...

nbias: number[]

View source

Normal velocity bias for each contact point, calculated by prepare from penetration and restitution.

Default: ...

nJacobian: Jacobian[]

View source

Normal constraint Jacobian for each contact point.

Each entry is a Jacobian built from the collision axis.

Default: ...

tJacobian: Jacobian[]

View source

Tangential constraint Jacobian for each contact point.

Each entry is a Jacobian built from the collision tangent.

Default: ...

restitution: number

View source

Restitution coefficient used when prepare calculates normal velocity bias.

Default: 0

staticFriction: number

View source

Static-friction coefficient used by accumulated impulse solving.

Default: 0

kineticFriction: number

View source

Kinetic-friction coefficient used to limit tangential impulses.

Default: 0

effectiveMass: number[]

View source

Effective normal mass for each contact point, calculated by prepare.

Default: ...

nLambda: number[]

View source

Normal impulse change calculated by solve for each contact point.

Default: ...

tLambda: number[]

View source

Tangential impulse change calculated by solve for each contact point.

Default: ...

Methods


staticapplyImpulse(jacobian: Jacobian, velocityA: Vector2, velocityB: Vector2, rotationA: Angle, rotationB: Angle, invmassA: number, invmassB: number, invinertiaA: number, invinertiaB: number, lambda: number): void

View source

Applies one constraint impulse to both bodies.

The linear velocity vectors and the value of each rotation are mutated using the vector and angular components stored in Jacobian.

Parameters

NameDescriptionDefault
jacobian

Constraint coefficients to apply.

—
velocityA

Mutable linear velocity for body A.

—
velocityB

Mutable linear velocity for body B.

—
rotationA

Mutable rotational value for body A.

—
rotationB

Mutable rotational value for body B.

—
invmassA

Inverse mass of body A.

—
invmassB

Inverse mass of body B.

—
invinertiaA

Inverse moment of inertia of body A.

—
invinertiaB

Inverse moment of inertia of body B.

—
lambda

Constraint impulse magnitude.

—

staticprepare(manifold: CollisionManifold, positionA: Vector2, positionB: Vector2, velocityA: Vector2, velocityB: Vector2, rotationA: Angle, rotationB: Angle, invDt: number): void

View source

Prepares the per-contact constraints for solving.

For every contact in CollisionData#contactNo, this clears the stored impulses, builds normal and tangent Jacobian values, calculates the penetration and restitution bias, and calculates effective normal mass. It reads the supplied positions, velocities, and rotations to calculate relative velocity; it does not replace the manifold’s stored body references.

Call this after the CollisionData has been filled by collision detection and before solve.

Parameters

NameDescriptionDefault
manifold

Manifold whose contact constraints should be prepared.

—
positionA

Current position of body A.

—
positionB

Current position of body B.

—
velocityA

Current linear velocity of body A.

—
velocityB

Current linear velocity of body B.

—
rotationA

Current rotational value of body A.

—
rotationB

Current rotational value of body B.

—
invDt

Inverse simulation-step duration.

—

staticsolve(manifold: CollisionManifold): void

View source

Solves and applies the constraints for every contact in a manifold.

Normal and tangential impulse changes are calculated from the prepared Jacobians. With impulse accumulation enabled, normal impulses accumulate and static friction can be used; otherwise the normal impulse is clamped to zero or greater and tangential impulse is limited by kinetic friction. The resulting impulses mutate the manifold’s stored velocities and rotations through applyImpulse.

Call prepare first for the current contact data.

Parameters

NameDescriptionDefault
manifold

Prepared manifold to solve.

—