API Documentation for:
Show:

b2World Class

Defined in: b2World:17
Module: Dynamics

The world class manages all physics entities, dynamic simulation, and asynchronous queries. The world also contains efficient memory management facilities.

Constructor

b2World

(
  • [gravity=b2Vec2]
  • [allowSleep=true]
)

Defined in b2World:17

Parameters:

  • [gravity=b2Vec2] B2Vec2= optional
  • [allowSleep=true] Boolean= optional

Methods

setContactFilter

(
  • filter
)
Void public

Register a contact filter to provide specific control over collision. Otherwise the default filter is used (b2_defaultFilter). The listener is owned by you and must remain in scope.

Parameters:

  • filter B2Filter

    Data to filter contacts by.

Returns:

Void:

addController

(
  • controller
)
B2Controller public

Defined in addController:2307

See b2Controller list.

Parameters:

  • controller B2Controller

Returns:

B2Controller:

calculateReasonableParticleIterations

(
  • timeStep
)
Int public

Recommend a value to be used in Step for particleIterations. This calculation is necessarily a simplification and should only be used as a starting point. Please see "Particle Iterations" in the Programmer's Guide for details.

Parameters:

  • timeStep Float

    Is the value to be passed into Step.

Returns:

Int:

Reasonable particle iterations

clearForces

() Void public

Defined in clearForces:1611

Manually clear the force buffer on all bodies. By default, forces are cleared automatically after each call to Step. The default behavior is modified by calling b2World.setAutoClearForces(). The purpose of this function is to support sub-stepping. Sub-stepping is often used to maintain a fixed sized time step under a variable frame-rate. When you perform sub-stepping you will disable auto clearing of forces and instead call b2World.clearForces() after all sub-steps are complete in one pass of your game loop. See b2World.setAutoClearForces()

Returns:

Void:

createBody

(
  • bodyDef
)
B2Body public

Defined in createBody:632

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

Warning: This function is locked during callbacks.
NOTE: However using the addPhysicsJS framework event listeners you can do what every you want whenever you want and addPhysicsJS manages the locked world problems for you.

Parameters:

  • bodyDef B2BodyDef

Returns:

B2Body:

createParticleSystem

(
  • systemDef
)
B2ParticleSystem public

Create a particle system given a definition. No reference to the definition is retained.

Warning: This function is locked during callbacks.
NOTE: However using the addPhysicsJS framework event listeners you can do what every you want whenever you want and addPhysicsJS manages the locked world problems for you.

Parameters:

  • systemDef B2ParticleSystemDef

Returns:

B2ParticleSystem:

destroyParticleSystem

(
  • system
)
Void public

Destroy a particle system.

Warning: This function is locked during callbacks.
NOTE: However using the addPhysicsJS framework event listeners you can do what every you want whenever you want and addPhysicsJS manages the locked world problems for you.

Parameters:

  • system B2ParticleSystem

Returns:

Void:

drawDebugData

() Void public

Defined in drawDebugData:2061

Call this to draw shapes and other debug draw data. This is intentionally non-const.

Returns:

Void:

drawParticleSystem

(
  • system
)
Void public

Parameters:

  • system B2ParticleSystem

Returns:

Void:

drawShape

(
  • fixture
  • transform
  • color
)
Void public

Defined in drawShape:1916

Parameters:

  • fixture B2Fixture
  • transform B2Transform
  • color B2Color

Returns:

Void:

getAllowSleeping

() Boolean public

Returns:

Boolean:

flag

getAutoClearForces

() Boolean public

Get the flag that controls automatic clearing of forces after each time step.

Returns:

getBodyCount

() Int public

Defined in getBodyCount:441

Get the number of bodies.

Returns:

Int:

getBodyList

() B2Body public

Defined in getBodyList:380

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 linked-list.

getContactCount

() Int public

Defined in getContactCount:463

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

Returns:

Int:

getContactList

() B2Contact public

Defined in getContactList:422

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.

Warning: contacts are created and destroyed in the middle of a time step. Use b2ContactListener to avoid missing contacts.

Returns:

B2Contact:

The head of the world contact linked-list

getContactManager

() B2ContactManager public

Get the contact manager for testing.

Returns:

B2ContactManager:

getGravity

(
  • [out=b2Vec2]
)
B2Vec2 | Object public

Defined in getGravity:497

Get the global gravity vector.

NOTE: Unless a reusable object is provided, this returns a permanently heap allocated b2Vec2 for memory management. Copy returned values to avoid un expected value changes due to recycling.

Parameters:

  • [out=b2Vec2] B2Vec2 | Object= optional

    reusable object

Returns:

B2Vec2 | Object:

out

getGroundBody

() B2Body public

Defined in getGroundBody:514

Returns:

B2Body:

getJointCount

() Int public

Defined in getJointCount:452

Get the number of joints.

Returns:

Int:

getJointList

() b2Joint public

Defined in getJointList:393

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 linked-list.

getParticleSystemList

() B2ParticleSystem public

Get the world particle-system list. With the returned body, use b2ParticleSystem::GetNext to get the next particle-system in the world list. A NULL particle-system indicates the end of the list.

Returns:

B2ParticleSystem:

The head of the world particle-system list. NULL particle-system indicates the end of the list.

getProfile

() B2Profile public

Defined in getProfile:568

Get the current profile.

Returns:

B2Profile:

getProxyCount

() Int public

Defined in getProxyCount:2230

Get the number of broad-phase proxies.

Returns:

Int:

getSubStepping

() Boolean public

Defined in getSubStepping:368

Get single stepped continuous physics status. For testing.

Returns:

getTreeBalance

() Float public

Defined in getTreeBalance:2252

Get the balance of the dynamic tree.

Returns:

Float:

getTreeHeight

() Float public

Defined in getTreeHeight:2241

Get the height of the dynamic tree.

Returns:

Float:

getTreeQuality

() Float public

Defined in getTreeQuality:2263

Get the quality metric of the dynamic tree. The smaller the better. The minimum is 1.

Returns:

Float:

hasForce

() Boolean public

Defined in hasForce:272

Returns FALSE if the b2World has zero force on BOTH the x and y axis.

NOTE: addPhysicsJS feeds zero force into addBox2D and handles force itself, which enables its much more advanced, customisable force abilities. Including multiple force fields.

Returns:

Boolean:

TRUE if force x AND y != 0.0, FALSE otherwise.

isLocked

() Boolean public

Defined in isLocked:523

Is the world locked (is it mid time step).

Returns:

queryAABB

(
  • callback
  • aabb
)
Void public

Defined in queryAABB:1633

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

Parameters:

  • callback B2QueryCallback | Function(b2Fixture):boolean

    A user implemented callback class.

  • aabb B2AABB

    The query box.

Returns:

Void:

queryPoint

(
  • callback
  • point
  • [slop]
)
Void public

Defined in queryPoint:1733

Parameters:

  • callback B2QueryCallback | Function(b2Fixture):boolean
  • point B2Vec2

    Point in world to test.

  • [slop] Float= optional

Returns:

Void:

queryShape

(
  • callback
  • shape
  • transform
  • childIndex
)
Void public

Defined in queryShape:1677

Query the world for all fixtures that potentially overlap the provided shape's AABB. Calls b2World.queryAABB() internally.

Parameters:

  • callback B2QueryCallback | Function(b2Fixture):boolean
  • shape B2Shape
  • transform B2Transform
  • childIndex Int

Returns:

Void:

rayCast

(
  • callback
  • point1
  • point2
)
Void public

Defined in rayCast:1784

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 B2RayCastCallback | Function(b2Fixture,b2Vec2,b2Vec2,number):number

    A user implemented callback class.

  • point1 B2Vec2

    The ray starting point

  • point2 B2Vec2

    The ray ending point

Returns:

Void:

rayCastAll

(
  • point1
  • point2
  • out
)
Array. public

Defined in rayCastAll:1885

Return all fixtures to intersect raycast.

Parameters:

  • point1 B2Vec2
  • point2 B2Vec2
  • out Array.

Returns:

Array.:

out

rayCastOne

(
  • point1
  • point2
)
B2Fixture public

Defined in rayCastOne:1849

Return first fixture to intersect raycast.

Parameters:

  • point1 B2Vec2

    The ray starting point.

  • point2 B2Vec2

    The ray ending point.

Returns:

B2Fixture:

removeController

() B2Controller public

See b2Controller list.

Returns:

B2Controller:

setAllowSleeping

(
  • flag
)
Void public

Enable/disable allowSleeping.

Parameters:

Returns:

Void:

setAutoClearForces

(
  • flag
)
public

Set the flag that controls automatic clearing of forces after each time step.

Parameters:

setBroadPhase

(
  • broadPhase
)
Void public

Defined in setBroadPhase:2180

Parameters:

  • broadPhase B2BroadPhase

Returns:

Void:

setContactListener

(
  • listener
)
Void public

Register a contact event listener. The listener is owned by you and must remain in scope.

Parameters:

Returns:

Void:

setContinuousPhysics

(
  • flag
)
Void public

Enable/disable continuous physics. For testing.

Parameters:

Returns:

Void:

setContinuousPhysics

() Boolean public

Get continuous physics status. For testing.

Returns:

setDebugDraw

(
  • debugDraw
)
Void public

Defined in setDebugDraw:618

Register a routine for debug drawing. The debug draw functions are called inside with b2World::DrawDebugData method. The debug draw object is owned by you and must remain in scope.

Parameters:

  • debugDraw B2DebugDraw

    DebugDrawing definition.

Returns:

Void:

setDestructionListener

() Void public

Register a destruction listener. The listener is owned by you and must remain in scope.

Returns:

Void:

setGravity

(
  • gravity
  • [wake=true]
)
Void public

Defined in setGravity:474

Change the global gravity vector.

Parameters:

  • gravity B2Vec2
  • [wake=true] Boolean= optional

    false lets bodies sleep through this update.

Returns:

Void:

setSubStepping

(
  • flag
)
Void public

Defined in setSubStepping:355

Enable/disable single stepped continuous physics. For testing.

Parameters:

Returns:

Void:

setWarmStarting

(
  • flag
)
Void public

Defined in setWarmStarting:320

Enable/disable warm starting. For testing.

Parameters:

Returns:

Void:

shiftOrigin

(
  • newOrigin
)
Void public

Defined in shiftOrigin:2275

Shift the world origin. Useful for large worlds. The body shift formula is: position -= newOrigin.

Parameters:

  • newOrigin B2Vec2

    The new origin with respect to the old origin.

Returns:

Void:

solve

(
  • step
)
Void public

Defined in solve:1018

Find islands, integrate and solve constraints, solve position constraints.

Parameters:

  • step B2TimeStep

Returns:

Void:

step

(
  • deltaTime
  • velocityIterations
  • positionIterations
  • particleIterations
)
Void public

Defined in step:1520

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

For the numerical stability of particles, minimize the following dimensionless gravity acceleration: gravity / particleRadius * (timeStep / particleIterations)^2 b2ParticleSystem.b2CalculateParticleIterations() or CalculateReasonableParticleIterations() help to determine the optimal particleIterations.

Parameters:

  • deltaTime Number

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

  • velocityIterations Number

    For the velocity constraint solver.

  • positionIterations Number

    For the position constraint solver.

  • particleIterations Number=

    For the particle constraint solver. (Only if particle module included.)

Returns:

Void:

worldRayCastOneWrapper

(
  • fixture
  • point
  • normal
  • fraction
)
Number private

Parameters:

  • fixture B2Fixture
  • point B2Vec2
  • normal B2Vec2
  • fraction Number

Returns:

Properties

m_allowSleep

Boolean public

Defined in m_allowSleep:93

Enable/disable sleep.

m_bodyCount

Int public

Defined in m_bodyCount:111

Default: 0

m_bodyList

B2Body public

Defined in m_bodyList:103

Default: null

m_contactManager

B2ContactManager public

Defined in m_contactManager:58

m_controllerCount

Int public

Default: 0

m_controllerList

?b2Controller | Null public

Default: null

m_debugDraw

?b2DebugDraw | Null public

Defined in m_debugDraw:127

Default: null

m_destructionListener

?b2DestructionListener | Null public

Default: null

m_flag_clearForces

Boolean public

The flag that controls automatic clearing of forces after each time step.

Default: true

m_gravity

B2Vec2 public

Defined in m_gravity:65

Default: (0,0)

m_groundBody

Int public

Defined in m_groundBody:82

Default: b2Body.

m_inv_dt0

Float public

Defined in m_inv_dt0:154

This is used to compute the time step ratio to support a variable time step.

Default: 0.0

m_island

B2Island public

Defined in m_island:164

m_jointCount

Int public

Defined in m_jointCount:171

Default: 0

m_jointList

?b2Joint | Null public

Defined in m_jointList:179

Default: null

m_particleSystemList

?b2ParticleSystem public

Default: null

m_profile

B2Profile public

Defined in m_profile:73

Development profiling data.

s_stack

Array. public

Defined in s_stack:188