Class Narrowphase

Narrowphase. Creates contacts and friction given shapes and transforms.

Hierarchy

  • Narrowphase

Constructors

Properties

collidingBodiesLastStep: TupleDictionary<boolean>

Keeps track of the colliding bodies last step.

contactEquationPool: ContactEquationPool

Keeps track of the allocated ContactEquations.

Example

// Allocate a few equations before starting the simulation.
// This way, no contact objects need to be created on the fly in the game loop.
world.narrowphase.contactEquationPool.resize(1024);
world.narrowphase.frictionEquationPool.resize(1024);
contactEquations: ContactEquation[]

Contact equations

currentContactMaterial: null | ContactMaterial

The current contact material

enableFriction: boolean

Whether to make friction equations in the upcoming contacts.

enableFrictionReduction: boolean

Enable reduction of friction equations. If disabled, a box on a plane will generate 2 contact equations and 2 friction equations. If enabled, there will be only one friction equation. Same kind of simplifications are made for all collision types.

Deprecated

This flag will be removed when the feature is stable enough.

Default

true
enabledEquations: boolean

Whether to make equations enabled in upcoming contacts.

frictionEquationPool: FrictionEquationPool

Keeps track of the allocated ContactEquations.

frictionEquations: FrictionEquation[]

Friction equations

narrowphases: {
    1: ((bodyA, shapeA, offsetA, _angleA, bodyB, shapeB, offsetB, _angleB, justTest?, radiusA?, radiusB?) => number);
    16: ((_bodyA, _shapeA, _positionA, _angleA, _bodyB, _shapeB, _positionB, _angleB, _justTest?) => number);
    32: ((bodyA, polyA, positionA, angleA, bodyB, polyB, positionB, angleB, justTest?) => number);
    64: ((bi, si, xi, ai, bj, sj, xj, aj, justTest?) => number);
    8: ((bodyA, polyA, positionA, angleA, bodyB, polyB, positionB, angleB, justTest?) => number);
} = ...

Type declaration

  • 1: ((bodyA, shapeA, offsetA, _angleA, bodyB, shapeB, offsetB, _angleB, justTest?, radiusA?, radiusB?) => number)
      • (bodyA, shapeA, offsetA, _angleA, bodyB, shapeB, offsetB, _angleB, justTest?, radiusA?, radiusB?): number
      • Circle/Circle Narrowphase.

        Parameters

        • bodyA: Body
        • shapeA: Circle | Capsule
        • offsetA: Vec2
        • _angleA: number
        • bodyB: Body
        • shapeB: Circle | Capsule
        • offsetB: Vec2
        • _angleB: number
        • justTest: boolean = false
        • radiusA: number = shapeA.radius
        • radiusB: number = shapeB.radius

        Returns number

  • 16: ((_bodyA, _shapeA, _positionA, _angleA, _bodyB, _shapeB, _positionB, _angleB, _justTest?) => number)
      • (_bodyA, _shapeA, _positionA, _angleA, _bodyB, _shapeB, _positionB, _angleB, _justTest?): number
      • Line/Line Narrowphase.

        Parameters

        • _bodyA: Body
        • _shapeA: Line
        • _positionA: Vec2
        • _angleA: number
        • _bodyB: Body
        • _shapeB: Line
        • _positionB: Vec2
        • _angleB: number
        • _justTest: boolean = false

        Returns number

        Todo

  • 32: ((bodyA, polyA, positionA, angleA, bodyB, polyB, positionB, angleB, justTest?) => number)
  • 64: ((bi, si, xi, ai, bj, sj, xj, aj, justTest?) => number)
      • (bi, si, xi, ai, bj, sj, xj, aj, justTest?): number
      • Capsule/Capsule Narrowphase.

        Parameters

        Returns number

  • 8: ((bodyA, polyA, positionA, angleA, bodyB, polyB, positionB, angleB, justTest?) => number)
slipForce: number

The friction slip force to use when creating friction equations.

Methods

  • Parameters

    • bodyA: Body
    • bodyB: Body
    • Optional checkCollisionMasks: boolean

    Returns boolean

  • Capsule/Capsule Narrowphase.

    Parameters

    Returns number

  • Circle/Capsule Narrowphase.

    Parameters

    Returns number

  • Circle/Circle Narrowphase.

    Parameters

    • bodyA: Body
    • shapeA: Circle | Capsule
    • offsetA: Vec2
    • _angleA: number
    • bodyB: Body
    • shapeB: Circle | Capsule
    • offsetB: Vec2
    • _angleB: number
    • justTest: boolean = false
    • radiusA: number = shapeA.radius
    • radiusB: number = shapeB.radius

    Returns number

  • Circle/Convex Narrowphase.

    Parameters

    • circleBody: Body
    • circleShape: Circle | Capsule
    • circleOffset: Vec2
    • _circleAngle: number
    • convexBody: Body
    • convexShape: Convex
    • convexOffset: Vec2
    • convexAngle: number
    • justTest: boolean = false
    • circleRadius: number = circleShape.radius

    Returns number

  • Circle/Heightfield Narrowphase.

    Parameters

    • circleBody: Body
    • circleShape: Circle
    • circlePos: Vec2
    • _circleAngle: number
    • hfBody: Body
    • hfShape: Heightfield
    • hfPos: Vec2
    • _fAngle: number
    • justTest: boolean = false
    • radius: number = circleShape.radius

    Returns number

  • Circle/Line Narrowphase.

    Parameters

    • circleBody: Body
    • circleShape: Circle
    • circleOffset: Vec2
    • _circleAngle: number
    • lineBody: Body
    • lineShape: Line
    • lineOffset: Vec2
    • lineAngle: number
    • justTest: boolean = false

      If set to true, this function will return the result (intersection or not) without adding equations.

    • lineRadius: number = 0

      Radius to add to the line. Can be used to test Capsules.

    • circleRadius: number = circleShape.radius

      If set, this value overrides the circle shape radius.

    Returns number

  • Parameters

    • circleBody: Body
    • circleShape: Circle
    • circleOffset: Vec2
    • _circleAngle: number
    • particleBody: Body
    • particleShape: Particle
    • particleOffset: Vec2
    • _particleAngle: number
    • justTest: boolean = false

    Returns number

  • Circle/Plane Narrowphase

    Parameters

    • circleBody: Body
    • circleShape: Circle
    • circleOffset: Vec2
    • _circleAngle: number
    • planeBody: Body
    • planeShape: Plane
    • planeOffset: Vec2
    • planeAngle: number
    • justTest: boolean = false

    Returns number

  • Check if the bodies were in contact since the last reset().

    Parameters

    Returns boolean

  • Convex/Capsule Narrowphase.

    Parameters

    • convexBody: Body
    • convexShape: Convex
    • convexPosition: Vec2
    • convexAngle: number
    • capsuleBody: Body
    • capsuleShape: Capsule
    • capsulePosition: Vec2
    • capsuleAngle: number
    • justTest: boolean = false

    Returns number

  • Convex/Heightfield Narrowphase.

    Parameters

    Returns number

  • Convex/Line Narrowphase.

    Parameters

    • _convexBody: Body
    • _convexShape: Convex
    • _convexOffset: Vec2
    • _convexAngle: number
    • _lineBody: Body
    • _lineShape: Line
    • _lineOffset: Vec2
    • _lineAngle: number
    • _justTest: boolean = false

    Returns number

    Todo

  • Creates a ContactEquation, either by reusing an existing object or creating a new one.

    Parameters

    Returns ContactEquation

  • Creates a FrictionEquation, either by reusing an existing object or creating a new one.

    Parameters

    Returns FrictionEquation

  • Creates a FrictionEquation given the data in the ContactEquation. Uses same offset vectors ri and rj, but the tangent vector will be constructed from the collision normal.

    Parameters

    Returns FrictionEquation

  • Line/Box Narrowphase.

    Parameters

    • _lineBody: Body
    • _lineShape: Line
    • _lineOffset: Vec2
    • _lineAngle: number
    • _boxBody: Body
    • _boxShape: Box
    • _boxOffset: Vec2
    • _boxAngle: number
    • _justTest: boolean = false

    Returns number

    Todo

  • Line/Capsule Narrowphase.

    Parameters

    • _lineBody: Body
    • _lineShape: Line
    • _linePosition: Vec2
    • _lineAngle: number
    • _capsuleBody: Body
    • _capsuleShape: Capsule
    • _capsulePosition: Vec2
    • _capsuleAngle: number
    • _justTest: boolean = false

    Returns number

    Todo

  • Line/Line Narrowphase.

    Parameters

    • _bodyA: Body
    • _shapeA: Line
    • _positionA: Vec2
    • _angleA: number
    • _bodyB: Body
    • _shapeB: Line
    • _positionB: Vec2
    • _angleB: number
    • _justTest: boolean = false

    Returns number

    Todo

  • Particle/Capsule Narrowphase.

    Parameters

    • particleBody: Body
    • particleShape: Particle
    • particlePosition: Vec2
    • particleAngle: number
    • capsuleBody: Body
    • capsuleShape: Capsule
    • capsulePosition: Vec2
    • capsuleAngle: number
    • justTest: boolean = false

    Returns number

  • Particle/Convex Narrowphase.

    Parameters

    • particleBody: Body
    • particleShape: Particle
    • particleOffset: Vec2
    • _particleAngle: number
    • convexBody: Body
    • convexShape: Convex
    • convexOffset: Vec2
    • convexAngle: number
    • justTest: boolean = false

    Returns number

  • Particle/Plane Narrowphase.

    Parameters

    • particleBody: Body
    • particleShape: Particle
    • particleOffset: Vec2
    • _particleAngle: number
    • planeBody: Body
    • planeShape: Plane
    • planeOffset: Vec2
    • planeAngle: number
    • justTest: boolean = false

    Returns number

  • Plane/Capsule Narrowphase.

    Parameters

    • planeBody: Body
    • planeShape: Plane
    • planeOffset: Vec2
    • planeAngle: number
    • capsuleBody: Body
    • capsuleShape: Capsule
    • capsuleOffset: Vec2
    • capsuleAngle: number
    • justTest: boolean = false

    Returns number

  • Plane/Convex Narrowphase.

    Parameters

    • planeBody: Body
    • planeShape: Plane
    • planeOffset: Vec2
    • planeAngle: number
    • convexBody: Body
    • convexShape: Convex
    • convexOffset: Vec2
    • convexAngle: number
    • justTest: boolean = false

    Returns number

    Todo

    only use the deepest contact point + the contact point furthest away from it

  • Plane/line Narrowphase

    Parameters

    • planeBody: Body
    • planeShape: Plane
    • planeOffset: Vec2
    • planeAngle: number
    • lineBody: Body
    • lineShape: Line
    • lineOffset: Vec2
    • lineAngle: number
    • justTest: boolean = false

    Returns number

  • Throws away the old equations and gets ready to create new

    Returns void