org.jbox2d.dynamics
Class World

java.lang.Object
  extended by org.jbox2d.dynamics.World

public class World
extends Object

The world that physics takes place in.

To the extent that it is possible, avoid accessing members directly, as in a future version their accessibility may be rolled back - as un-Java as that is, we must follow upstream C++ conventions, and for now everything is public to speed development of Box2d, but it is subject to change. You're warned!


Constructor Summary
World(AABB worldAABB, Vec2 gravity, boolean doSleep)
          Construct a world object.
 
Method Summary
 Body createBody(BodyDef def)
          Create a body given a definition.
 Joint createJoint(JointDef def)
          Create a joint to constrain bodies together.
 void destroyBody(Body b)
          Destroy a rigid body given a definition.
 void destroyJoint(Joint j)
          Destroy a joint.
 void drawDebugData()
          For internal use
 void drawJoint(Joint joint)
          For internal use
 void drawShape(Shape shape, XForm xf, Color3f color, boolean core)
          For internal use
 int getBodyCount()
          Get the number of bodies.
 Body getBodyList()
          Get the world body list.
 int getContactCount()
          Get the number of contacts (each may have 0 or more contact points).
 DebugDraw getDebugDraw()
           
 Vec2 getGravity()
          Get a clone of the global gravity vector.
 Body getGroundBody()
          The world provides a single static ground body with no collision shapes.
 int getJointCount()
          Get the number of joints.
 Joint getJointList()
          Get the world joint list.
 int getPairCount()
          Get the number of broad-phase pairs.
 int getProxyCount()
          Get the number of broad-phase proxies.
 AABB getWorldAABB()
          Get the world bounding box.
 boolean inRange(AABB aabb)
          Return true if the bounding box is within range of the world AABB.
 boolean isDrawingDebugData()
           
 Shape[] query(AABB aabb, int maxCount)
          Query the world for all shapes that potentially overlap the provided AABB up to max count.
 void refilter(Shape shape)
          Re-filter a shape.
 void registerPostStep(Steppable s)
          Registers a Steppable object to be stepped immediately following the physics step, once the locks are lifted.
 void setBoundaryListener(BoundaryListener listener)
          Register a broad-phase boundary listener.
 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 setDebugDraw(DebugDraw debugDraw)
          Register a routine for debug drawing.
 void setDestructionListener(DestructionListener listener)
          Register a destruction listener.
 void setDrawDebugData(boolean tf)
           
 void setGravity(Vec2 gravity)
          Change the global gravity vector.
 void setPositionCorrection(boolean flag)
          Enable/disable position correction.
 void setWarmStarting(boolean flag)
          Enable/disable warm starting.
 void solve(TimeStep step)
          For internal use
 void solveTOI(TimeStep step)
          For internal use: find TOI contacts and solve them.
 void step(float dt, int iterations)
          Take a time step.
 void unregisterPostStep(Steppable s)
          Unregisters a method from post-stepping.
 void validate()
          Perform validation of internal data structures.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

World

public World(AABB worldAABB,
             Vec2 gravity,
             boolean doSleep)
Construct a world object.

Parameters:
worldAABB - a bounding box that completely encompasses all your shapes.
gravity - the world gravity vector.
doSleep - improve performance by not simulating inactive bodies.
Method Detail

setDrawDebugData

public void setDrawDebugData(boolean tf)

isDrawingDebugData

public boolean isDrawingDebugData()

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).


setGravity

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


getGravity

public Vec2 getGravity()
Get a clone of the global gravity vector.

Returns:
Clone of gravity vector

getGroundBody

public Body getGroundBody()
The world provides a single static ground body with no collision shapes. You can use this to simplify the creation of joints and static shapes.


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.

setDestructionListener

public void setDestructionListener(DestructionListener listener)
Register a destruction listener.


setBoundaryListener

public void setBoundaryListener(BoundaryListener listener)
Register a broad-phase boundary listener.


setContactListener

public void setContactListener(ContactListener listener)
Register a contact event listener


setContactFilter

public void setContactFilter(ContactFilter filter)
Register a contact filter to provide specific control over collision. Otherwise the default filter is used (b2_defaultFilter).


setDebugDraw

public void setDebugDraw(DebugDraw debugDraw)
Register a routine for debug drawing. The debug draw functions are called inside the World.step() method, so make sure your renderer is ready to consume draw commands when you call step().


getDebugDraw

public DebugDraw getDebugDraw()

createBody

public Body createBody(BodyDef def)
Create a body given a definition. No reference to the definition is retained. Body will be static unless mass is nonzero.
Warning: This function is locked during callbacks.


destroyBody

public void destroyBody(Body b)
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 iterations)
Take a time step. This performs collision detection, integration, and constraint solution.

Parameters:
dt - the amount of time to simulate, this should not vary.
iterations - the number of iterations to be used by the constraint solver.

registerPostStep

public void registerPostStep(Steppable s)
Registers a Steppable object to be stepped immediately following the physics step, once the locks are lifted.

Parameters:
s -

unregisterPostStep

public void unregisterPostStep(Steppable s)
Unregisters a method from post-stepping. Fails silently if method is not found.

Parameters:
s -

refilter

public void refilter(Shape shape)
Re-filter a shape. This re-runs contact filtering on a shape.


query

public Shape[] query(AABB aabb,
                     int maxCount)
Query the world for all shapes that potentially overlap the provided AABB up to max count. The number of shapes found is returned.

Parameters:
aabb - the query box.
maxCount - the capacity of the shapes array.
Returns:
array of shapes overlapped, up to maxCount in length

solve

public void solve(TimeStep step)
For internal use


solveTOI

public void solveTOI(TimeStep step)
For internal use: find TOI contacts and solve them.


drawShape

public void drawShape(Shape shape,
                      XForm xf,
                      Color3f color,
                      boolean core)
For internal use


drawJoint

public void drawJoint(Joint joint)
For internal use


drawDebugData

public void drawDebugData()
For internal use


setWarmStarting

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


setPositionCorrection

public void setPositionCorrection(boolean flag)
Enable/disable position correction. For testing.


setContinuousPhysics

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


validate

public void validate()
Perform validation of internal data structures.


getProxyCount

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


getPairCount

public int getPairCount()
Get the number of broad-phase pairs.


getWorldAABB

public AABB getWorldAABB()
Get the world bounding box.


inRange

public boolean inRange(AABB aabb)
Return true if the bounding box is within range of the world AABB.