public class World

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

Fields

public static final int WORLD_POOL_SIZE = 100
public static final int WORLD_POOL_CONTAINER_SIZE = 10
public static final int NEW_FIXTURE = 1
public static final int LOCKED = 2
public static final int CLEAR_FORCES = 4
public int activeContacts
public int contactPoolCount
protected int m_flags
protected ContactManager m_contactManager

Constructors

public World(Vec2 gravity)Construct a world object.
public World(Vec2 gravity, IWorldPool pool)Construct a world object.
public World(Vec2 gravity, IWorldPool argPool, BroadPhaseStrategy broadPhaseStrategy)

Methods

public void setAllowSleep(boolean flag)
public void setSubStepping(boolean subStepping)
public boolean isSubStepping()
public boolean isAllowSleep()
public Contact popContact(Fixture fixtureA, int indexA, Fixture fixtureB, int indexB)
public void pushContact(Contact contact)
public IWorldPool getPool()
public void setDestructionListener(DestructionListener listener)Register a destruction listener.
public void setContactFilter(ContactFilter filter)Register a contact filter to provide specific control over collision.
public void setContactListener(ContactListener listener)Register a contact event listener.
public void setDebugDraw(DebugDraw debugDraw)Register a routine for debug drawing.
public Body createBody(BodyDef def)create a rigid body given a definition.
public void destroyBody(Body body)destroy a rigid body given a definition.
public Joint createJoint(JointDef def)create a joint to constrain bodies together.
public void destroyJoint(Joint j)destroy a joint.
public void step(float dt, int velocityIterations, int positionIterations)Take a time step.
public void clearForces()Call this after you are done with time steps to clear the forces.
public void drawDebugData()Call this to draw shapes and other debug draw data.
public void queryAABB(QueryCallback callback, AABB aabb)Query the world for all fixtures that potentially overlap the provided AABB.
public void raycast(RayCastCallback callback, Vec2 point1, Vec2 point2)Ray-cast the world for all fixtures in the path of the ray.
public Body getBodyList()Get the world body list.
public Joint getJointList()Get the world joint list.
public Contact getContactList()Get the world contact list.
public boolean isSleepingAllowed()
public void setSleepingAllowed(boolean sleepingAllowed)
public void setWarmStarting(boolean flag)Enable/disable warm starting.
public boolean isWarmStarting()
public void setContinuousPhysics(boolean flag)Enable/disable continuous physics.
public boolean isContinuousPhysics()
public int getProxyCount()Get the number of broad-phase proxies.
public int getBodyCount()Get the number of bodies.
public int getJointCount()Get the number of joints.
public int getContactCount()Get the number of contacts (each may have 0 or more contact points).
public int getTreeHeight()Gets the height of the dynamic tree
public int getTreeBalance()Gets the balance of the dynamic tree
public float getTreeQuality()Gets the quality of the dynamic tree
public void setGravity(Vec2 gravity)Change the global gravity vector.
public Vec2 getGravity()Get the global gravity vector.
public boolean isLocked()Is the world locked (in the middle of a time step).
public void setAutoClearForces(boolean flag)Set flag to control automatic clearing of forces after each time step.
public boolean getAutoClearForces()Get the flag that controls automatic clearing of forces after each time step.
public ContactManager getContactManager()Get the contact manager for testing purposes
public Profile getProfile()

Inherited methods

Field details

WORLD_POOL_SIZE

public static final int WORLD_POOL_SIZE = 100

WORLD_POOL_CONTAINER_SIZE

public static final int WORLD_POOL_CONTAINER_SIZE = 10

NEW_FIXTURE

public static final int NEW_FIXTURE = 1

LOCKED

public static final int LOCKED = 2

CLEAR_FORCES

public static final int CLEAR_FORCES = 4

activeContacts

public int activeContacts

contactPoolCount

public int contactPoolCount

m_flags

protected int m_flags

m_contactManager

protected ContactManager m_contactManager

Constructor details

World

public World(Vec2 gravity)
Construct a world object.

Parameters

gravity Vec2
the world gravity vector.

World

public World(Vec2 gravity, IWorldPool pool)
Construct a world object.

Parameters

gravity Vec2
the world gravity vector.
pool IWorldPool
Not documented.

World

public World(Vec2 gravity, IWorldPool argPool, BroadPhaseStrategy broadPhaseStrategy)

Method details

setAllowSleep

public void setAllowSleep(boolean flag)

setSubStepping

public void setSubStepping(boolean subStepping)

isSubStepping

public boolean isSubStepping()

isAllowSleep

public boolean isAllowSleep()

popContact

public Contact popContact(Fixture fixtureA, int indexA, Fixture fixtureB, int indexB)

pushContact

public void pushContact(Contact contact)

getPool

public IWorldPool getPool()

setDestructionListener

public void setDestructionListener(DestructionListener listener)
Register a destruction listener. The listener is owned by you and must remain in scope.

setContactFilter

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

setContactListener

public void setContactListener(ContactListener listener)
Register a contact event listener. The listener is owned by you and must remain in scope.

setDebugDraw

public void setDebugDraw(DebugDraw debugDraw)
Register a routine for debug drawing. The debug draw functions are called inside with World.DrawDebugData method. The debug draw object is owned by you and must remain in scope.

createBody

public Body createBody(BodyDef def)
create a rigid body given a definition. No reference to the definition is retained.
Warning. This function is locked during callbacks.

destroyBody

public void destroyBody(Body body)
destroy a rigid body given a definition. No reference to the definition is retained. This function is locked during callbacks.
Warning. This automatically deletes all associated shapes and joints.
Warning. This function is locked during callbacks.

createJoint

public Joint createJoint(JointDef def)
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.

destroyJoint

public void destroyJoint(Joint j)
destroy a joint. This may cause the connected bodies to begin colliding.
Warning. This function is locked during callbacks.

step

public void step(float dt, int velocityIterations, int positionIterations)
Take a time step. This performs collision detection, integration, and constraint solution.

Parameters

dt float
Not documented.
velocityIterations int
for the velocity constraint solver.
positionIterations int
for the position constraint solver.

clearForces

public void clearForces()
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. By default, forces will be automatically cleared, so you don’t need to call this function.

See also

  • setAutoClearForces

drawDebugData

public void drawDebugData()
Call this to draw shapes and other debug draw data.

queryAABB

public void queryAABB(QueryCallback callback, AABB aabb)
Query the world for all fixtures that potentially overlap the provided AABB.

Parameters

callback QueryCallback
a user implemented callback class.
aabb AABB
the query box.

raycast

public void raycast(RayCastCallback callback, Vec2 point1, Vec2 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 RayCastCallback
a user implemented callback class.
point1 Vec2
the ray starting point
point2 Vec2
the ray ending point

getBodyList

public Body getBodyList()
Get the world body list. With the returned body, use Body.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 list.

getJointList

public Joint getJointList()
Get the world joint list. With the returned joint, use Joint.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 list.

getContactList

public Contact getContactList()
Get the world contact list. With the returned contact, use Contact.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 ContactListener to avoid missing contacts.

Returns

the head of the world contact list.

isSleepingAllowed

public boolean isSleepingAllowed()

setSleepingAllowed

public void setSleepingAllowed(boolean sleepingAllowed)

setWarmStarting

public void setWarmStarting(boolean flag)
Enable/disable warm starting. For testing.

isWarmStarting

public boolean isWarmStarting()

setContinuousPhysics

public void setContinuousPhysics(boolean flag)
Enable/disable continuous physics. For testing.

isContinuousPhysics

public boolean isContinuousPhysics()

getProxyCount

public int getProxyCount()
Get the number of broad-phase proxies.

getBodyCount

public int getBodyCount()
Get the number of bodies.

getJointCount

public int getJointCount()
Get the number of joints.

getContactCount

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

getTreeHeight

public int getTreeHeight()
Gets the height of the dynamic tree

getTreeBalance

public int getTreeBalance()
Gets the balance of the dynamic tree

getTreeQuality

public float getTreeQuality()
Gets the quality of the dynamic tree

setGravity

public void setGravity(Vec2 gravity)
Change the global gravity vector.

getGravity

public Vec2 getGravity()
Get the global gravity vector.

isLocked

public boolean isLocked()
Is the world locked (in the middle of a time step).

setAutoClearForces

public void setAutoClearForces(boolean flag)
Set flag to control automatic clearing of forces after each time step.

getAutoClearForces

public boolean getAutoClearForces()
Get the flag that controls automatic clearing of forces after each time step.

getContactManager

public ContactManager getContactManager()
Get the contact manager for testing purposes

getProfile

public Profile getProfile()