The world class manages all physics entities, dynamic simulation, and asynchronous queries.

Constructors

Properties

e_locked: number

Locked

e_newFixture: number

New Fixture

Methods

  • Call this after you are done with time steps to clear the forces. You normally call this after each call to Step, unless you are performing sub-steps.

    Returns void

  • Create a joint to constrain bodies together. No reference to the definition is retained. This may cause the connected bodies to cease colliding.

    Parameters

    Returns b2Joint

    New created joint.

    This function is locked during callbacks.

  • Destroy a rigid body given a definition. No reference to the definition is retained. This function is locked during callbacks.

    Parameters

    Returns void

    This function is locked during callbacks.

  • Destroy a controller given the controller instance.

    Parameters

    Returns void

    This function is locked during callbacks.

  • Get the number of bodies.

    Returns number

    Number of bodies in this world.

  • Get the world body list. With the returned body, use b2Body::GetNext to get the next body in the world list. A NULL body indicates the end of the list.

    Returns b2Body

    The head of the world body list.

  • Get the number of contacts (each may have 0 or more contact points).

    Returns number

    Number of contacts.

  • Get the world contact list. With the returned contact, use b2Contact::GetNext to get the next contact in the world list. A NULL contact indicates the end of the list.

    Returns b2Contact

    The head of the world contact list.

  • The world provides a single static ground body with no collision shapes. You can use this to simplify the creation of joints and static shapes.

    Returns b2Body

    The ground body.

  • Get the number of joints.

    Returns number

    The number of joints in the world.

  • Get the world joint list. With the returned joint, use b2Joint::GetNext to get the next joint in the world list. A NULL joint indicates the end of the list.

    Returns b2Joint

    The head of the world joint list.

  • Get the number of broad-phase proxies.

    Returns number

    Number of borad-phase proxies.

  • Is the world locked (in the middle of a time step).

    Returns boolean

    True if the world is locked and in the middle of a time step, otherwise false.

  • Query the world for all fixtures that potentially overlap the provided AABB.

    Parameters

    • callback: (fixutre: b2Fixture) => boolean

      A user implemented callback class. It should match signature function Callback(fixture:b2Fixture):Boolean. Return true to continue to the next fixture.

    • aabb: b2AABB

      The query bounding box.

    Returns void

  • Query the world for all fixtures that contain a point.

    Parameters

    • callback: (fixture: b2Fixture) => boolean

      A user implemented callback class. It should match signature function Callback(fixture:b2Fixture):Boolean. Return true to continue to the next fixture.

    • p: b2Vec2

      The query point.

    Returns void

    This provides a feature specific to this port.

  • Query the world for all fixtures that precisely overlap the provided transformed shape.

    Parameters

    • callback: (fixture: b2Fixture) => boolean

      A user implemented callback class. It should match signature function Callback(fixture:b2Fixture):Boolean. Return true to continue to the next fixture.

    • shape: b2Shape

      The query shape.

    • Optionaltransform: b2Transform

      Optional transform, default = null.

    Returns void

    This provides a feature specific to this port.

  • Ray-cast the world for all fixtures in the path of the ray. Your callback Controls whether you get the closest point, any point, or n-points The ray-cast ignores shapes that contain the starting point.

    Parameters

    • callback: (fixture: b2Fixture, point: b2Vec2, normal: b2Vec2, fraction: number) => number

      A callback function which must be of signature: function Callback( fixture:b2Fixture, // The fixture hit by the ray point:b2Vec2, // The point of initial intersection normal:b2Vec2, // The normal vector at the point of intersection fraction:Number // The fractional length along the ray of the intersection ):Number Callback should return the new length of the ray as a fraction of the original length. By returning 0, you immediately terminate. By returning 1, you continue wiht the original ray. By returning the current fraction, you proceed to find the closest point.

    • point1: b2Vec2

      The ray starting point.

    • point2: b2Vec2

      The ray ending point.

    Returns void

  • Use the given object as a broadphase. The old broadphase will not be cleanly emptied.

    Parameters

    Returns void

    This function is locked during callbacks.

  • Enable/disable continuous physics. For testing.

    Parameters

    • flag: boolean

      True for continuous physics, otherwise false.

    Returns void

  • Register a routine for debug drawing. The debug draw functions are called inside the b2World::Step method, so make sure your renderer is ready to consume draw commands when you call Step().

    Parameters

    Returns void

  • Enable/disable warm starting. For testing.

    Parameters

    • flag: boolean

      True for warm starting, otherwise false.

    Returns void

  • Take a time step. This performs collision detection, integration, and constraint solution.

    Parameters

    • dt: number

      The amout of time to simulate, this should not vary.

    • velocityIterations: number

      For the velocity constraint solver.

    • positionIterations: number

      For the position constraint solver.

    Returns void