Options
All
  • Public
  • Public/Protected
  • All
Menu

The physics world

Hierarchy

Index

Constructors

constructor

  • new World(options?: { allowSleep?: boolean; broadphase?: Broadphase; gravity?: Vec3; quatNormalizeFast?: boolean; quatNormalizeSkip?: number; solver?: Solver }): World
  • Parameters

    • options: { allowSleep?: boolean; broadphase?: Broadphase; gravity?: Vec3; quatNormalizeFast?: boolean; quatNormalizeSkip?: number; solver?: Solver } = ...
      • Optional allowSleep?: boolean

        Makes bodies go to sleep when they've been inactive.

        default

        false

      • Optional broadphase?: Broadphase

        The broadphase algorithm to use.

        default

        NaiveBroadphase

      • Optional gravity?: Vec3

        The gravity of the world.

      • Optional quatNormalizeFast?: boolean

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

        default

        false

      • Optional quatNormalizeSkip?: number

        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).

        default

        0

      • Optional solver?: Solver

        The solver algorithm to use.

        default

        GSSolver

    Returns World

Properties

accumulator

accumulator: number

Time accumulator for interpolation.

see

https://gafferongames.com/game-physics/fix-your-timestep/

addBodyEvent

addBodyEvent: {}

Dispatched after a body has been added to the world.

Type declaration

allowSleep

allowSleep: boolean

Makes bodies go to sleep when they've been inactive.

default

false

bodies

bodies: Body[]

All bodies in this world

broadphase

broadphase: Broadphase

The broadphase algorithm to use.

default

NaiveBroadphase

collisionMatrix

collisionMatrix: ArrayCollisionMatrix

collisionMatrix

collisionMatrixPrevious

collisionMatrixPrevious: ArrayCollisionMatrix

CollisionMatrix from the previous step.

contactMaterialTable

contactMaterialTable: TupleDictionary

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

contactmaterials

contactmaterials: ContactMaterial[]

All added contactmaterials.

contacts

contacts: ContactEquation[]

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

defaultContactMaterial

defaultContactMaterial: ContactMaterial

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

defaultMaterial

defaultMaterial: Material

The default material of the bodies.

default_dt

default_dt: number

Default and last timestep sizes.

dt

dt: number

Currently / last used timestep. Is set to -1 if not available. This value is updated before each internal step, which means that it is "fresh" inside event callbacks.

gravity

gravity: Vec3

The gravity of the world.

hasActiveBodies

hasActiveBodies: boolean

True if any bodies are not sleeping, false if every body is sleeping.

materials

materials: Material[]

All added materials.

deprecated
todo

Remove

quatNormalizeFast

quatNormalizeFast: boolean

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

default

false

quatNormalizeSkip

quatNormalizeSkip: number

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).

default

0

removeBodyEvent

removeBodyEvent: {}

Dispatched after a body has been removed from the world.

Type declaration

solver

solver: Solver

The solver algorithm to use.

default

GSSolver

stepnumber

stepnumber: number

Number of timesteps taken since start.

time

time: number

The wall-clock time since simulation start.

Methods

addBody

  • addBody(body: Body): void
  • Add a rigid body to the simulation.

    todo

    If the simulation has not yet started, why recrete and copy arrays for each body? Accumulate in dynamic arrays in this case.

    todo

    Adding an array of bodies should be possible. This would save some loops too

    Parameters

    Returns void

addConstraint

addContactMaterial

addEventListener

  • addEventListener(type: string, listener: Function): EventTarget

addMaterial

clearForces

  • clearForces(): void

collisionMatrixTick

  • collisionMatrixTick(): void

dispatchEvent

getContactMaterial

hasAnyEventListener

  • hasAnyEventListener(type: string): boolean

hasEventListener

  • hasEventListener(type: string, listener: Function): boolean

numObjects

  • numObjects(): number
  • Get number of objects in the world.

    deprecated

    Returns number

rayTest

  • Raycast test

    deprecated

    Use .raycastAll, .raycastClosest or .raycastAny instead.

    Parameters

    Returns void

raycastAll

  • raycastAll(from?: Vec3, to?: Vec3, options?: RayOptions, callback?: RaycastCallback): boolean
  • Ray cast against all bodies. The provided callback will be executed for each hit with a RaycastResult as single argument.

    Parameters

    • Optional from: Vec3
    • Optional to: Vec3
    • options: RayOptions = ...
    • Optional callback: RaycastCallback

    Returns boolean

    True if any body was hit.

raycastAny

  • Ray cast, and stop at the first result. Note that the order is random - but the method is fast.

    Parameters

    Returns boolean

    True if any body was hit.

raycastClosest

removeBody

  • removeBody(body: Body): void

removeConstraint

removeEventListener

  • removeEventListener(type: string, listener: Function): EventTarget

step

  • step(dt: number, timeSinceLastCalled?: number, maxSubSteps?: number): void