Class World
java.lang.Object
org.jbox2d.dynamics.World
public class World
extends java.lang.Object
The world class manages all physics entities, dynamic simulation, and asynchronous queries. The
world also contains efficient memory management facilities.
-
Field Summary
FieldsModifier and TypeFieldDescriptionintprivate floatprivate final Vec2Arrayprivate final Vec2private final Sweepprivate final Sweepprivate final Timerprivate final Vec2private final Vec2private final Vec2private final Vec2static final intprivate final Color3fintprivate ContactRegister[][]private final RayCastInputprivate final Islandprivate final Profileprivate static java.lang.Integerprivate final Color3fprivate floatprivate final Vec2static final intprivate booleanprivate intprivate Bodyprotected ContactManagerprivate booleanprivate DebugDrawprivate DestructionListenerprotected intprivate final Vec2private floatThis is used to compute the time step ratio to support a variable time step.private intprivate Jointprivate Profileprivate booleanprivate booleanprivate booleanstatic final intprivate final IWorldPoolprivate Body[]private final TimeStepprivate final Timerprivate final TimeStepprivate final Body[]private final Timerprivate final Vec2Arrayprivate final TimeOfImpact.TOIInputprivate final Islandprivate final TimeOfImpact.TOIOutputprivate final Vec2private final Vec2static final intstatic final intprivate final WorldQueryWrapperprivate final WorldRayCastWrapperprivate final Transform -
Constructor Summary
ConstructorsConstructorDescriptionConstruct a world object.World(Vec2 gravity, IWorldPool pool) Construct a world object.World(Vec2 gravity, IWorldPool argPool, BroadPhaseStrategy broadPhaseStrategy) -
Method Summary
Modifier and TypeMethodDescriptionprivate voidaddType(IDynamicStack<Contact> creator, ShapeType type1, ShapeType type2) voidCall this after you are done with time steps to clear the forces.createBody(BodyDef def) create a rigid body given a definition.createJoint(JointDef def) create a joint to constrain bodies together.voiddestroyBody(Body body) destroy a rigid body given a definition.voiddestroy a joint.voidCall this to draw shapes and other debug draw data.private voidprivate voidbooleanGet the flag that controls automatic clearing of forces after each time step.intGet the number of bodies.Get the world body list.intGet the number of contacts (each may have 0 or more contact points).Get the world contact list.Get the contact manager for testing purposesGet the global gravity vector.intGet the number of joints.Get the world joint list.getPool()intGet the number of broad-phase proxies.intGets the balance of the dynamic treeintGets the height of the dynamic treefloatGets the quality of the dynamic treeprivate voidbooleanbooleanbooleanisLocked()Is the world locked (in the middle of a time step).booleanbooleanbooleanpopContact(Fixture fixtureA, int indexA, Fixture fixtureB, int indexB) voidpushContact(Contact contact) voidqueryAABB(QueryCallback callback, AABB aabb) Query the world for all fixtures that potentially overlap the provided AABB.voidraycast(RayCastCallback callback, Vec2 point1, Vec2 point2) Ray-cast the world for all fixtures in the path of the ray.voidsetAllowSleep(boolean flag) voidsetAutoClearForces(boolean flag) Set flag to control automatic clearing of forces after each time step.voidsetContactFilter(ContactFilter filter) Register a contact filter to provide specific control over collision.voidsetContactListener(ContactListener listener) Register a contact event listener.voidsetContinuousPhysics(boolean flag) Enable/disable continuous physics.voidsetDebugDraw(DebugDraw debugDraw) Register a routine for debug drawing.voidsetDestructionListener(DestructionListener listener) Register a destruction listener.voidsetGravity(Vec2 gravity) Change the global gravity vector.voidsetSleepingAllowed(boolean sleepingAllowed) voidsetSubStepping(boolean subStepping) voidsetWarmStarting(boolean flag) Enable/disable warm starting.private voidprivate voidvoidstep(float dt, int velocityIterations, int positionIterations) Take a time step.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
WORLD_POOL_SIZE
public static final int WORLD_POOL_SIZE- See Also:
-
WORLD_POOL_CONTAINER_SIZE
public static final int WORLD_POOL_CONTAINER_SIZE- See Also:
-
NEW_FIXTURE
public static final int NEW_FIXTURE- See Also:
-
LOCKED
public static final int LOCKED- See Also:
-
CLEAR_FORCES
public static final int CLEAR_FORCES- See Also:
-
activeContacts
public int activeContacts -
contactPoolCount
public int contactPoolCount -
m_flags
protected int m_flags -
m_contactManager
-
m_bodyList
-
m_jointList
-
m_bodyCount
private int m_bodyCount -
m_jointCount
private int m_jointCount -
m_gravity
-
m_allowSleep
private boolean m_allowSleep -
m_destructionListener
-
m_debugDraw
-
pool
-
m_inv_dt0
private float m_inv_dt0This is used to compute the time step ratio to support a variable time step. -
m_warmStarting
private boolean m_warmStarting -
m_continuousPhysics
private boolean m_continuousPhysics -
m_subStepping
private boolean m_subStepping -
m_stepComplete
private boolean m_stepComplete -
m_profile
-
contactStacks
-
step
-
stepTimer
-
tempTimer
-
color
-
xf
-
cA
-
cB
-
avs
-
wqwrapper
-
wrcwrapper
-
input
-
island
-
stack
-
islandProfile
-
broadphaseTimer
-
toiIsland
-
toiInput
-
toiOutput
-
subStep
-
tempBodies
-
backup1
-
backup2
-
LIQUID_INT
private static java.lang.Integer LIQUID_INT -
liquidLength
private float liquidLength -
averageLinearVel
private float averageLinearVel -
liquidOffset
-
circCenterMoved
-
liquidColor
-
center
-
axis
-
v1
-
v2
-
tlvertices
-
-
Constructor Details
-
World
Construct a world object.- Parameters:
gravity- the world gravity vector.
-
World
Construct a world object.- Parameters:
gravity- the world gravity vector.
-
World
-
-
Method Details
-
setAllowSleep
public void setAllowSleep(boolean flag) -
setSubStepping
public void setSubStepping(boolean subStepping) -
isSubStepping
public boolean isSubStepping() -
isAllowSleep
public boolean isAllowSleep() -
addType
-
initializeRegisters
private void initializeRegisters() -
popContact
-
pushContact
-
getPool
-
setDestructionListener
Register a destruction listener. The listener is owned by you and must remain in scope.- Parameters:
listener-
-
setContactFilter
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.- Parameters:
filter-
-
setContactListener
Register a contact event listener. The listener is owned by you and must remain in scope.- Parameters:
listener-
-
setDebugDraw
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.- Parameters:
debugDraw-
-
createBody
-
destroyBody
destroy a rigid body given a definition. No reference to the definition is retained. This function is locked during callbacks.- Parameters:
body-
-
createJoint
-
destroyJoint
destroy a joint. This may cause the connected bodies to begin colliding.- Parameters:
joint-
-
step
public void step(float dt, int velocityIterations, int positionIterations) Take a time step. This performs collision detection, integration, and constraint solution.- Parameters:
velocityIterations- for the velocity constraint solver.positionIterations- for the position constraint solver.timeStep- the amount of time to simulate, this should not vary.
-
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:
-
drawDebugData
public void drawDebugData()Call this to draw shapes and other debug draw data. -
queryAABB
Query the world for all fixtures that potentially overlap the provided AABB.- Parameters:
callback- a user implemented callback class.aabb- the query box.
-
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- a user implemented callback class.point1- the ray starting pointpoint2- the ray ending point
-
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
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
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.- 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.- Parameters:
flag-
-
isWarmStarting
public boolean isWarmStarting() -
setContinuousPhysics
public void setContinuousPhysics(boolean flag) Enable/disable continuous physics. For testing.- Parameters:
flag-
-
isContinuousPhysics
public boolean isContinuousPhysics() -
getProxyCount
public int getProxyCount()Get the number of broad-phase proxies.- Returns:
-
getBodyCount
public int getBodyCount()Get the number of bodies.- Returns:
-
getJointCount
public int getJointCount()Get the number of joints.- Returns:
-
getContactCount
public int getContactCount()Get the number of contacts (each may have 0 or more contact points).- Returns:
-
getTreeHeight
public int getTreeHeight()Gets the height of the dynamic tree- Returns:
-
getTreeBalance
public int getTreeBalance()Gets the balance of the dynamic tree- Returns:
-
getTreeQuality
public float getTreeQuality()Gets the quality of the dynamic tree- Returns:
-
setGravity
-
getGravity
-
isLocked
public boolean isLocked()Is the world locked (in the middle of a time step).- Returns:
-
setAutoClearForces
public void setAutoClearForces(boolean flag) Set flag to control automatic clearing of forces after each time step.- Parameters:
flag-
-
getAutoClearForces
public boolean getAutoClearForces()Get the flag that controls automatic clearing of forces after each time step.- Returns:
-
getContactManager
-
getProfile
-
solve
-
solveTOI
-
drawJoint
-
drawShape
-