API Docs for: 0.3.0
Show:

World Class

Extends EventEmitter
Defined in: src/world/World.js:37

The dynamics world, where all bodies and constraints lives.

Constructor

World

(
  • [options]
)

Parameters:

  • [options] Object optional
    • solver Solver

      Defaults to GSSolver.

    • gravity Float32Array

      Defaults to [0,-9.78]

    • broadphase Broadphase

      Defaults to NaiveBroadphase

Methods

addBody

(
  • body
)

Add a body to the simulation

Parameters:

Example:

var world = new World(),
    body = new Body();
world.addBody(body);

addConstraint

(
  • c
)

Add a constraint to the simulation.

Parameters:

addContactMaterial

(
  • contactMaterial
)

Add a ContactMaterial to the simulation.

Parameters:

addSpring

(
  • s
)

Add a spring to the simulation

Parameters:

clear

()

Resets the World, removes all bodies, constraints and springs.

clone

() World

Get a copy of this World instance

Returns:

fromJSON

(
  • json
)
Boolean

Load a scene from a serialized state in JSON format.

Parameters:

  • json Object

Returns:

Boolean:

True on success, else false.

getContactMaterial

(
  • materialA
  • materialB
)
ContactMaterial

Get a contact material given two materials

Parameters:

Returns:

ContactMaterial:

The matching ContactMaterial, or false on fail.

hitTest

(
  • worldPoint
  • bodies
  • precision
)
Array

Test if a world point overlaps bodies

Parameters:

  • worldPoint Array

    Point to use for intersection tests

  • bodies Array

    A list of objects to check for intersection

  • precision Number

    Used for matching against particles and lines. Adds some margin to these infinitesimal objects.

Returns:

Array:

Array of bodies that overlap the point

integrateBody

(
  • body
  • dt
)
static

Move a body forward in time.

Parameters:

  • body Body
  • dt Number

removeBody

(
  • body
)

Remove a body from the simulation

Parameters:

removeConstraint

(
  • c
)

Removes a constraint

Parameters:

removeSpring

(
  • s
)

Remove a spring

Parameters:

runNarrowphase

(
  • np
  • bi
  • si
  • xi
  • ai
  • bj
  • sj
  • xj
  • aj
  • mu
  • glen
)
static

Runs narrowphase for the shape pair i and j.

Parameters:

step

(
  • dt
)

Step the physics world forward in time.

Parameters:

  • dt Number

    The time step size to use.

Example:

var world = new World();
world.step(0.01);

toJSON

() Object

Convert the world to a JSON-serializable Object.

Returns:

Object:

upgradeJSON

(
  • json
)
Object | Boolean

Upgrades a JSON object to current version

Parameters:

  • json Object

Returns:

Object | Boolean:

New json object, or false on failure.

Properties

applySpringForces

Boolean

Enable to automatically apply spring forces each step.

bodies

Array

All bodies in the world.

broadphase

Broadphase

The broadphase algorithm to use.

constraints

Array

User-added constraints.

Float32Array

Gravity in the world. This is applied on all bodies in the beginning of each step().

contactMaterials

Array

The ContactMaterials added to the World.

defaultFriction

Number

Friction between colliding bodies. This value is used if no matching ContactMaterial is found for the body pair.

doPofiling

Boolean

Whether to do timing measurements during the step() or not.

lastStepTime

Number

How many millisecconds the last step() took. This is updated each step if .doProfiling is set to true.

lastTimeStep

Number

For keeping track of what time step size we used last step

narrowphase

Narrowphase

The narrowphase to use to generate contacts.

solveConstraints

Boolean

Enable/disable constraint solving in each step.

solver

Solver

The solver used to satisfy constraints and contacts.

springs

Array

All springs in the world.