|
libgdx API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.badlogic.gdx.physics.box2d.World
public final class World
The world class manages all physics entities, dynamic simulation, and asynchronous queries. The world also contains efficient memory management facilities.
Field Summary | |
---|---|
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 Summary | |
---|---|
World(Vector2 gravity,
boolean doSleep)
Construct a world object. |
Method Summary | |
---|---|
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. |
java.util.Iterator<Body> |
getBodies()
|
int |
getBodyCount()
Get the number of bodies. |
int |
getContactCount()
Get the number of contacts (each may have 0 or more contact points). |
java.util.List<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. |
java.util.Iterator<Joint> |
getJoints()
|
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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected final Pool<Body> freeBodies
protected final Pool<Fixture> freeFixtures
protected final LongMap<Body> bodies
protected final LongMap<Fixture> fixtures
protected final LongMap<Joint> joints
protected ContactFilter contactFilter
protected ContactListener contactListener
Constructor Detail |
---|
public World(Vector2 gravity, boolean doSleep)
gravity
- the world gravity vector.doSleep
- improve performance by not simulating inactive bodies.Method Detail |
---|
public void rayCast(RayCastCallback callback, Vector2 point1, Vector2 point2)
callback
- a user implemented callback class.point1
- the ray starting pointpoint2
- the ray ending pointpublic 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 java.util.List<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 contacts
public java.util.Iterator<Body> getBodies()
public java.util.Iterator<Joint> getJoints()
public void dispose()
Disposable
dispose
in interface Disposable
public static void setVelocityThreshold(float threshold)
threshold
- the threshold, default 1.0fpublic static float getVelocityThreshold()
|
libgdx API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |