Options
All
  • Public
  • Public/Protected
  • All
Menu

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

Hierarchy

  • b2World

Index

Constructors

constructor

  • Creates a new world.

    Parameters

    • gravity: b2Vec2

      The world gravity vector.

    • doSleep: boolean

      Improvie performance by not simulating inactive bodies.

    Returns b2World

Properties

Static e_locked

e_locked: number

Locked

Static e_newFixture

e_newFixture: number

New Fixture

Methods

AddController

  • Add a controller to the world list.

    Parameters

    Returns b2Controller

    Controller that was added to the world.

ClearForces

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

CreateBody

  • Create a rigid body given a definition. No reference to the definition is retained.

    Parameters

    Returns b2Body

    Created rigid body.

CreateController

  • Creates a new controller.

    Parameters

    Returns b2Controller

    New controller.

CreateJoint

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

    warning

    This function is locked during callbacks.

    Parameters

    Returns b2Joint

    New created joint.

DestroyBody

  • DestroyBody(b: b2Body): void
  • Destroy a rigid body given a definition. No reference to the definition is retained. This function is locked during callbacks.

    warning

    This function is locked during callbacks.

    Parameters

    Returns void

DestroyController

  • Destroy a controller given the controller instance.

    warning

    This function is locked during callbacks.

    Parameters

    Returns void

DestroyJoint

  • Destroy a joint. This may cause the connected bodies to begin colliding.

    Parameters

    Returns void

DrawDebugData

  • DrawDebugData(): void
  • Call this to draw shapes and other debug draw data.

    Returns void

GetBodyCount

  • GetBodyCount(): number
  • Get the number of bodies.

    Returns number

    Number of bodies in this world.

GetBodyList

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

GetContactCount

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

    Returns number

    Number of contacts.

GetContactList

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

GetGravity

  • Get the global gravity vector.

    Returns b2Vec2

    Global gravity vector.

GetGroundBody

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

GetJointCount

  • GetJointCount(): number
  • Get the number of joints.

    Returns number

    The number of joints in the world.

GetJointList

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

GetProxyCount

  • GetProxyCount(): number
  • Get the number of broad-phase proxies.

    Returns number

    Number of borad-phase proxies.

IsLocked

  • IsLocked(): boolean
  • 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.

QueryAABB

  • 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

QueryPoint

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

    note

    This provides a feature specific to this port.

    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

QueryShape

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

    note

    This provides a feature specific to this port.

    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.

    • Optional transform: b2Transform

      Optional transform, default = null.

    Returns void

RayCast

  • 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

RayCastAll

  • Ray-cast the world for all fixture in the path of the ray.

    Parameters

    • point1: b2Vec2

      The ray starting point.

    • point2: b2Vec2

      The ray ending point.

    Returns b2Fixture[]

    Array of all the fixtures intersected by the ray.

RayCastOne

  • Ray-cast the world for the first fixture in the path of the ray.

    Parameters

    • point1: b2Vec2

      The ray starting point.

    • point2: b2Vec2

      The ray ending point.

    Returns b2Fixture

    First fixture intersected by the ray.

RemoveController

  • Removes the controller from the world.

    Parameters

    Returns void

SetBroadPhase

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

    warning

    This function is locked during callbacks.

    Parameters

    Returns void

SetContactFilter

  • Register a contact filter to provide specific control over collision. Otherwise the default filter is used (b2_defaultFilter).

    Parameters

    Returns void

SetContactListener

  • Register a contact event listener.

    Parameters

    Returns void

SetContinuousPhysics

  • SetContinuousPhysics(flag: boolean): void
  • Enable/disable continuous physics. For testing.

    Parameters

    • flag: boolean

      True for continuous physics, otherwise false.

    Returns void

SetDebugDraw

  • 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

SetDestructionListener

  • Destruct the world. All physics entities are destroyed and all heap memory is released.

    Parameters

    Returns void

SetGravity

  • SetGravity(gravity: b2Vec2): void
  • Change the global gravity vector.

    Parameters

    • gravity: b2Vec2

      New global gravity vector.

    Returns void

SetWarmStarting

  • SetWarmStarting(flag: boolean): void
  • Enable/disable warm starting. For testing.

    Parameters

    • flag: boolean

      True for warm starting, otherwise false.

    Returns void

Step

  • Step(dt: number, velocityIterations: number, positionIterations: number): 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

Validate

  • Validate(): void
  • Perform validation of internal data structures.

    Returns void

Generated using TypeDoc