public final class World extends java.lang.Object implements Disposable
Modifier and Type | Field and Description |
---|---|
protected LongMap<Body> |
bodies
all known bodies
|
protected ContactFilter |
contactFilter
Contact filter
|
protected ContactListener |
contactListener
Contact listener
|
protected LongMap<Fixture> |
fixtures
all known fixtures
|
protected Pool<Body> |
freeBodies
pool for bodies
|
protected Pool<Fixture> |
freeFixtures
pool for fixtures
|
protected LongMap<Joint> |
joints
all known joints
|
Constructor and Description |
---|
World(Vector2 gravity,
boolean doSleep)
Construct a world object.
|
Modifier and Type | Method and Description |
---|---|
void |
clearForces()
Manually clear the force buffer on all bodies.
|
Body |
createBody(BodyDef def)
Create a rigid body given a definition.
|
Joint |
createJoint(JointDef def)
Create a joint to constrain bodies together.
|
void |
destroyBody(Body body)
Destroy a rigid body given a definition.
|
void |
destroyJoint(Joint joint)
Destroy a joint.
|
void |
dispose()
Releases all resources of this object.
|
boolean |
getAutoClearForces()
Get the flag that controls automatic clearing of forces after each time step.
|
void |
getBodies(Array<Body> bodies) |
int |
getBodyCount()
Get the number of bodies.
|
int |
getContactCount()
Get the number of contacts (each may have 0 or more contact points).
|
Array<Contact> |
getContactList()
Returns the list of
Contact instances produced by the last call to step(float, int, int) . |
Vector2 |
getGravity() |
int |
getJointCount()
Get the number of joints.
|
void |
getJoints(Array<Joint> joints) |
int |
getProxyCount()
Get the number of broad-phase proxies.
|
static float |
getVelocityThreshold() |
boolean |
isLocked()
Is the world locked (in the middle of a time step).
|
void |
QueryAABB(QueryCallback callback,
float lowerX,
float lowerY,
float upperX,
float upperY)
Query the world for all fixtures that potentially overlap the provided AABB.
|
void |
rayCast(RayCastCallback callback,
Vector2 point1,
Vector2 point2)
Ray-cast the world for all fixtures in the path of the ray.
|
void |
setAutoClearForces(boolean flag)
Set flag to control automatic clearing of forces after each time step.
|
void |
setContactFilter(ContactFilter filter)
Register a contact filter to provide specific control over collision.
|
void |
setContactListener(ContactListener listener)
Register a contact event listener.
|
void |
setContinuousPhysics(boolean flag)
Enable/disable continuous physics.
|
void |
setDestructionListener(DestructionListener listener)
Register a destruction listener.
|
void |
setGravity(Vector2 gravity)
Change the global gravity vector.
|
static void |
setVelocityThreshold(float threshold)
Sets the box2d velocity threshold globally, for all World instances.
|
void |
setWarmStarting(boolean flag)
Enable/disable warm starting.
|
void |
step(float timeStep,
int velocityIterations,
int positionIterations)
Take a time step.
|
protected ContactFilter contactFilter
protected ContactListener contactListener
public World(Vector2 gravity, boolean doSleep)
gravity
- the world gravity vector.doSleep
- improve performance by not simulating inactive bodies.public void setDestructionListener(DestructionListener listener)
public void setContactFilter(ContactFilter filter)
public void setContactListener(ContactListener listener)
public Body createBody(BodyDef def)
public void destroyBody(Body body)
public Joint createJoint(JointDef def)
public void destroyJoint(Joint joint)
public void step(float timeStep, int velocityIterations, int positionIterations)
timeStep
- the amount of time to simulate, this should not vary.velocityIterations
- for the velocity constraint solver.positionIterations
- for the position constraint solver.public void clearForces()
setAutoClearForces(boolean)
public void setWarmStarting(boolean flag)
public void setContinuousPhysics(boolean flag)
public int getProxyCount()
public int getBodyCount()
public int getJointCount()
public int getContactCount()
public void setGravity(Vector2 gravity)
public Vector2 getGravity()
public boolean isLocked()
public void setAutoClearForces(boolean flag)
public boolean getAutoClearForces()
public void QueryAABB(QueryCallback callback, float lowerX, float lowerY, float upperX, float upperY)
callback
- a user implemented callback class.lowerX
- the x coordinate of the lower left cornerlowerY
- the y coordinate of the lower left cornerupperX
- the x coordinate of the upper right cornerupperY
- the y coordinate of the upper right cornerpublic Array<Contact> getContactList()
Contact
instances produced by the last call to step(float, int, int)
. Note that the
returned list will have O(1) access times when using indexing. contacts are created and destroyed in the middle of a time
step. Use ContactListener
to avoid missing contactspublic void getBodies(Array<Body> bodies)
bodies
- an Array in which to place all bodies currently in the simulationpublic void getJoints(Array<Joint> joints)
joints
- an Array in which to place all joints currently in the simulationpublic void dispose()
Disposable
dispose
in interface Disposable
public static void setVelocityThreshold(float threshold)
threshold
- the threshold, default 1.0fpublic static float getVelocityThreshold()
public void rayCast(RayCastCallback callback, Vector2 point1, Vector2 point2)
callback
- a user implemented callback class.point1
- the ray starting pointpoint2
- the ray ending point