public class World extends java.lang.Object implements Shiftable, DataContainer
Interfacing with dyn4j starts with this class. Create a new instance of this class and add bodies and joints. Then call one of the update or step methods in your game loop to move the physics engine forward in time.
Via the addListener(Listener)
method, a World
instance can have multiple listeners for all the listener types.
Some listener types return a boolean to indicate continuing or allowing something, like CollisionListener
. If, for example,
there are multiple CollisionListener
s and any one of them returns false for an event, the collision is skipped. However,
all listeners will still be called no matter if the first returned false.
Modifier and Type  Field and Description 

static Vector2 
EARTH_GRAVITY
Earths gravity constant

static Vector2 
ZERO_GRAVITY
Zero gravity constant

Constructor and Description 

World()
Default constructor.

World(Bounds bounds)
Optional constructor.

World(Capacity initialCapacity)
Optional constructor.

World(Capacity initialCapacity,
Bounds bounds)
Full constructor.

Modifier and Type  Method and Description 

void 
addBody(Body body)

void 
addJoint(Joint joint)

void 
addListener(Listener listener)
Adds the given listener to the list of listeners.

boolean 
containsBody(Body body)
Returns true if this world contains the given body.

boolean 
containsJoint(Joint joint)
Returns true if this world contains the given joint.

boolean 
containsListener(Listener listener)
Returns true if the given listener is already attached to this world.

boolean 
convexCast(Convex convex,
Transform transform,
Vector2 deltaPosition,
Body body,
boolean ignoreSensors,
ConvexCastResult result)
Performs a linear convex cast on the given body, placing a detected collision into the given result object.

boolean 
convexCast(Convex convex,
Transform transform,
Vector2 deltaPosition,
boolean ignoreSensors,
boolean ignoreInactive,
boolean all,
java.util.List<ConvexCastResult> results)
Performs a linear convex cast on the world, placing any detected collisions into the given results list.

boolean 
convexCast(Convex convex,
Transform transform,
Vector2 deltaPosition,
boolean ignoreSensors,
boolean all,
java.util.List<ConvexCastResult> results)
Performs a linear convex cast on the world, placing any detected collisions into the given results list.

boolean 
convexCast(Convex convex,
Transform transform,
Vector2 deltaPosition,
double deltaAngle,
Body body,
boolean ignoreSensors,
ConvexCastResult result)
Performs a linear convex cast on the given body, placing a detected collision into the given result object.

boolean 
convexCast(Convex convex,
Transform transform,
Vector2 deltaPosition,
double deltaAngle,
Body body,
Filter filter,
boolean ignoreSensors,
ConvexCastResult result)
Performs a linear convex cast on the given body, placing a detected collision into the given result object.

boolean 
convexCast(Convex convex,
Transform transform,
Vector2 deltaPosition,
double deltaAngle,
boolean ignoreSensors,
boolean ignoreInactive,
boolean all,
java.util.List<ConvexCastResult> results)
Performs a linear convex cast on the world, placing any detected collisions into the given results list.

boolean 
convexCast(Convex convex,
Transform transform,
Vector2 deltaPosition,
double deltaAngle,
boolean ignoreSensors,
boolean all,
java.util.List<ConvexCastResult> results)
Performs a linear convex cast on the world, placing any detected collisions into the given results list.

boolean 
convexCast(Convex convex,
Transform transform,
Vector2 deltaPosition,
double deltaAngle,
Filter filter,
boolean ignoreSensors,
boolean ignoreInactive,
boolean all,
java.util.List<ConvexCastResult> results)
Performs a linear convex cast on the world, placing any detected collisions into the given results list.

boolean 
detect(AABB aabb,
Body body,
boolean ignoreSensors,
java.util.List<DetectResult> results)
Returns true if the given
AABB overlaps the given body in the world. 
boolean 
detect(AABB aabb,
Body body,
Filter filter,
boolean ignoreSensors,
java.util.List<DetectResult> results)
Returns true if the given
AABB overlaps the given body in the world. 
boolean 
detect(AABB aabb,
boolean ignoreSensors,
boolean ignoreInactive,
java.util.List<DetectResult> results)

boolean 
detect(AABB aabb,
boolean ignoreInactive,
java.util.List<DetectResult> results)

boolean 
detect(AABB aabb,
Filter filter,
boolean ignoreSensors,
boolean ignoreInactive,
java.util.List<DetectResult> results)

boolean 
detect(AABB aabb,
java.util.List<DetectResult> results)

boolean 
detect(Convex convex,
Body body,
boolean ignoreSensors,
java.util.List<DetectResult> results)
Returns true if the given
Convex overlaps the given body in the world. 
boolean 
detect(Convex convex,
Body body,
Filter filter,
boolean ignoreSensors,
boolean includeCollisionData,
java.util.List<DetectResult> results)
Returns true if the given
Convex overlaps the given body in the world. 
boolean 
detect(Convex convex,
Body body,
Filter filter,
boolean ignoreSensors,
java.util.List<DetectResult> results)
Returns true if the given
Convex overlaps the given body in the world. 
boolean 
detect(Convex convex,
boolean ignoreSensors,
boolean ignoreInactive,
java.util.List<DetectResult> results)
Returns true if the given
Convex overlaps a body in the world. 
boolean 
detect(Convex convex,
boolean ignoreSensors,
java.util.List<DetectResult> results)
Returns true if the given
Convex overlaps a body in the world. 
boolean 
detect(Convex convex,
Filter filter,
boolean ignoreSensors,
boolean ignoreInactive,
boolean includeCollisionData,
java.util.List<DetectResult> results)
Returns true if the given
Convex overlaps a body in the world. 
boolean 
detect(Convex convex,
Filter filter,
boolean ignoreSensors,
boolean ignoreInactive,
java.util.List<DetectResult> results)
Returns true if the given
Convex overlaps a body in the world. 
boolean 
detect(Convex convex,
java.util.List<DetectResult> results)
Returns true if the given
Convex overlaps a body in the world. 
boolean 
detect(Convex convex,
Transform transform,
Body body,
boolean ignoreSensors,
java.util.List<DetectResult> results)
Returns true if the given
Convex overlaps the given body in the world. 
boolean 
detect(Convex convex,
Transform transform,
Body body,
Filter filter,
boolean ignoreSensors,
boolean includeCollisionData,
java.util.List<DetectResult> results)
Returns true if the given
Convex overlaps the given body in the world. 
boolean 
detect(Convex convex,
Transform transform,
Body body,
Filter filter,
boolean ignoreSensors,
java.util.List<DetectResult> results)
Returns true if the given
Convex overlaps the given body in the world. 
boolean 
detect(Convex convex,
Transform transform,
boolean ignoreSensors,
boolean ignoreInactive,
java.util.List<DetectResult> results)
Returns true if the given
Convex overlaps a body in the world. 
boolean 
detect(Convex convex,
Transform transform,
boolean ignoreSensors,
java.util.List<DetectResult> results)
Returns true if the given
Convex overlaps a body in the world. 
boolean 
detect(Convex convex,
Transform transform,
Filter filter,
boolean ignoreSensors,
boolean ignoreInactive,
boolean includeCollisionData,
java.util.List<DetectResult> results)
Returns true if the given
Convex overlaps a body in the world. 
boolean 
detect(Convex convex,
Transform transform,
Filter filter,
boolean ignoreSensors,
boolean ignoreInactive,
java.util.List<DetectResult> results)
Returns true if the given
Convex overlaps a body in the world. 
boolean 
detect(Convex convex,
Transform transform,
java.util.List<DetectResult> results)
Returns true if the given
Convex overlaps a body in the world. 
double 
getAccumulatedTime()
Returns the current accumulated time.

java.util.List<Body> 
getBodies()
Returns an unmodifiable list containing all the bodies in this world.

Body 
getBody(int index)
Returns the
Body at the given index. 
int 
getBodyCount()

java.util.Iterator<Body> 
getBodyIterator()
Returns an iterator for iterating over the bodies in this world.

Bounds 
getBounds()
Returns the bounds of this world.

BroadphaseDetector<Body,BodyFixture> 
getBroadphaseDetector()
Returns the broadphase collision detection algorithm.

CoefficientMixer 
getCoefficientMixer()
Returns the
CoefficientMixer . 
ContactConstraintSolver 
getContactConstraintSolver()
Returns the
ContactConstraintSolver . 
ContactManager 
getContactManager()
Returns the
ContactManager . 
BroadphaseFilter<Body,BodyFixture> 
getDetectBroadphaseFilter()
Returns the
BroadphaseFilter used when detecting collisions for each time step. 
Vector2 
getGravity()
Returns the acceleration due to gravity.

java.util.UUID 
getId()
Returns the world id.

Joint 
getJoint(int index)
Returns the
Joint at the given index. 
int 
getJointCount()

java.util.Iterator<Joint> 
getJointIterator()
Returns an iterator for iterating over the joints in this world.

java.util.List<Joint> 
getJoints()
Returns an unmodifiable list containing all the joints in this world.

int 
getListenerCount()
Returns the total number of listeners attached to this world.

<T extends Listener> 
getListenerCount(java.lang.Class<T> clazz)
Returns the total number of listeners of the given type (or sub types)
attached to this world.

<T extends Listener> 
getListeners(java.lang.Class<T> clazz)
Returns the listeners that are of the given type (or sub types)
of the given type.

<T extends Listener> 
getListeners(java.lang.Class<T> clazz,
java.util.List<T> listeners)
Returns the listeners of the given type (or sub types) in the given list.

ManifoldSolver 
getManifoldSolver()
Returns the manifold solver.

NarrowphaseDetector 
getNarrowphaseDetector()
Returns the narrowphase collision detection algorithm.

RaycastDetector 
getRaycastDetector()
Returns the raycast detector.

Settings 
getSettings()
Returns the settings for this world.

Step 
getStep()
Returns the
Step object used to advance
the simulation. 
TimeOfImpactDetector 
getTimeOfImpactDetector()
Returns the time of impact detector.

java.lang.Object 
getUserData()
Gets the custom user data.

boolean 
isEmpty()
Returns true if this world doesn't contain any
bodies or joints.

boolean 
isUpdateRequired()
Returns true if upon the next time step the contacts must be updated.

boolean 
raycast(Ray ray,
Body body,
double maxLength,
boolean ignoreSensors,
RaycastResult result)
Performs a raycast against the given
Body and returns true
if the ray intersects the body. 
boolean 
raycast(Ray ray,
Body body,
double maxLength,
Filter filter,
boolean ignoreSensors,
RaycastResult result)
Performs a raycast against the given
Body and returns true
if the ray intersects the body. 
boolean 
raycast(Ray ray,
double maxLength,
boolean ignoreSensors,
boolean ignoreInactive,
boolean all,
java.util.List<RaycastResult> results)

boolean 
raycast(Ray ray,
double maxLength,
boolean ignoreSensors,
boolean all,
java.util.List<RaycastResult> results)

boolean 
raycast(Ray ray,
double maxLength,
Filter filter,
boolean ignoreSensors,
boolean ignoreInactive,
boolean all,
java.util.List<RaycastResult> results)

boolean 
raycast(Vector2 start,
Vector2 end,
Body body,
boolean ignoreSensors,
RaycastResult result)
Performs a raycast against the given
Body and returns true
if the ray intersects the body. 
boolean 
raycast(Vector2 start,
Vector2 end,
Body body,
Filter filter,
boolean ignoreSensors,
RaycastResult result)
Performs a raycast against the given
Body and returns true
if the ray intersects the body. 
boolean 
raycast(Vector2 start,
Vector2 end,
boolean ignoreSensors,
boolean ignoreInactive,
boolean all,
java.util.List<RaycastResult> results)

boolean 
raycast(Vector2 start,
Vector2 end,
boolean ignoreSensors,
boolean all,
java.util.List<RaycastResult> results)

boolean 
raycast(Vector2 start,
Vector2 end,
Filter filter,
boolean ignoreSensors,
boolean ignoreInactive,
boolean all,
java.util.List<RaycastResult> results)

void 
removeAllBodies()
This is a convenience method for the
removeAllBodiesAndJoints() method since all joints will be removed
when all bodies are removed anyway. 
void 
removeAllBodies(boolean notify)
This is a convenience method for the
removeAllBodiesAndJoints(boolean) method since all joints will be removed
when all bodies are removed anyway. 
void 
removeAllBodiesAndJoints()
Removes all the joints and bodies from this world.

void 
removeAllBodiesAndJoints(boolean notify)
Removes all the joints and bodies from this world.

void 
removeAllJoints()

void 
removeAllJoints(boolean notify)

int 
removeAllListeners()
Removes all the listeners.

<T extends Listener> 
removeAllListeners(java.lang.Class<T> clazz)
Removes all the listeners of the specified type (or sub types).

boolean 
removeBody(Body body)

boolean 
removeBody(Body body,
boolean notify)

boolean 
removeBody(int index)

boolean 
removeBody(int index,
boolean notify)

boolean 
removeJoint(int index)

boolean 
removeJoint(Joint joint)

boolean 
removeListener(Listener listener)
Removes the given listener from this world.

void 
setAccumulatedTime(double elapsedTime)
Sets the current accumulated time.

void 
setBounds(Bounds bounds)
Sets the bounds of this
World . 
void 
setBroadphaseDetector(BroadphaseDetector<Body,BodyFixture> broadphaseDetector)
Sets the broadphase collision detection algorithm.

void 
setCoefficientMixer(CoefficientMixer coefficientMixer)
Sets the
CoefficientMixer . 
void 
setContactConstraintSolver(ContactConstraintSolver constraintSolver)
Sets the
ContactConstraintSolver for this world. 
void 
setContactManager(ContactManager contactManager)
Sets the
ContactManager . 
void 
setDetectBroadphaseFilter(BroadphaseFilter<Body,BodyFixture> filter)
Sets the
BroadphaseFilter used when detecting collisions for each time step. 
void 
setGravity(Vector2 gravity)
Sets the acceleration due to gravity.

void 
setManifoldSolver(ManifoldSolver manifoldSolver)
Sets the manifold solver.

void 
setNarrowphaseDetector(NarrowphaseDetector narrowphaseDetector)
Sets the narrowphase collision detection algorithm.

void 
setRaycastDetector(RaycastDetector raycastDetector)
Sets the raycast detector.

void 
setSettings(Settings settings)
Sets the dynamics settings for this world.

void 
setTimeOfImpactDetector(TimeOfImpactDetector timeOfImpactDetector)
Sets the time of impact detector.

void 
setUpdateRequired(boolean flag)
Sets the update required flag.

void 
setUserData(java.lang.Object userData)
Sets the custom user data to the given data.

void 
shift(Vector2 shift)
Shifts the coordinates of the entire world by the given amount.

void 
step(int steps)
Performs the given number of simulation steps using the step frequency in
Settings . 
void 
step(int steps,
double elapsedTime)
Performs the given number of simulation steps using the given elapsed time for each step.

boolean 
update(double elapsedTime)
Updates the
World . 
boolean 
update(double elapsedTime,
double stepElapsedTime)
Updates the
World . 
boolean 
update(double elapsedTime,
double stepElapsedTime,
int maximumSteps)
Updates the
World . 
boolean 
update(double elapsedTime,
int maximumSteps)
Updates the
World . 
void 
updatev(double elapsedTime)
Updates the
World . 
public static final Vector2 EARTH_GRAVITY
public static final Vector2 ZERO_GRAVITY
public World()
Builds a simulation World
without bounds.
Defaults to using EARTH_GRAVITY
, DynamicAABBTree
broadphase,
Gjk
narrowphase, and ClippingManifoldSolver
.
Uses the Capacity.DEFAULT_CAPACITY
capacity object for initialization.
public World(Capacity initialCapacity)
Defaults to using EARTH_GRAVITY
, DynamicAABBTree
broadphase,
Gjk
narrowphase, and ClippingManifoldSolver
.
The initial capacity specifies the estimated number of bodies that the simulation will have at any one time. This is used to size internal structures to improve performance. The internal structures can grow past the initial capacity.
initialCapacity
 the initial capacity settingspublic World(Bounds bounds)
Defaults to using EARTH_GRAVITY
, DynamicAABBTree
broadphase,
Gjk
narrowphase, and ClippingManifoldSolver
.
bounds
 the bounds of the World
; can be nullpublic World(Capacity initialCapacity, Bounds bounds)
Defaults to using EARTH_GRAVITY
, DynamicAABBTree
broadphase,
Gjk
narrowphase, and ClippingManifoldSolver
.
The initial capacity specifies the estimated number of bodies that the simulation will have at any one time. This is used to size internal structures to improve performance. The internal structures can grow past the initial capacity.
initialCapacity
 the initial capacity settingsbounds
 the bounds of the World
; can be nulljava.lang.NullPointerException
 if initialCapacity is nullpublic boolean update(double elapsedTime)
World
.
This method will only update the world given the step frequency contained
in the Settings
object. You can use the StepListener
interface
to listen for when a step is actually performed. In addition, this method will
return true if a step was performed.
This method performs, at maximum, one simulation step. Any remaining time from
the previous call of this method is added to the given elapsed time to determine
if a step needs to be performed. If the given elapsed time is usually greater
than the step frequency, consider using the update(double, int)
method
instead.
Alternatively you can call the updatev(double)
method to use a variable
time step.
elapsedTime
 the elapsed time in secondsWorld
performed a simulation stepupdate(double, int)
,
updatev(double)
,
getAccumulatedTime()
public boolean update(double elapsedTime, int maximumSteps)
World
.
This method will only update the world given the step frequency contained
in the Settings
object. You can use the StepListener
interface
to listen for when a step is actually performed.
Unlike the update(double)
method, this method will perform more than one
step based on the given elapsed time. For example, if the given elapsed time + the
remaining time from the last call of this method is 2 * step frequency, then 2 steps
will be performed. Use the maximumSteps parameter to put an upper bound on the
number of steps performed.
Alternatively you can call the updatev(double)
method to use a variable
time step.
elapsedTime
 the elapsed time in secondsmaximumSteps
 the maximum number of steps to performWorld
performed at least one simulation stepupdate(double)
,
updatev(double)
,
getAccumulatedTime()
public boolean update(double elapsedTime, double stepElapsedTime)
World
.
This method will only update the world given the step frequency contained
in the Settings
object. You can use the StepListener
interface
to listen for when a step is actually performed. In addition, this method will
return true if a step was performed.
This method performs, at maximum, one simulation step. Any remaining time from
the previous call of this method is added to the given elapsed time to determine
if a step needs to be performed. If the given elapsed time is usually greater
than the step frequency, consider using the update(double, int)
method
instead.
The stepElapsedTime parameter provides a way for the World
to continue to
update at the frequency defined in the Settings
object, but advance the
simulation by the given time.
Alternatively you can call the updatev(double)
method to use a variable
time step.
elapsedTime
 the elapsed time in secondsstepElapsedTime
 the time, in seconds, that the simulation should be advancedWorld
performed at least one simulation stepupdate(double)
,
updatev(double)
,
getAccumulatedTime()
public boolean update(double elapsedTime, double stepElapsedTime, int maximumSteps)
World
.
This method will only update the world given the step frequency contained
in the Settings
object. You can use the StepListener
interface
to listen for when a step is actually performed.
Unlike the update(double)
method, this method will perform more than one
step based on the given elapsed time. For example, if the given elapsed time + the
remaining time from the last call of this method is 2 * step frequency, then 2 steps
will be performed. Use the maximumSteps parameter to put an upper bound on the
number of steps performed.
The stepElapsedTime parameter provides a way for the World
to continue to
update at the frequency defined in the Settings
object, but advance the
simulation by the given time.
Alternatively you can call the updatev(double)
method to use a variable
time step.
elapsedTime
 the elapsed time in secondsstepElapsedTime
 the time, in seconds, that the simulation should be advanced for each step; if less than or equal to zero Settings.getStepFrequency()
will be usedmaximumSteps
 the maximum number of steps to performWorld
performed at least one simulation stepupdate(double)
,
updatev(double)
,
getAccumulatedTime()
public void updatev(double elapsedTime)
World
.
This method will update the world on every call. Unlike the update(double)
method, this method uses the given elapsed time and does not attempt to update the world
on a set interval.
This method immediately returns if the given elapsedTime is less than or equal to zero.
elapsedTime
 the elapsed time in secondsupdate(double)
,
update(double, int)
public void step(int steps)
Settings
.
This method immediately returns if the given step count is less than or equal to zero.
steps
 the number of simulation steps to performpublic void step(int steps, double elapsedTime)
This method immediately returns if the given elapsedTime or step count is less than or equal to zero.
steps
 the number of simulation steps to performelapsedTime
 the elapsed time for each steppublic boolean raycast(Vector2 start, Vector2 end, boolean ignoreSensors, boolean all, java.util.List<RaycastResult> results)
Body
s in the World
.
The given RaycastResult
list, results, will be filled with the raycast results
if the given ray intersected any bodies.
The RaycastResult
class implements the Comparable interface to allow sorting by
distance from the ray's origin.
If the all flag is false, the results list will only contain the closest result (if any).
All raycasts pass through the RaycastListener
s before being tested. If any
RaycastListener
doesn't allow the raycast then the body will not be tested.
Bodies that contain the start of the ray will not be included in the results.
Inactive bodies are ignored in this test.
start
 the start pointend
 the end pointignoreSensors
 true if sensor BodyFixture
s should be ignoredall
 true if all intersected Body
s should be returned; false if only the closest Body
should be returnedresults
 a list to contain the results of the raycastBody
was intersected by the Ray
java.lang.NullPointerException
 if start, end, or results is nullraycast(Ray, double, boolean, boolean, List)
,
RaycastListener.allow(Ray, Body, BodyFixture)
public boolean raycast(Vector2 start, Vector2 end, boolean ignoreSensors, boolean ignoreInactive, boolean all, java.util.List<RaycastResult> results)
Body
s in the World
.
The given RaycastResult
list, results, will be filled with the raycast results
if the given ray intersected any bodies.
The RaycastResult
class implements the Comparable interface to allow sorting by
distance from the ray's origin.
If the all flag is false, the results list will only contain the closest result (if any).
All raycasts pass through the RaycastListener
s before being tested. If any
RaycastListener
doesn't allow the raycast then the body will not be tested.
Bodies that contain the start of the ray will not be included in the results.
start
 the start pointend
 the end pointignoreSensors
 true if sensor BodyFixture
s should be ignoredignoreInactive
 true if inactive bodies should be ignoredall
 true if all intersected Body
s should be returned; false if only the closest Body
should be returnedresults
 a list to contain the results of the raycastBody
was intersected by the Ray
java.lang.NullPointerException
 if start, end, or results is nullraycast(Ray, double, boolean, boolean, boolean, List)
,
RaycastListener.allow(Ray, Body, BodyFixture)
public boolean raycast(Vector2 start, Vector2 end, Filter filter, boolean ignoreSensors, boolean ignoreInactive, boolean all, java.util.List<RaycastResult> results)
Body
s in the World
.
The given RaycastResult
list, results, will be filled with the raycast results
if the given ray intersected any bodies.
The RaycastResult
class implements the Comparable interface to allow sorting by
distance from the ray's origin.
If the all flag is false, the results list will only contain the closest result (if any).
All raycasts pass through the RaycastListener
s before being tested. If any
RaycastListener
doesn't allow the raycast then the body will not be tested.
Bodies that contain the start of the ray will not be included in the results.
start
 the start pointend
 the end pointfilter
 the Filter
to use against the fixtures; can be nullignoreSensors
 true if sensor BodyFixture
s should be ignoredignoreInactive
 true if inactive bodies should be ignoredall
 true if all intersected Body
s should be returned; false if only the closest Body
should be returnedresults
 a list to contain the results of the raycastBody
was intersected by the Ray
java.lang.NullPointerException
 if start, end, or results is nullraycast(Ray, double, Filter, boolean, boolean, boolean, List)
,
RaycastListener.allow(Ray, Body, BodyFixture)
public boolean raycast(Ray ray, double maxLength, boolean ignoreSensors, boolean all, java.util.List<RaycastResult> results)
Body
s in the World
.
The given RaycastResult
list, results, will be filled with the raycast results
if the given ray intersected any bodies.
The RaycastResult
class implements the Comparable interface to allow sorting by
distance from the ray's origin.
If the all flag is false, the results list will only contain the closest result (if any).
Pass 0 into the maxLength field to specify an infinite length Ray
.
All raycasts pass through the RaycastListener
s before being tested. If any
RaycastListener
doesn't allow the raycast then the body will not be tested.
Bodies that contain the start of the ray will not be included in the results.
Inactive bodies are ignored in this test.
ray
 the Ray
maxLength
 the maximum length of the ray; 0 for infinite lengthignoreSensors
 true if sensor BodyFixture
s should be ignoredall
 true if all intersected Body
s should be returned; false if only the closest Body
should be returnedresults
 a list to contain the results of the raycastBody
was intersected by the given Ray
java.lang.NullPointerException
 if ray or results is nullraycast(Vector2, Vector2, boolean, boolean, List)
,
RaycastListener.allow(Ray, Body, BodyFixture)
public boolean raycast(Ray ray, double maxLength, boolean ignoreSensors, boolean ignoreInactive, boolean all, java.util.List<RaycastResult> results)
Body
s in the World
.
The given RaycastResult
list, results, will be filled with the raycast results
if the given ray intersected any bodies.
The RaycastResult
class implements the Comparable interface to allow sorting by
distance from the ray's origin.
If the all flag is false, the results list will only contain the closest result (if any).
Pass 0 into the maxLength field to specify an infinite length Ray
.
All raycasts pass through the RaycastListener
s before being tested. If any
RaycastListener
doesn't allow the raycast then the body will not be tested.
Bodies that contain the start of the ray will not be included in the results.
ray
 the Ray
maxLength
 the maximum length of the ray; 0 for infinite lengthignoreSensors
 true if sensor BodyFixture
s should be ignoredignoreInactive
 true if inactive bodies should be ignoredall
 true if all intersected Body
s should be returned; false if only the closest Body
should be returnedresults
 a list to contain the results of the raycastBody
was intersected by the given Ray
java.lang.NullPointerException
 if ray or results is nullraycast(Vector2, Vector2, boolean, boolean, boolean, List)
,
RaycastListener.allow(Ray, Body, BodyFixture)
public boolean raycast(Ray ray, double maxLength, Filter filter, boolean ignoreSensors, boolean ignoreInactive, boolean all, java.util.List<RaycastResult> results)
Body
s in the World
.
The given RaycastResult
list, results, will be filled with the raycast results
if the given ray intersected any bodies.
The RaycastResult
class implements the Comparable interface to allow sorting by
distance from the ray's origin.
If the all flag is false, the results list will only contain the closest result (if any).
Pass 0 into the maxLength field to specify an infinite length Ray
.
All raycasts pass through the RaycastListener
s before being tested. If any
RaycastListener
doesn't allow the raycast then the body will not be tested.
Bodies that contain the start of the ray will not be included in the results.
ray
 the Ray
maxLength
 the maximum length of the ray; 0 for infinite lengthfilter
 the Filter
to use against the fixtures; can be nullignoreSensors
 true if sensor BodyFixture
s should be ignoredignoreInactive
 true if inactive bodies should be ignoredall
 true if all intersected Body
s should be returned; false if only the closest Body
should be returnedresults
 a list to contain the results of the raycastBody
was intersected by the given Ray
java.lang.NullPointerException
 if ray or results is nullraycast(Vector2, Vector2, Filter, boolean, boolean, boolean, List)
,
RaycastListener.allow(Ray, Body, BodyFixture)
public boolean raycast(Vector2 start, Vector2 end, Body body, boolean ignoreSensors, RaycastResult result)
Body
and returns true
if the ray intersects the body.
The given RaycastResult
object, result, will be filled with the raycast result
if the given ray intersected the given body.
All raycasts pass through the RaycastListener
s before being tested. If any
RaycastListener
doesn't allow the raycast then the body will not be tested.
Returns false if the start position of the ray lies inside the given body.
start
 the start pointend
 the end pointbody
 the Body
to testignoreSensors
 whether or not to ignore sensor BodyFixture
sresult
 the raycast resultRay
intersects the Body
java.lang.NullPointerException
 if start, end, body, or result is nullraycast(Ray, Body, double, boolean, RaycastResult)
,
RaycastListener.allow(Ray, Body, BodyFixture)
public boolean raycast(Vector2 start, Vector2 end, Body body, Filter filter, boolean ignoreSensors, RaycastResult result)
Body
and returns true
if the ray intersects the body.
The given RaycastResult
object, result, will be filled with the raycast result
if the given ray intersected the given body.
All raycasts pass through the RaycastListener
s before being tested. If any
RaycastListener
doesn't allow the raycast then the body will not be tested.
Returns false if the start position of the ray lies inside the given body.
start
 the start pointend
 the end pointbody
 the Body
to testfilter
 the Filter
to use against the fixtures; can be nullignoreSensors
 whether or not to ignore sensor BodyFixture
sresult
 the raycast resultRay
intersects the Body
java.lang.NullPointerException
 if start, end, body, or result is nullraycast(Ray, Body, double, Filter, boolean, RaycastResult)
,
RaycastListener.allow(Ray, Body, BodyFixture)
public boolean raycast(Ray ray, Body body, double maxLength, boolean ignoreSensors, RaycastResult result)
Body
and returns true
if the ray intersects the body.
The given RaycastResult
object, result, will be filled with the raycast result
if the given ray intersected the given body.
Pass 0 into the maxLength field to specify an infinite length Ray
.
All raycasts pass through the RaycastListener
s before being tested. If any
RaycastListener
doesn't allow the raycast then the body will not be tested.
Returns false if the start position of the ray lies inside the given body.
ray
 the Ray
to castbody
 the Body
to testmaxLength
 the maximum length of the ray; 0 for infinite lengthignoreSensors
 whether or not to ignore sensor BodyFixture
sresult
 the raycast resultRay
intersects the Body
java.lang.NullPointerException
 if ray, body, or result is nullraycast(Vector2, Vector2, Body, boolean, RaycastResult)
,
RaycastListener.allow(Ray, Body, BodyFixture)
public boolean raycast(Ray ray, Body body, double maxLength, Filter filter, boolean ignoreSensors, RaycastResult result)
Body
and returns true
if the ray intersects the body.
The given RaycastResult
object, result, will be filled with the raycast result
if the given ray intersected the given body.
Pass 0 into the maxLength field to specify an infinite length Ray
.
All raycasts pass through the RaycastListener
s before being tested. If any
RaycastListener
doesn't allow the raycast then the body will not be tested.
Returns false if the start position of the ray lies inside the given body.
ray
 the Ray
to castbody
 the Body
to testmaxLength
 the maximum length of the ray; 0 for infinite lengthfilter
 the Filter
to use against the fixtures; can be nullignoreSensors
 whether or not to ignore sensor BodyFixture
sresult
 the raycast resultRay
intersects the Body
java.lang.NullPointerException
 if ray, body, or result is nullraycast(Vector2, Vector2, Body, Filter, boolean, RaycastResult)
,
RaycastListener.allow(Ray, Body, BodyFixture)
public boolean convexCast(Convex convex, Transform transform, Vector2 deltaPosition, boolean ignoreSensors, boolean all, java.util.List<ConvexCastResult> results)
This method does a static test of bodies (in other words, does not take into account the bodies linear or angular velocity, but rather assumes they are stationary).
The deltaPosition
parameter is the linear cast vector determining the direction and magnitude of the cast.
The ConvexCastResult
class implements the Comparable interface to allow sorting by
the time of impact.
If the all flag is false, the results list will only contain the closest result (if any).
All convex casts pass through the ConvexCastListener
s before being tested. If any
ConvexCastListener
doesn't allow the convex cast, then the body will not be tested.
For multifixtured bodies, only the fixture that has the minimum time of impact will be added to the results list.
Bodies in collision with the given convex at the beginning of the cast are not included in the results.
Inactive bodies are ignored in this test.
convex
 the convex to casttransform
 the initial position and orientation of the convexdeltaPosition
 Δposition; the change in position (the cast length and direction basically)ignoreSensors
 true if sensor fixtures should be ignored in the testsall
 true if all hits should be returned; false if only the first should be returnedresults
 the list to add the results toconvexCast(Convex, Transform, Vector2, double, boolean, boolean, boolean, List)
public boolean convexCast(Convex convex, Transform transform, Vector2 deltaPosition, boolean ignoreSensors, boolean ignoreInactive, boolean all, java.util.List<ConvexCastResult> results)
This method does a static test of bodies (in other words, does not take into account the bodies linear or angular velocity, but rather assumes they are stationary).
The deltaPosition
parameter is the linear cast vector determining the direction and magnitude of the cast.
The ConvexCastResult
class implements the Comparable interface to allow sorting by
the time of impact.
If the all flag is false, the results list will only contain the closest result (if any).
All convex casts pass through the ConvexCastListener
s before being tested. If any
ConvexCastListener
doesn't allow the convex cast, then the body will not be tested.
For multifixtured bodies, only the fixture that has the minimum time of impact will be added to the results list.
Bodies in collision with the given convex at the beginning of the cast are not included in the results.
convex
 the convex to casttransform
 the initial position and orientation of the convexdeltaPosition
 Δposition; the change in position (the cast length and direction basically)ignoreSensors
 true if sensor fixtures should be ignored in the testsignoreInactive
 true if inactive bodies should be ignored in the testsall
 true if all hits should be returned; false if only the first should be returnedresults
 the list to add the results toconvexCast(Convex, Transform, Vector2, double, boolean, boolean, boolean, List)
public boolean convexCast(Convex convex, Transform transform, Vector2 deltaPosition, double deltaAngle, boolean ignoreSensors, boolean all, java.util.List<ConvexCastResult> results)
This method does a static test of bodies (in other words, does not take into account the bodies linear or angular velocity, but rather assumes they are stationary).
The deltaPosition
parameter is the linear cast vector determining the direction and magnitude of the cast.
The deltaAngle
parameter is the change in angle over the linear cast and is interpolated linearly
during detection.
The ConvexCastResult
class implements the Comparable interface to allow sorting by
the time of impact.
If the all flag is false, the results list will only contain the closest result (if any).
All convex casts pass through the ConvexCastListener
s before being tested. If any
ConvexCastListener
doesn't allow the convex cast, then the body will not be tested.
For multifixtured bodies, only the fixture that has the minimum time of impact will be added to the results list.
Bodies in collision with the given convex at the beginning of the cast are not included in the results.
Inactive bodies are ignored in this test.
convex
 the convex to casttransform
 the initial position and orientation of the convexdeltaPosition
 Δposition; the change in position (the cast length and direction basically)deltaAngle
 Δangle; the change in the angle; this is the change in the angle over the linear periodignoreSensors
 true if sensor fixtures should be ignored in the testsall
 true if all hits should be returned; false if only the first should be returnedresults
 the list to add the results toconvexCast(Convex, Transform, Vector2, double, boolean, boolean, boolean, List)
public boolean convexCast(Convex convex, Transform transform, Vector2 deltaPosition, double deltaAngle, boolean ignoreSensors, boolean ignoreInactive, boolean all, java.util.List<ConvexCastResult> results)
This method does a static test of bodies (in other words, does not take into account the bodies linear or angular velocity, but rather assumes they are stationary).
The deltaPosition
parameter is the linear cast vector determining the direction and magnitude of the cast.
The deltaAngle
parameter is the change in angle over the linear cast and is interpolated linearly
during detection.
The ConvexCastResult
class implements the Comparable interface to allow sorting by
the time of impact.
If the all flag is false, the results list will only contain the closest result (if any).
All convex casts pass through the ConvexCastListener
s before being tested. If any
ConvexCastListener
doesn't allow the convex cast, then the body will not be tested.
For multifixtured bodies, only the fixture that has the minimum time of impact will be added to the results list.
Bodies in collision with the given convex at the beginning of the cast are not included in the results.
convex
 the convex to casttransform
 the initial position and orientation of the convexdeltaPosition
 Δposition; the change in position (the cast length and direction basically)deltaAngle
 Δangle; the change in the angle; this is the change in the angle over the linear periodignoreSensors
 true if sensor fixtures should be ignored in the testsignoreInactive
 true if inactive bodies should be ignored in the testsall
 true if all hits should be returned; false if only the first should be returnedresults
 the list to add the results topublic boolean convexCast(Convex convex, Transform transform, Vector2 deltaPosition, double deltaAngle, Filter filter, boolean ignoreSensors, boolean ignoreInactive, boolean all, java.util.List<ConvexCastResult> results)
This method does a static test of bodies (in other words, does not take into account the bodies linear or angular velocity, but rather assumes they are stationary).
The deltaPosition
parameter is the linear cast vector determining the direction and magnitude of the cast.
The deltaAngle
parameter is the change in angle over the linear cast and is interpolated linearly
during detection.
The ConvexCastResult
class implements the Comparable interface to allow sorting by
the time of impact.
If the all flag is false, the results list will only contain the closest result (if any).
All convex casts pass through the ConvexCastListener
s before being tested. If any
ConvexCastListener
doesn't allow the convex cast, then the body will not be tested.
For multifixtured bodies, only the fixture that has the minimum time of impact will be added to the results list.
Bodies in collision with the given convex at the beginning of the cast are not included in the results.
convex
 the convex to casttransform
 the initial position and orientation of the convexdeltaPosition
 Δposition; the change in position (the cast length and direction basically)deltaAngle
 Δangle; the change in the angle; this is the change in the angle over the linear periodfilter
 the Filter
to use against the fixtures; can be nullignoreSensors
 true if sensor fixtures should be ignored in the testsignoreInactive
 true if inactive bodies should be ignored in the testsall
 true if all hits should be returned; false if only the first should be returnedresults
 the list to add the results topublic boolean convexCast(Convex convex, Transform transform, Vector2 deltaPosition, Body body, boolean ignoreSensors, ConvexCastResult result)
This method does a static test of the body (in other words, does not take into account the body's linear or angular velocity, but rather assumes it is stationary).
The deltaPosition
parameter is the linear cast vector determining the direction and magnitude of the cast.
All convex casts pass through the ConvexCastListener
s before being tested. If any
ConvexCastListener
doesn't allow the convex cast, then the body will not be tested.
For multifixtured bodies, the fixture that has the minimum time of impact will be the result.
Returns false if the given body and convex are in collision at the beginning of the cast.
convex
 the convex to casttransform
 the initial position and orientation of the convexdeltaPosition
 Δposition; the change in position (the cast length and direction basically)body
 the body to cast againstignoreSensors
 true if sensor fixtures should be ignored in the testsresult
 the convex cast resultpublic boolean convexCast(Convex convex, Transform transform, Vector2 deltaPosition, double deltaAngle, Body body, boolean ignoreSensors, ConvexCastResult result)
This method does a static test of the body (in other words, does not take into account the body's linear or angular velocity, but rather assumes it is stationary).
The deltaPosition
parameter is the linear cast vector determining the direction and magnitude of the cast.
The deltaAngle
parameter is the change in angle over the linear cast and is interpolated linearly
during detection.
All convex casts pass through the ConvexCastListener
s before being tested. If any
ConvexCastListener
doesn't allow the convex cast, then the body will not be tested.
For multifixtured bodies, the fixture that has the minimum time of impact will be the result.
Returns false if the given body and convex are in collision at the beginning of the cast.
convex
 the convex to casttransform
 the initial position and orientation of the convexdeltaPosition
 Δposition; the change in position (the cast length and direction basically)deltaAngle
 Δangle; the change in the angle; this is the change in the angle over the linear periodbody
 the body to cast againstignoreSensors
 true if sensor fixtures should be ignored in the testsresult
 the convex cast resultpublic boolean convexCast(Convex convex, Transform transform, Vector2 deltaPosition, double deltaAngle, Body body, Filter filter, boolean ignoreSensors, ConvexCastResult result)
This method does a static test of the body (in other words, does not take into account the body's linear or angular velocity, but rather assumes it is stationary).
The deltaPosition
parameter is the linear cast vector determining the direction and magnitude of the cast.
The deltaAngle
parameter is the change in angle over the linear cast and is interpolated linearly
during detection.
All convex casts pass through the ConvexCastListener
s before being tested. If any
ConvexCastListener
doesn't allow the convex cast, then the body will not be tested.
For multifixtured bodies, the fixture that has the minimum time of impact will be the result.
Returns false if the given body and convex are in collision at the beginning of the cast.
convex
 the convex to casttransform
 the initial position and orientation of the convexdeltaPosition
 Δposition; the change in position (the cast length and direction basically)deltaAngle
 Δangle; the change in the angle; this is the change in the angle over the linear periodbody
 the body to cast againstfilter
 the Filter
to use against the fixtures; can be nullignoreSensors
 true if sensor fixtures should be ignored in the testsresult
 the convex cast resultpublic boolean detect(AABB aabb, java.util.List<DetectResult> results)
Body
in this World
.
If any part of a body is overlaping the AABB, the body is added to the list.
This performs a static collision test of the world using the BroadphaseDetector
.
This may return bodies who only have sensor fixtures overlapping.
Inactive bodies are ignored in this test.
aabb
 the world space AABB
results
 the list of overlapping bodies and fixturespublic boolean detect(AABB aabb, boolean ignoreInactive, java.util.List<DetectResult> results)
Body
Fixture
in this World
.
If any part of a body is overlaping the AABB, the body and that respective fixture is added to the returned list.
This performs a static collision test of the world using the BroadphaseDetector
.
This may return bodies who only have sensor fixtures overlapping.
aabb
 the world space AABB
ignoreInactive
 true if inactive bodies should be ignoredresults
 the list of overlapping bodies and fixturespublic boolean detect(AABB aabb, boolean ignoreSensors, boolean ignoreInactive, java.util.List<DetectResult> results)
Body
in this World
.
If this method returns true, the results list will contain the bodies and fixtures that the convex overlaps.
aabb
 the world space AABB
ignoreSensors
 true if sensor fixtures should be ignoredignoreInactive
 true if inactive bodies should be ignoredresults
 the list of overlapping bodies and fixturespublic boolean detect(AABB aabb, Filter filter, boolean ignoreSensors, boolean ignoreInactive, java.util.List<DetectResult> results)
Body
in this World
.
If this method returns true, the results list will contain the bodies and fixtures that the convex overlaps.
aabb
 the world space AABB
filter
 the Filter
to use against the fixtures; can be nullignoreSensors
 true if sensor fixtures should be ignoredignoreInactive
 true if inactive bodies should be ignoredresults
 the list of overlapping bodies and fixturespublic boolean detect(Convex convex, java.util.List<DetectResult> results)
Convex
overlaps a body in the world.
If this method returns true, the results list will contain the bodies and fixtures that the convex overlaps.
Use the Body.isInContact(Body)
method instead if you want to test if two bodies
are colliding.
The returned results may include sensor fixutres.
Inactive bodies are ignored in this test.
The results from this test will not include Penetration
objects.
convex
 the convex shape in world coordinatesresults
 the list of overlapping bodies and fixturesdetect(Convex, boolean, List)
public boolean detect(Convex convex, boolean ignoreSensors, java.util.List<DetectResult> results)
Convex
overlaps a body in the world.
If this method returns true, the results list will contain the bodies and fixtures that the convex overlaps.
Use the Body.isInContact(Body)
method instead if you want to test if two bodies
are colliding.
Inactive bodies are ignored in this test.
The results from this test will not include Penetration
objects.
convex
 the convex shape in world coordinatesignoreSensors
 true if sensor fixtures should be ignoredresults
 the list of overlapping bodies and fixturesdetect(Convex, boolean, boolean, List)
public boolean detect(Convex convex, boolean ignoreSensors, boolean ignoreInactive, java.util.List<DetectResult> results)
Convex
overlaps a body in the world.
If this method returns true, the results list will contain the bodies and fixtures that the convex overlaps.
Use the Body.isInContact(Body)
method instead if you want to test if two bodies
are colliding.
The results from this test will not include Penetration
objects.
convex
 the convex shape in world coordinatesignoreSensors
 true if sensor fixtures should be ignoredignoreInactive
 true if inactive bodies should be ignoredresults
 the list of overlapping bodies and fixturesdetect(Convex, Transform, Filter, boolean, boolean, List)
public boolean detect(Convex convex, Filter filter, boolean ignoreSensors, boolean ignoreInactive, java.util.List<DetectResult> results)
Convex
overlaps a body in the world.
If this method returns true, the results list will contain the bodies and fixtures that the convex overlaps.
Use the Body.isInContact(Body)
method instead if you want to test if two bodies
are colliding.
The results from this test will not include Penetration
objects.
convex
 the convex shape in world coordinatesfilter
 the Filter
to use against the fixtures; can be nullignoreSensors
 true if sensor fixtures should be ignoredignoreInactive
 true if inactive bodies should be ignoredresults
 the list of overlapping bodies and fixturesdetect(Convex, Transform, Filter, boolean, boolean, boolean, List)
public boolean detect(Convex convex, Filter filter, boolean ignoreSensors, boolean ignoreInactive, boolean includeCollisionData, java.util.List<DetectResult> results)
Convex
overlaps a body in the world.
If this method returns true, the results list will contain the bodies and fixtures that the convex overlaps.
Use the Body.isInContact(Body)
method instead if you want to test if two bodies
are colliding.
Use the includeCollisionData
parameter to have the Penetration
object
filled in the DetectResult
s. Including this information will have a performance impact.
convex
 the convex shape in world coordinatesfilter
 the Filter
to use against the fixtures; can be nullignoreSensors
 true if sensor fixtures should be ignoredignoreInactive
 true if inactive bodies should be ignoredincludeCollisionData
 true if the overlap Penetration
should be returnedresults
 the list of overlapping bodies and fixturespublic boolean detect(Convex convex, Transform transform, java.util.List<DetectResult> results)
Convex
overlaps a body in the world.
If this method returns true, the results list will contain the bodies and fixtures that the convex overlaps.
Use the Body.isInContact(Body)
method instead if you want to test if two bodies
are colliding.
The returned results may include sensor fixutres.
Inactive bodies are ignored in this test.
The results from this test will not include Penetration
objects.
convex
 the convex shape in local coordinatestransform
 the convex shape's world transformresults
 the list of overlapping bodies and fixturesdetect(Convex, Transform, boolean, List)
public boolean detect(Convex convex, Transform transform, boolean ignoreSensors, java.util.List<DetectResult> results)
Convex
overlaps a body in the world.
If this method returns true, the results list will contain the bodies and fixtures that the convex overlaps.
Use the Body.isInContact(Body)
method instead if you want to test if two bodies
are colliding.
Inactive bodies are ignored in this test.
The results from this test will not include Penetration
objects.
convex
 the convex shape in local coordinatestransform
 the convex shape's world transformignoreSensors
 true if sensor fixtures should be ignoredresults
 the list of overlapping bodies and fixturesdetect(Convex, Transform, boolean, boolean, List)
public boolean detect(Convex convex, Transform transform, boolean ignoreSensors, boolean ignoreInactive, java.util.List<DetectResult> results)
Convex
overlaps a body in the world.
If this method returns true, the results list will contain the bodies and fixtures that the convex overlaps.
Use the Body.isInContact(Body)
method instead if you want to test if two bodies
are colliding.
The results from this test will not include Penetration
objects.
convex
 the convex shape in local coordinatestransform
 the convex shape's world transformignoreSensors
 true if sensor fixtures should be ignoredignoreInactive
 true if inactive bodies should be ignoredresults
 the list of overlapping bodies and fixturesdetect(Convex, Transform, Filter, boolean, boolean, List)
public boolean detect(Convex convex, Transform transform, Filter filter, boolean ignoreSensors, boolean ignoreInactive, java.util.List<DetectResult> results)
Convex
overlaps a body in the world.
If this method returns true, the results list will contain the bodies and fixtures that the convex overlaps.
Use the Body.isInContact(Body)
method instead if you want to test if two bodies
are colliding.
The results from this test will not include Penetration
objects.
convex
 the convex shape in local coordinatestransform
 the convex shape's world transformfilter
 the Filter
to use against the fixtures; can be nullignoreSensors
 true if sensor fixtures should be ignoredignoreInactive
 true if inactive bodies should be ignoredresults
 the list of overlapping bodies and fixturesdetect(Convex, Transform, Filter, boolean, boolean, boolean, List)
public boolean detect(Convex convex, Transform transform, Filter filter, boolean ignoreSensors, boolean ignoreInactive, boolean includeCollisionData, java.util.List<DetectResult> results)
Convex
overlaps a body in the world.
If this method returns true, the results list will contain the bodies and fixtures that the convex overlaps.
Use the Body.isInContact(Body)
method instead if you want to test if two bodies
are colliding.
Use the includeCollisionData
parameter to have the Penetration
object
filled in the DetectResult
s. Including this information will have a performance impact.
convex
 the convex shape in local coordinatestransform
 the convex shape's world transformfilter
 the Filter
to use against the fixtures; can be nullignoreSensors
 true if sensor fixtures should be ignoredignoreInactive
 true if inactive bodies should be ignoredincludeCollisionData
 true if the overlap Penetration
should be returnedresults
 the list of overlapping bodies and fixturespublic boolean detect(AABB aabb, Body body, boolean ignoreSensors, java.util.List<DetectResult> results)
AABB
overlaps the given body in the world.
If this method returns true, the results list will contain the bodies and fixtures that the AABB overlaps.
Use the Body.isInContact(Body)
method instead if you want to test if two bodies
are colliding.
public boolean detect(AABB aabb, Body body, Filter filter, boolean ignoreSensors, java.util.List<DetectResult> results)
AABB
overlaps the given body in the world.
If this method returns true, the results list will contain the bodies and fixtures that the AABB overlaps.
Use the Body.isInContact(Body)
method instead if you want to test if two bodies
are colliding.
aabb
 the AABB
in world coordinatesbody
 the Body
to test againstfilter
 the Filter
to use against the fixtures; can be nullignoreSensors
 true if sensor fixtures should be ignoredresults
 the list of overlapping bodies and fixturespublic boolean detect(Convex convex, Body body, boolean ignoreSensors, java.util.List<DetectResult> results)
Convex
overlaps the given body in the world.
If this method returns true, the results list will contain the bodies and fixtures that the convex overlaps.
Use the Body.isInContact(Body)
method instead if you want to test if two bodies
are colliding.
The results from this test will not include Penetration
objects.
public boolean detect(Convex convex, Body body, Filter filter, boolean ignoreSensors, java.util.List<DetectResult> results)
Convex
overlaps the given body in the world.
If this method returns true, the results list will contain the bodies and fixtures that the convex overlaps.
Use the Body.isInContact(Body)
method instead if you want to test if two bodies
are colliding.
The results from this test will not include Penetration
objects.
convex
 the Convex
in world coordinatesbody
 the Body
to test againstfilter
 the Filter
to use against the fixtures; can be nullignoreSensors
 true if sensor fixtures should be ignoredresults
 the list of overlapping bodies and fixturespublic boolean detect(Convex convex, Body body, Filter filter, boolean ignoreSensors, boolean includeCollisionData, java.util.List<DetectResult> results)
Convex
overlaps the given body in the world.
If this method returns true, the results list will contain the bodies and fixtures that the convex overlaps.
Use the Body.isInContact(Body)
method instead if you want to test if two bodies
are colliding.
Use the includeCollisionData
parameter to have the Penetration
object
filled in the DetectResult
s. Including this information negatively impacts performance.
convex
 the Convex
in world coordinatesbody
 the Body
to test againstfilter
 the Filter
to use against the fixtures; can be nullincludeCollisionData
 true if the overlap Penetration
should be returnedignoreSensors
 true if sensor fixtures should be ignoredresults
 the list of overlapping bodies and fixturespublic boolean detect(Convex convex, Transform transform, Body body, boolean ignoreSensors, java.util.List<DetectResult> results)
Convex
overlaps the given body in the world.
If this method returns true, the results list will contain the bodies and fixtures that the convex overlaps.
Use the Body.isInContact(Body)
method instead if you want to test if two bodies
are colliding.
The results from this test will not include Penetration
objects.
convex
 the Convex
in local coordinatestransform
 the convex shape's world Transform
body
 the Body
to test againstignoreSensors
 true if sensor fixtures should be ignoredresults
 the list of overlapping bodies and fixturespublic boolean detect(Convex convex, Transform transform, Body body, Filter filter, boolean ignoreSensors, java.util.List<DetectResult> results)
Convex
overlaps the given body in the world.
If this method returns true, the results list will contain the bodies and fixtures that the convex overlaps.
Use the Body.isInContact(Body)
method instead if you want to test if two bodies
are colliding.
The results from this test will not include Penetration
objects.
convex
 the Convex
in local coordinatestransform
 the convex shape's world Transform
body
 the Body
to test againstfilter
 the Filter
to use against the fixtures; can be nullignoreSensors
 true if sensor fixtures should be ignoredresults
 the list of overlapping bodies and fixturespublic boolean detect(Convex convex, Transform transform, Body body, Filter filter, boolean ignoreSensors, boolean includeCollisionData, java.util.List<DetectResult> results)
Convex
overlaps the given body in the world.
If this method returns true, the results list will contain the bodies and fixtures that the convex overlaps.
Use the Body.isInContact(Body)
method instead if you want to test if two bodies
are colliding.
Use the includeCollisionData
parameter to have the Penetration
object
filled in the DetectResult
s. Including this information negatively impacts performance.
convex
 the Convex
in local coordinatestransform
 the convex shape's world Transform
body
 the Body
to test againstfilter
 the Filter
to use against the fixtures; can be nullincludeCollisionData
 true if the overlap Penetration
should be returnedignoreSensors
 true if sensor fixtures should be ignoredresults
 the list of overlapping bodies and fixturespublic void shift(Vector2 shift)
NewPosition = OldPosition + shiftThis method is useful in situations where the world is very large causing very large numbers to be used in the computations. Shifting the coordinate system allows the computations to be localized and retain accuracy.
This method modifies the coordinates of every body and joint in the world.
Adding joints or bodies after this method is called should consider that everything has been shifted.
This method does NOT require a call to setUpdateRequired(boolean)
.
public void addBody(Body body)
body
 the Body
to addjava.lang.NullPointerException
 if body is nulljava.lang.IllegalArgumentException
 if body has already been added to this world or if its a member of another world instancepublic void addJoint(Joint joint)
joint
 the Joint
to addjava.lang.NullPointerException
 if joint is nulljava.lang.IllegalArgumentException
 if joint has already been added to this world or if its a member of another world instancepublic boolean containsBody(Body body)
body
 the Body
to test forpublic boolean containsJoint(Joint joint)
joint
 the Joint
to test forpublic boolean removeBody(int index)
Body
at the given index from this World
.
Use the removeBody(int, boolean)
method to enable implicit
destruction notification.
index
 the index of the body to remove.public boolean removeBody(int index, boolean notify)
Body
at the given index from this World
.
When a body is removed, joints and contacts may be implicitly destroyed.
Pass true to the notify parameter to be notified of the destruction of these objects
via the DestructionListener
s.
This method does not trigger ContactListener.end(ContactPoint)
events
for the contacts that are being removed.
index
 the index of the body to remove.notify
 true if implicit destruction should be notifiedpublic boolean removeBody(Body body)
Body
from this World
.
Use the removeBody(Body, boolean)
method to enable implicit
destruction notification.
body
 the Body
to remove.public boolean removeBody(Body body, boolean notify)
Body
from this World
.
When a body is removed, joints and contacts may be implicitly destroyed.
Pass true to the notify parameter to be notified of the destruction of these objects
via the DestructionListener
s.
This method does not trigger ContactListener.end(ContactPoint)
events
for the contacts that are being removed.
body
 the Body
to removenotify
 true if implicit destruction should be notifiedpublic boolean removeJoint(int index)
public boolean removeJoint(Joint joint)
public void removeAllBodiesAndJoints()
This method does not notify of destroyed objects.
removeAllBodiesAndJoints(boolean)
public void removeAllBodiesAndJoints(boolean notify)
notify
 true if destruction of joints and contacts should be notified of by the DestructionListener
public void removeAllBodies()
removeAllBodiesAndJoints()
method since all joints will be removed
when all bodies are removed anyway.
This method does not notify of the destroyed contacts, joints, etc.
removeAllBodies(boolean)
public void removeAllBodies(boolean notify)
removeAllBodiesAndJoints(boolean)
method since all joints will be removed
when all bodies are removed anyway.notify
 true if destruction of joints and contacts should be notified of by the DestructionListener
public void removeAllJoints()
removeAllJoints(boolean)
public void removeAllJoints(boolean notify)
notify
 true if destruction of joints should be notified of by the DestructionListener
public boolean isUpdateRequired()
This is typically set via user code when something about the simulation changes that can affect collision detection.
setUpdateRequired(boolean)
public void setUpdateRequired(boolean flag)
Set this flag to true if any of the following conditions have been met:
flag
 the flagpublic java.util.UUID getId()
public Settings getSettings()
Settings
public void setSettings(Settings settings)
settings
 the desired settingsjava.lang.NullPointerException
 if the given settings is nullpublic void setGravity(Vector2 gravity)
gravity
 the gravity in meters/second^{2}java.lang.NullPointerException
 if gravity is nullpublic Vector2 getGravity()
Vector2
the gravity in meters/second^{2}public void setBounds(Bounds bounds)
World
.bounds
 the bounds; can be nullpublic Bounds getBounds()
This will return null if no bounds were initially set
or if it was set to null via the setBounds(Bounds)
method.
Bounds
the bounds or nullpublic <T extends Listener> java.util.List<T> getListeners(java.lang.Class<T> clazz)
Returns an empty list if no listeners for the given type are found.
Returns null if clazz is null.
Example usage:
world.getListeners(ContactListener.class);
T
 the listener typeclazz
 the type of listener to getpublic <T extends Listener> void getListeners(java.lang.Class<T> clazz, java.util.List<T> listeners)
This method does not clear the given listeners list before adding the listeners.
If clazz or listeners is null, this method immediately returns.
Example usage:
List<ContactListener> list = ...; world.getListeners(ContactListener.class, list);
T
 the listener typeclazz
 the type of listener to getlisteners
 the list to add the listeners topublic void addListener(Listener listener)
listener
 the listenerjava.lang.NullPointerException
 if the given listener is nulljava.lang.IllegalArgumentException
 if the given listener has already been added to this worldpublic boolean containsListener(Listener listener)
listener
 the listenerpublic boolean removeListener(Listener listener)
listener
 the listener to removepublic int removeAllListeners()
public <T extends Listener> int removeAllListeners(java.lang.Class<T> clazz)
Returns zero if the given type is null or there are zero listeners attached.
Example usage:
world.removeAllListeners(ContactListener.class);
T
 the listener typeclazz
 the listener typepublic int getListenerCount()
public <T extends Listener> int getListenerCount(java.lang.Class<T> clazz)
Returns zero if the given class type is null.
Example usage:
world.getListenerCount(BoundsListener.class);
T
 the listener typeclazz
 the listener typepublic void setBroadphaseDetector(BroadphaseDetector<Body,BodyFixture> broadphaseDetector)
broadphaseDetector
 the broadphase collision detection algorithmjava.lang.NullPointerException
 if broadphaseDetector is nullpublic BroadphaseDetector<Body,BodyFixture> getBroadphaseDetector()
BroadphaseDetector
the broadphase collision detection algorithmpublic void setDetectBroadphaseFilter(BroadphaseFilter<Body,BodyFixture> filter)
BroadphaseFilter
used when detecting collisions for each time step.
This should always be an instance of a class that extends the DetectBroadphaseFilter
so that the standard filters are retained.
filter
 the filterpublic BroadphaseFilter<Body,BodyFixture> getDetectBroadphaseFilter()
BroadphaseFilter
used when detecting collisions for each time step.BroadphaseFilter
public void setNarrowphaseDetector(NarrowphaseDetector narrowphaseDetector)
narrowphaseDetector
 the narrowphase collision detection algorithmjava.lang.NullPointerException
 if narrowphaseDetector is nullpublic NarrowphaseDetector getNarrowphaseDetector()
NarrowphaseDetector
the narrowphase collision detection algorithmpublic void setManifoldSolver(ManifoldSolver manifoldSolver)
manifoldSolver
 the manifold solverjava.lang.NullPointerException
 if manifoldSolver is nullpublic ManifoldSolver getManifoldSolver()
ManifoldSolver
the manifold solverpublic void setTimeOfImpactDetector(TimeOfImpactDetector timeOfImpactDetector)
timeOfImpactDetector
 the time of impact detectorjava.lang.NullPointerException
 if timeOfImpactDetector is nullpublic TimeOfImpactDetector getTimeOfImpactDetector()
TimeOfImpactDetector
the time of impact detectorpublic void setRaycastDetector(RaycastDetector raycastDetector)
raycastDetector
 the raycast detectorjava.lang.NullPointerException
 if raycastDetector is nullpublic RaycastDetector getRaycastDetector()
RaycastDetector
the raycast detectorpublic CoefficientMixer getCoefficientMixer()
CoefficientMixer
.CoefficientMixer
setCoefficientMixer(CoefficientMixer)
public void setCoefficientMixer(CoefficientMixer coefficientMixer)
CoefficientMixer
.
A CoefficientMixer
is an implementation of mixing functions for various
coefficients used in contact solving. Common coefficients are restitution and
friction. Since each BodyFixture
can have it's own value for these
coefficients, the CoefficientMixer
is used to mathematically combine them
into one coefficient to be used in contact resolution.
CoefficientMixer.DEFAULT_MIXER
is the default.
coefficientMixer
 the coefficient mixerjava.lang.NullPointerException
 if coefficientMixer is nullCoefficientMixer
public void setContactManager(ContactManager contactManager)
ContactManager
.
A ContactManager
manages the contacts detected in the detect()
method
and performs notification of ContactListener
s. ContactManager
s can also contain
specialized logic for improving performance and simulation quality.
Changing the contact manager requires an update to be performed on the next update of this world and any cached information will be lost.
The default is the WarmStartingContactManager
.
contactManager
 the contact managerjava.lang.NullPointerException
 if contactManager is nullContactManager
public ContactManager getContactManager()
ContactManager
.ContactManager
setContactManager(ContactManager)
public void setContactConstraintSolver(ContactConstraintSolver constraintSolver)
ContactConstraintSolver
for this world.constraintSolver
 the contact constraint solverjava.lang.NullPointerException
 if contactManager is nullContactConstraintSolver
public ContactConstraintSolver getContactConstraintSolver()
ContactConstraintSolver
.ContactConstraintSolver
setContactConstraintSolver(ContactConstraintSolver)
public java.lang.Object getUserData()
DataContainer
getUserData
in interface DataContainer
public void setUserData(java.lang.Object userData)
DataContainer
setUserData
in interface DataContainer
userData
 the user datapublic int getBodyCount()
public Body getBody(int index)
Body
at the given index.index
 the indexBody
public java.util.List<Body> getBodies()
The returned list is backed by the internal list, therefore adding or removing bodies while
iterating through the returned list is not permitted. Use the getBodyIterator()
method instead.
Body
>getBodyIterator()
public java.util.Iterator<Body> getBodyIterator()
The returned iterator supports the remove
method.
Body
>public int getJointCount()
public Joint getJoint(int index)
Joint
at the given index.index
 the indexJoint
public java.util.List<Joint> getJoints()
The returned list is backed by the internal list, therefore adding or removing joints while
iterating through the returned list is not permitted. Use the getJointIterator()
method instead.
Joint
>getJointIterator()
public java.util.Iterator<Joint> getJointIterator()
The returned iterator supports the remove
method.
Joint
>public Step getStep()
Step
object used to advance
the simulation.
The returned object contains the step information (elapsed time) for the last and the previous time step.
Step
the current step objectpublic boolean isEmpty()
public double getAccumulatedTime()
This is the time that has elapsed since the last step of the engine.
This time is used and/or accumulated on each call of the
update(double)
and update(double, int)
methods.
This time is reduced by the step frequency for each step of the engine.
public void setAccumulatedTime(double elapsedTime)
A typical use case would be to throw away any remaining time
that the update(double)
or update(double, int)
methods didn't use:
boolean updated = world.update(elapsedTime); // the check if the world actually updated is crutial in this example if (updated) { // throw away any remaining time we didnt use world.setAccumulatedTime(0); }Or, in the case of reusing the same World object, you could use this method to clear any accumulated time.
If elapsedTime is less than zero, this method immediately returns.
elapsedTime
 the desired elapsed timegetAccumulatedTime()