b2World Class
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]
Parameters:
-
[gravity=b2Vec2]
B2Vec2= optional -
[allowSleep=true]
Boolean= optional
Item Index
Methods
- setContactFilter
- addController
- calculateReasonableParticleIterations
- clearForces
- createBody
- createParticleSystem
- destroyParticleSystem
- drawDebugData
- drawParticleSystem
- drawShape
- getAllowSleeping
- getAutoClearForces
- getBodyCount
- getBodyList
- getContactCount
- getContactList
- getContactManager
- getGravity
- getGroundBody
- getJointCount
- getJointList
- getParticleSystemList
- getProfile
- getProxyCount
- getSubStepping
- getTreeBalance
- getTreeHeight
- getTreeQuality
- hasForce
- isLocked
- queryAABB
- queryPoint
- queryShape
- rayCast
- rayCastAll
- rayCastOne
- removeController
- setAllowSleeping
- setAutoClearForces
- setBroadPhase
- setContactListener
- setContinuousPhysics
- setContinuousPhysics
- setDebugDraw
- setDestructionListener
- setGravity
- setSubStepping
- setWarmStarting
- shiftOrigin
- solve
- step
- worldRayCastOneWrapper
Methods
setContactFilter
-
filter
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
B2FilterData to filter contacts by.
Returns:
addController
-
controller
See b2Controller list.
Parameters:
-
controller
B2Controller
Returns:
calculateReasonableParticleIterations
-
timeStep
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
FloatIs the value to be passed into
Step
.
Returns:
Reasonable particle iterations
clearForces
()
Void
public
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:
createBody
-
bodyDef
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:
createParticleSystem
-
systemDef
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:
destroyParticleSystem
-
system
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:
drawDebugData
()
Void
public
Call this to draw shapes and other debug draw data. This is intentionally non-const.
Returns:
drawParticleSystem
-
system
Parameters:
-
system
B2ParticleSystem
Returns:
drawShape
-
fixture
-
transform
-
color
Parameters:
-
fixture
B2Fixture -
transform
B2Transform -
color
B2Color
Returns:
getAutoClearForces
()
Boolean
public
Get the flag that controls automatic clearing of forces after each time step.
Returns:
getBodyCount
()
Int
public
Get the number of bodies.
Returns:
getBodyList
()
B2Body
public
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:
The head of the world body linked-list.
getContactCount
()
Int
public
Get the number of contacts (each may have 0 or more contact points).
Returns:
getContactList
()
B2Contact
public
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:
The head of the world contact linked-list
getContactManager
()
B2ContactManager
public
Get the contact manager for testing.
Returns:
getGravity
-
[out=b2Vec2]
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= optionalreusable object
Returns:
out
getGroundBody
()
B2Body
public
Returns:
getJointCount
()
Int
public
Get the number of joints.
Returns:
getJointList
()
b2Joint
public
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:
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:
The head of the world particle-system list. NULL particle-system indicates the end of the list.
getProfile
()
B2Profile
public
Get the current profile.
Returns:
getProxyCount
()
Int
public
Get the number of broad-phase proxies.
Returns:
getSubStepping
()
Boolean
public
Get single stepped continuous physics status. For testing.
Returns:
getTreeBalance
()
Float
public
Get the balance of the dynamic tree.
Returns:
getTreeHeight
()
Float
public
Get the height of the dynamic tree.
Returns:
getTreeQuality
()
Float
public
Get the quality metric of the dynamic tree. The smaller the better. The minimum is 1.
Returns:
hasForce
()
Boolean
public
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:
TRUE if force x AND y != 0.0, FALSE otherwise.
queryAABB
-
callback
-
aabb
Query the world for all fixtures that potentially overlap the provided AABB.
Parameters:
-
callback
B2QueryCallback | Function(b2Fixture):booleanA user implemented callback class.
-
aabb
B2AABBThe query box.
Returns:
queryPoint
-
callback
-
point
-
[slop]
Parameters:
-
callback
B2QueryCallback | Function(b2Fixture):boolean -
point
B2Vec2Point in world to test.
-
[slop]
Float= optional
Returns:
queryShape
-
callback
-
shape
-
transform
-
childIndex
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:
rayCast
-
callback
-
point1
-
point2
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):numberA user implemented callback class.
-
point1
B2Vec2The ray starting point
-
point2
B2Vec2The ray ending point
Returns:
rayCastAll
-
point1
-
point2
-
out
Return all fixtures to intersect raycast.
Parameters:
-
point1
B2Vec2 -
point2
B2Vec2 -
out
Array.
Returns:
out
rayCastOne
-
point1
-
point2
Return first fixture to intersect raycast.
Parameters:
-
point1
B2Vec2The ray starting point.
-
point2
B2Vec2The ray ending point.
Returns:
setAllowSleeping
-
flag
Enable/disable allowSleeping.
Parameters:
-
flag
Boolean
Returns:
setAutoClearForces
-
flag
Set the flag that controls automatic clearing of forces after each time step.
Parameters:
-
flag
Boolean
setBroadPhase
-
broadPhase
Parameters:
-
broadPhase
B2BroadPhase
Returns:
setContactListener
-
listener
Register a contact event listener. The listener is owned by you and must remain in scope.
Parameters:
-
listener
Function
Returns:
setContinuousPhysics
-
flag
Enable/disable continuous physics. For testing.
Parameters:
-
flag
Boolean
Returns:
setDebugDraw
-
debugDraw
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
B2DebugDrawDebugDrawing definition.
Returns:
setDestructionListener
()
Void
public
Register a destruction listener. The listener is owned by you and must remain in scope.
Returns:
setGravity
-
gravity
-
[wake=true]
Change the global gravity vector.
Parameters:
-
gravity
B2Vec2 -
[wake=true]
Boolean= optionalfalse lets bodies sleep through this update.
Returns:
setSubStepping
-
flag
Enable/disable single stepped continuous physics. For testing.
Parameters:
-
flag
Boolean
Returns:
setWarmStarting
-
flag
Enable/disable warm starting. For testing.
Parameters:
-
flag
Boolean
Returns:
shiftOrigin
-
newOrigin
Shift the world origin. Useful for large worlds. The body shift formula is: position -= newOrigin.
Parameters:
-
newOrigin
B2Vec2The new origin with respect to the old origin.
Returns:
solve
-
step
Find islands, integrate and solve constraints, solve position constraints.
Parameters:
-
step
B2TimeStep
Returns:
step
-
deltaTime
-
velocityIterations
-
positionIterations
-
particleIterations
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:
Returns:
Properties
m_bodyCount
Int
public
Default: 0
m_bodyList
B2Body
public
Default: null
m_contactManager
B2ContactManager
public
m_controllerCount
Int
public
Default: 0
m_controllerList
?b2Controller | Null
public
Default: null
m_debugDraw
?b2DebugDraw | Null
public
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
Default: (0,0)
m_groundBody
Int
public
Default: b2Body.
m_inv_dt0
Float
public
This is used to compute the time step ratio to support a variable time step.
Default: 0.0
m_island
B2Island
public
m_jointCount
Int
public
Default: 0
m_jointList
?b2Joint | Null
public
Default: null
m_particleSystemList
?b2ParticleSystem
public
Default: null
m_profile
B2Profile
public
Development profiling data.