#

API Docs for: 0.6.0
Show: Inherited Protected Private Deprecated

# World Class

Extends EventTarget
Defined in: `src/world/World.js:24`

The physics world

## Constructor

### `World`

()

Defined in `src/world/World.js:24`

- Index
- Methods
- Properties

## Item Index

### Methods

- add deprecated
- addConstraint
- addContactMaterial
- addEventListener
- addMaterial
- collisionMatrixTick
- dispatchEvent
- getContactMaterial
- hasEventListener
- numObjects deprecated
- rayTest
- remove
- removeConstraint
- removeEventListener
- step
- step

### Properties

- allowSleep
- bodies
- broadphase
- collisionMatrix
- collisionMatrixPrevious
- constraints
- contactmaterials
- contactMaterialTable
- contacts
- defaultContactMaterial
- doProfiling
- dt
- gravity
- materials
- narrowphase
- profile
- quatNormalizeFast
- quatNormalizeSkip
- solver
- stepnumber
- subystems
- time

## Methods

### `add`

(

- `body`

)
deprecated

Defined in `src/world/World.js:238`

Deprecated: Use .addBody instead

Add a rigid body to the simulation.

#### Parameters:

- `body` Body

### `addConstraint`

(

- `c`

)

Defined in `src/world/World.js:265`

Add a constraint to the simulation.

#### Parameters:

- `c` Constraint

### `addContactMaterial`

(

- `cmat`

)

Defined in `src/world/World.js:344`

Adds a contact material to the World

#### Parameters:

- `cmat` ContactMaterial

### `addEventListener`

(

- `type`
- `listener`

)
EventTarget

Inherited from EventTarget: `src/utils/EventTarget.js:15`

Add an event listener

#### Parameters:

- `type` String
- `listener` Function

#### Returns:

EventTarget:

The self object, for chainability.

### `addMaterial`

(

- `m`

)

Defined in `src/world/World.js:334`

Adds a material to the World.

#### Parameters:

- `m` Material

### `collisionMatrixTick`

()

Defined in `src/world/World.js:227`

Store old collision state info

### `dispatchEvent`

(

- `event`

)
EventTarget

Inherited from EventTarget: `src/utils/EventTarget.js:68`

Emit an event.

#### Parameters:

- `event` Object
  - `type` String

#### Returns:

EventTarget:

The self object, for chainability.

### `getContactMaterial`

(

- `m1`
- `m2`

)
Contactmaterial

Defined in `src/world/World.js:206`

Get the contact material between materials m1 and m2

#### Parameters:

- `m1` Material
- `m2` Material

#### Returns:

Contactmaterial:

The contact material if it was found.

### `hasEventListener`

(

- `type`
- `listener`

)
Boolean

Inherited from EventTarget: `src/utils/EventTarget.js:34`

Check if an event listener is added

#### Parameters:

- `type` String
- `listener` Function

#### Returns:

Boolean:

### `numObjects`

() Number deprecated

Defined in `src/world/World.js:217`

Get number of objects in the world.

#### Returns:

Number:

### `rayTest`

(

- `from`
- `to`
- `result`

)

Defined in `src/world/World.js:286`

Raycast test

#### Parameters:

- `from` Vec3
- `to` Vec3
- `result` Function | RaycastResult

### `remove`

(

- `body`

)

Defined in `src/world/World.js:309`

Remove a rigid body from the simulation.

#### Parameters:

- `body` Body

### `removeConstraint`

(

- `c`

)

Defined in `src/world/World.js:274`

Removes a constraint

#### Parameters:

- `c` Constraint

### `removeEventListener`

(

- `type`
- `listener`

)
EventTarget

Inherited from EventTarget: `src/utils/EventTarget.js:50`

Remove an event listener

#### Parameters:

- `type` String
- `listener` Function

#### Returns:

EventTarget:

The self object, for chainability.

### `step`

(

- `dt`
- `[timeSinceLastCalled]`
- `[maxSubSteps=10]`

)

Defined in `src/world/World.js:374`

Step the physics world forward in time.

There are two modes. The simple mode is fixed timestepping without interpolation. In this case you only use the first argument. The second case uses interpolation. In that you also provide the time since the function was last used, as well as the maximum fixed timesteps to take.

#### Parameters:

- `dt` Number

  The fixed time step size to use.

- `[timeSinceLastCalled]` Number optional

  The time elapsed since the function was last called.

- `[maxSubSteps=10]` Number optional

  Maximum number of fixed steps to take per function call.

#### Example:

    // fixed timestepping without interpolation
    world.step(1/60);

### `step`

(

- `dt`

)

Defined in `src/world/World.js:448`

Step the simulation

#### Parameters:

- `dt` Number

## Properties

### `allowSleep`

Boolean

Defined in `src/world/World.js:39`

Makes bodies go to sleep when they've been inactive

### `bodies`

Array

Defined in `src/world/World.js:100`

### `broadphase`

Broadphase

Defined in `src/world/World.js:94`

### `collisionMatrix`

ArrayCollisionMatrix

Defined in `src/world/World.js:124`

### `collisionMatrixPrevious`

ArrayCollisionMatrix

Defined in `src/world/World.js:130`

CollisionMatrix from the previous step.

### `constraints`

Array

Defined in `src/world/World.js:112`

### `contactmaterials`

Array

Defined in `src/world/World.js:144`

### `contactMaterialTable`

TupleDictionary

Defined in `src/world/World.js:150`

Used to look up a ContactMaterial given two instances of Material.

### `contacts`

Array

Defined in `src/world/World.js:46`

All the current contacts (instances of ContactEquation) in the world.

### `defaultContactMaterial`

ContactMaterial

Defined in `src/world/World.js:158`

This contact material is used if no suitable contactmaterial is found for a contact.

### `doProfiling`

Boolean

Defined in `src/world/World.js:165`

### `dt`

Number

Defined in `src/world/World.js:33`

Last used timestep. Is set to -1 if not available.

### `gravity`

Vec3

Defined in `src/world/World.js:88`

### `materials`

Array

Defined in `src/world/World.js:137`

All added materials

### `narrowphase`

Narrowphase

Defined in `src/world/World.js:118`

### `profile`

Object

Defined in `src/world/World.js:171`

### `quatNormalizeFast`

Boolean

Defined in `src/world/World.js:61`

Set to true to use fast quaternion normalization. It is often enough accurate to use. If bodies tend to explode, set to false.

### `quatNormalizeSkip`

Number

Defined in `src/world/World.js:54`

How often to normalize quaternions. Set to 0 for every step, 1 for every second etc.. A larger value increases performance. If bodies tend to explode, set to a smaller value (zero to be sure nothing can go wrong).

### `solver`

Solver

Defined in `src/world/World.js:106`

### `stepnumber`

Number

Defined in `src/world/World.js:77`

Number of timesteps taken since start

### `subystems`

Array

Defined in `src/world/World.js:183`

### `time`

Number

Defined in `src/world/World.js:70`

The wall-clock time since simulation start