API Docs for: 0.7.1
Show:

Narrowphase Class

Narrowphase. Creates contacts and friction given shapes and transforms.

Constructor

Narrowphase

()

Methods

bodiesOverlap

(
  • bodyA
  • bodyB
)
Boolean

Parameters:

Returns:

Boolean:

capsuleCapsule

(
  • bi
  • si
  • xi
  • ai
  • bj
  • sj
  • xj
  • aj
)

Capsule/capsule narrowphase

Parameters:

circleCapsule

(
  • bi
  • si
  • xi
  • ai
  • bj
  • sj
  • xj
  • aj
)

Circle/capsule Narrowphase

Parameters:

circleCircle

(
  • bodyA
  • shapeA
  • offsetA
  • angleA
  • bodyB
  • shapeB
  • offsetB
  • angleB
  • justTest
  • [radiusA]
  • [radiusB]
)

Circle/circle Narrowphase

Parameters:

  • bodyA Body
  • shapeA Circle
  • offsetA Array
  • angleA Number
  • bodyB Body
  • shapeB Circle
  • offsetB Array
  • angleB Number
  • justTest Boolean
  • [radiusA] Number optional

    Optional radius to use for shapeA

  • [radiusB] Number optional

    Optional radius to use for shapeB

circleConvex

(
  • circleBody
  • circleShape
  • circleOffset
  • circleAngle
  • convexBody
  • convexShape
  • convexOffset
  • convexAngle
  • justTest
  • circleRadius
)

Circle/convex Narrowphase.

Parameters:

  • circleBody Body
  • circleShape Circle
  • circleOffset Array
  • circleAngle Number
  • convexBody Body
  • convexShape Convex
  • convexOffset Array
  • convexAngle Number
  • justTest Boolean
  • circleRadius Number

circleHeightfield

(
  • bi
  • si
  • xi
  • bj
  • sj
  • xj
  • aj
)

Parameters:

circleHeightfield

(
  • bi
  • si
  • xi
  • bj
  • sj
  • xj
  • aj
)

Parameters:

circleLine

(
  • circleBody
  • circleShape
  • circleOffset
  • circleAngle
  • lineBody
  • lineShape
  • lineOffset
  • lineAngle
  • justTest
  • lineRadius
  • circleRadius
)

Circle/line Narrowphase

Parameters:

  • circleBody Body
  • circleShape Circle
  • circleOffset Array
  • circleAngle Number
  • lineBody Body
  • lineShape Line
  • lineOffset Array
  • lineAngle Number
  • justTest Boolean

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

  • lineRadius Number

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

  • circleRadius Number

    If set, this value overrides the circle shape radius.

circleParticle

(
  • circleBody
  • circleShape
  • circleOffset
  • circleAngle
  • particleBody
  • particleShape
  • particleOffset
  • particleAngle
  • justTest
)

Circle/Particle Narrowphase

Parameters:

  • circleBody Body
  • circleShape Circle
  • circleOffset Array
  • circleAngle Number
  • particleBody Body
  • particleShape Particle
  • particleOffset Array
  • particleAngle Number
  • justTest Boolean

circlePlane

(
  • bi
  • si
  • xi
  • bj
  • sj
  • xj
  • aj
)

Creates ContactEquations and FrictionEquations for a collision.

Parameters:

  • bi Body

    The first body that should be connected to the equations.

  • si Circle

    The circle shape participating in the collision.

  • xi Array

    Extra offset to take into account for the Shape, in addition to the one in circleBody.position. Will not be rotated by circleBody.angle (maybe it should, for sake of homogenity?). Set to null if none.

  • bj Body

    The second body that should be connected to the equations.

  • sj Plane

    The Plane shape that is participating

  • xj Array

    Extra offset for the plane shape.

  • aj Number

    Extra angle to apply to the plane

collidedLastStep

(
  • bodyA
  • bodyB
)
Boolean

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

Parameters:

Returns:

Boolean:

convexCapsule

(
  • convexBody
  • convexShape
  • convexPosition
  • convexAngle
  • capsuleBody
  • capsuleShape
  • capsulePosition
  • capsuleAngle
)

Convex/capsule narrowphase

Parameters:

  • convexBody Body
  • convexShape Convex
  • convexPosition Array
  • convexAngle Number
  • capsuleBody Body
  • capsuleShape Capsule
  • capsulePosition Array
  • capsuleAngle Number

convexConvex

(
  • bi
  • si
  • xi
  • ai
  • bj
  • sj
  • xj
  • aj
)

Convex/convex Narrowphase.See this article for more info.

Parameters:

convexLine

(
  • convexBody
  • convexShape
  • convexOffset
  • convexAngle
  • lineBody
  • lineShape
  • lineOffset
  • lineAngle
  • justTest
)

Convex/line narrowphase

Parameters:

  • convexBody Body
  • convexShape Convex
  • convexOffset Array
  • convexAngle Number
  • lineBody Body
  • lineShape Line
  • lineOffset Array
  • lineAngle Number
  • justTest Boolean

createContactEquation

(
  • bodyA
  • bodyB
)
ContactEquation

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

Parameters:

Returns:

createFrictionEquation

(
  • bodyA
  • bodyB
)
FrictionEquation

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

Parameters:

Returns:

createFrictionFromContact

(
  • contactEquation
)
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:

findSeparatingAxis

(
  • c1
  • offset1
  • angle1
  • c2
  • offset2
  • angle2
  • sepAxis
)
Boolean static

Find a separating axis between the shapes, that maximizes the separating distance between them.

Parameters:

  • c1 Convex
  • offset1 Array
  • angle1 Number
  • c2 Convex
  • offset2 Array
  • angle2 Number
  • sepAxis Array

    The resulting axis

Returns:

Boolean:

Whether the axis could be found.

getClosestEdge

(
  • c
  • angle
  • axis
  • flip
)
Number static

Get the edge that has a normal closest to an axis.

Parameters:

  • c Convex
  • angle Number
  • axis Array
  • flip Boolean

Returns:

Number:

Index of the edge that is closest. This index and the next spans the resulting edge. Returns -1 if failed.

lineBox

(
  • lineBody
  • lineShape
  • lineOffset
  • lineAngle
  • boxBody
  • boxShape
  • boxOffset
  • boxAngle
  • justTest
)

Line/box narrowphase

Parameters:

  • lineBody Body
  • lineShape Line
  • lineOffset Array
  • lineAngle Number
  • boxBody Body
  • boxShape Box
  • boxOffset Array
  • boxAngle Number
  • justTest Boolean

lineCapsule

(
  • lineBody
  • lineShape
  • linePosition
  • lineAngle
  • capsuleBody
  • capsuleShape
  • capsulePosition
  • capsuleAngle
)

Capsule/line narrowphase

Parameters:

  • lineBody Body
  • lineShape Line
  • linePosition Array
  • lineAngle Number
  • capsuleBody Body
  • capsuleShape Capsule
  • capsulePosition Array
  • capsuleAngle Number

lineLine

(
  • bodyA
  • shapeA
  • positionA
  • angleA
  • bodyB
  • shapeB
  • positionB
  • angleB
)

Line/line narrowphase

Parameters:

  • bodyA Body
  • shapeA Line
  • positionA Array
  • angleA Number
  • bodyB Body
  • shapeB Line
  • positionB Array
  • angleB Number

particleConvex

(
  • particleBody
  • particleShape
  • particleOffset
  • particleAngle
  • convexBody
  • convexShape
  • convexOffset
  • convexAngle
  • justTest
)

Particle/convex Narrowphase

Parameters:

  • particleBody Body
  • particleShape Particle
  • particleOffset Array
  • particleAngle Number
  • convexBody Body
  • convexShape Convex
  • convexOffset Array
  • convexAngle Number
  • justTest Boolean

particlePlane

(
  • particleBody
  • particleShape
  • particleOffset
  • particleAngle
  • planeBody
  • planeShape
  • planeOffset
  • planeAngle
  • justTest
)

Narrowphase for particle vs plane

Parameters:

  • particleBody Body
  • particleShape Particle
  • particleOffset Array
  • particleAngle Number
  • planeBody Body
  • planeShape Plane
  • planeOffset Array
  • planeAngle Number
  • justTest Boolean

planeCapsule

(
  • planeBody
  • planeShape
  • planeOffset
  • planeAngle
  • capsuleBody
  • capsuleShape
  • capsuleOffset
  • capsuleAngle
  • justTest
)

Parameters:

  • planeBody Body
  • planeShape Circle
  • planeOffset Array
  • planeAngle Number
  • capsuleBody Body
  • capsuleShape Particle
  • capsuleOffset Array
  • capsuleAngle Number
  • justTest Boolean

planeConvex

(
  • planeBody
  • planeShape
  • planeOffset
  • planeAngle
  • convexBody
  • convexShape
  • convexOffset
  • convexAngle
  • justTest
)

Plane/Convex Narrowphase

Parameters:

  • planeBody Body
  • planeShape Plane
  • planeOffset Array
  • planeAngle Number
  • convexBody Body
  • convexShape Convex
  • convexOffset Array
  • convexAngle Number
  • justTest Boolean

planeLine

(
  • planeBody
  • planeShape
  • planeOffset
  • planeAngle
  • lineBody
  • lineShape
  • lineOffset
  • lineAngle
)

Plane/line Narrowphase

Parameters:

  • planeBody Body
  • planeShape Plane
  • planeOffset Array
  • planeAngle Number
  • lineBody Body
  • lineShape Line
  • lineOffset Array
  • lineAngle Number

projectConvexOntoAxis

(
  • convexShape
  • convexOffset
  • convexAngle
  • worldAxis
  • result
)
static

Project a Convex onto a world-oriented axis

Parameters:

  • convexShape Convex
  • convexOffset Array
  • convexAngle Number
  • worldAxis Array
  • result Array

reset

()

Throws away the old equations and gets ready to create new

Properties

collidingBodiesLastStep

TupleDictionary private

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

Array

contactSkinSize

Number

Contact skin size value to use in the next contact equations.

Default: 0.01

enabledEquations

Boolean

Whether to make equations enabled in upcoming contacts.

enableFriction

Boolean

Whether to make friction equations in the upcoming contacts.

enableFrictionReduction

Boolean deprecated

Defined in src/collision/Narrowphase.js:148

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

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.

Default: true

frictionCoefficient

Number

The friction value to use in the upcoming friction equations.

frictionEquationPool

FrictionEquationPool

Keeps track of the allocated ContactEquations.

frictionEquations

Array

frictionRelaxation

Number

The relaxation value to use in the next friction equations.

frictionStiffness

Number

The stiffness value to use in the next friction equations.

restitution

Number

The restitution value to use in the next contact equations.

slipForce

Number

The friction slip force to use when creating friction equations.

stiffness

Number

The stiffness value to use in the next contact equations.

stiffness

Number

The stiffness value to use in the next contact equations.

surfaceVelocity

Number

Will be the .relativeVelocity in each produced FrictionEquation.