Class AbstractCollisionWorld<T extends CollisionBody<E>,E extends Fixture,V extends CollisionData<T,E>>
- Object
-
- AbstractCollisionWorld<T,E,V>
-
- Type Parameters:
T
- theCollisionBody
typeE
- theFixture
typeV
- theCollisionData
type
- All Implemented Interfaces:
DataContainer
,Shiftable
,CollisionWorld<T,E,V>
- Direct Known Subclasses:
AbstractPhysicsWorld
public abstract class AbstractCollisionWorld<T extends CollisionBody<E>,E extends Fixture,V extends CollisionData<T,E>> extends Object implements CollisionWorld<T,E,V>, Shiftable, DataContainer
Abstract implementation of theCollisionWorld
interface.Implements the basic wiring for a collision detection pipeline. Extenders are expected to implement the
processCollisions(Iterator)
andcreateCollisionData(CollisionPair)
methods. It's expected that extenders would fully enumerate the Iterator given in theprocessCollisions(Iterator)
method to ensure a detection cycle is fully completed.Extenders should call the
detect()
method to initiate the collision detection pipeline. Calling thedetect()
will call theprocessCollisions(Iterator)
method to perform additional processing on the collisions found.At a high-level this class handles the following pipeline activities:
- (out of) Bounds detection (optional)
- Broad-phase collision detection
- Narrow-phase collision detection
- Narrow-phase post-processing (ex.
Link
shapes) - Manifold (contact point) generation
NOTE: This class uses the
AbstractCollisionBody.setOwner(Object)
andAbstractCollisionBody.setFixtureModificationHandler(org.dyn4j.collision.FixtureModificationHandler)
methods to handle certain scenarios like fixture removal on a body or bodies added to more than one world. Callers should NOT use the methods.- Since:
- 4.0.0
- Version:
- 4.0.0
- Author:
- William Bittle
- See Also:
CollisionWorld
-
-
Field Summary
-
Fields inherited from interface CollisionWorld
DEFAULT_INITIAL_BODY_CAPACITY
-
-
Constructor Summary
Constructors Constructor Description AbstractCollisionWorld()
Default constructor.AbstractCollisionWorld(int initialBodyCapacity)
Optional constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addBody(T body)
Adds the givenCollisionBody
to thisCollisionWorld
.boolean
addBoundsListener(BoundsListener<T,E> listener)
Adds the givenBoundsListener
to this world.boolean
addCollisionListener(CollisionListener<T,E> listener)
Adds the givenCollisionListener
to this world.boolean
containsBody(T body)
Returns true if this world contains the given body.List<ConvexCastResult<T,E>>
convexCast(Convex convex, Transform transform, Vector2 deltaPosition, double deltaAngle, DetectFilter<T,E> filter)
Returns a list ofConvexCastResult
s containing all the body-fixtures that overlap with the givenConvex
over the given deltaPosition and deltaAngle using the current state of theBroadphaseDetector
.ConvexCastResult<T,E>
convexCastClosest(Convex convex, Transform transform, Vector2 deltaPosition, double deltaAngle, DetectFilter<T,E> filter)
Returns the closestConvexCastResult
that overlaps with the givenConvex
over the given deltaPosition and deltaAngle using the current state of theBroadphaseDetector
.ConvexCastResult<T,E>
convexCastClosest(Convex convex, Transform transform, Vector2 deltaPosition, double deltaAngle, T body, DetectFilter<T,E> filter)
Returns the closestConvexCastResult
that overlaps with the givenConvex
over the given deltaPosition and deltaAngle only testing against the givenCollisionBody
.Iterator<ConvexCastResult<T,E>>
convexCastIterator(Convex convex, Transform transform, Vector2 deltaPosition, double deltaAngle, DetectFilter<T,E> filter)
Returns an iterator ofConvexCastResult
s containing all the body-fixtures that overlap with the givenConvex
over the given deltaPosition and deltaAngle using the current state of theBroadphaseDetector
.List<DetectResult<T,E>>
detect(AABB aabb, DetectFilter<T,E> filter)
Returns a list ofDetectResult
s containing all the body-fixtures that overlap with the givenAABB
using the current state of theBroadphaseDetector
.List<DetectResult<T,E>>
detect(AABB aabb, T body, DetectFilter<T,E> filter)
Returns a list ofDetectResult
s containing all the body-fixtures that overlap with the givenAABB
using the current state of theBroadphaseDetector
, only testing against the givenCollisionBody
.List<ConvexDetectResult<T,E>>
detect(Convex convex, Transform transform, DetectFilter<T,E> filter)
Returns a list ofConvexDetectResult
s containing all the body-fixtures that overlap with the givenConvex
using the current state of theBroadphaseDetector
.List<ConvexDetectResult<T,E>>
detect(Convex convex, Transform transform, T body, DetectFilter<T,E> filter)
Returns a list ofConvexDetectResult
s containing all the body-fixtures that overlapped with the givenConvex
using the current state of theBroadphaseDetector
, only testing against the givenCollisionBody
.Iterator<DetectResult<T,E>>
detectIterator(AABB aabb, DetectFilter<T,E> filter)
Returns an iterator ofDetectResult
s containing all the body-fixtures that overlap with the givenAABB
using the current state of theBroadphaseDetector
.Iterator<DetectResult<T,E>>
detectIterator(AABB aabb, T body, DetectFilter<T,E> filter)
Returns an iterator ofDetectResult
s containing all the body-fixtures that overlap with the givenAABB
using the current state of theBroadphaseDetector
, only testing against the givenCollisionBody
.Iterator<ConvexDetectResult<T,E>>
detectIterator(Convex convex, Transform transform, DetectFilter<T,E> filter)
Returns an iterator ofConvexDetectResult
s containing all the body-fixtures that overlapped with the givenConvex
using the current state of theBroadphaseDetector
.Iterator<ConvexDetectResult<T,E>>
detectIterator(Convex convex, Transform transform, T body, DetectFilter<T,E> filter)
Returns an iterator ofConvexDetectResult
s containing all the body-fixtures that overlapped with the givenConvex
using the current state of theBroadphaseDetector
, only testing against the givenCollisionBody
.List<T>
getBodies()
Returns an unmodifiable list containing all the bodies in this world.T
getBody(int index)
Returns theCollisionBody
at the given index.int
getBodyCount()
Returns the number ofCollisionBody
s in thisCollisionWorld
.Iterator<T>
getBodyIterator()
Returns an iterator for iterating over the bodies in this world.Bounds
getBounds()
Returns the bounds of this world.List<BoundsListener<T,E>>
getBoundsListeners()
Returns an unmodifiable list of all the bounds listeners registered to this world.BroadphaseDetector<T,E>
getBroadphaseDetector()
Returns the broad-phase collision detection algorithm.BroadphaseFilter<T,E>
getBroadphaseFilter()
Returns theBroadphaseFilter
used when detecting collisions for each time step.V
getCollisionData(T body1, E fixture1, T body2, E fixture2)
Returns the collision data for the given body-fixture pairs.Iterator<V>
getCollisionDataIterator()
Returns an iterator that can be used to enumerate all the collisions in this world.List<CollisionListener<T,E>>
getCollisionListeners()
Returns an unmodifiable list of all the collision listeners registered to this world.ManifoldSolver
getManifoldSolver()
Returns the manifold solver.NarrowphaseDetector
getNarrowphaseDetector()
Returns the narrow-phase collision detection algorithm.NarrowphasePostProcessor
getNarrowphasePostProcessor()
Returns the narrow-phase post processing algorithm.RaycastDetector
getRaycastDetector()
Returns the raycast detector.TimeOfImpactDetector
getTimeOfImpactDetector()
Returns the time of impact detector.Object
getUserData()
Gets the custom user data.boolean
isEmpty()
Returns true if this world doesn't contain any bodies or joints.List<RaycastResult<T,E>>
raycast(Ray ray, double maxLength, DetectFilter<T,E> filter)
Returns a list ofRaycastResult
s containing all the body-fixtures that overlap with the givenRay
using the current state of theBroadphaseDetector
.List<RaycastResult<T,E>>
raycast(Ray ray, double maxLength, T body, DetectFilter<T,E> filter)
Returns a list ofRaycastResult
s containing all the body-fixtures that overlap with the givenRay
only testing against the givenCollisionBody
.RaycastResult<T,E>
raycastClosest(Ray ray, double maxLength, DetectFilter<T,E> filter)
Returns the closestRaycastResult
that overlaps with the givenRay
using the current state of theBroadphaseDetector
.RaycastResult<T,E>
raycastClosest(Ray ray, double maxLength, T body, DetectFilter<T,E> filter)
Returns the closestRaycastResult
that overlaps with the givenRay
only testing against the givenCollisionBody
.Iterator<RaycastResult<T,E>>
raycastIterator(Ray ray, double maxLength, DetectFilter<T,E> filter)
Returns an iterator ofRaycastResult
s containing all the body-fixtures that overlap with the givenRay
using the current state of theBroadphaseDetector
.Iterator<RaycastResult<T,E>>
raycastIterator(Ray ray, double maxLength, T body, DetectFilter<T,E> filter)
Returns an iterator ofRaycastResult
s containing all the body-fixtures that overlap with the givenRay
only testing against the givenCollisionBody
.void
removeAllBodies()
Removes all bodies from this world.void
removeAllBoundsListeners()
Removes all bounds listeners from this world.void
removeAllCollisionListeners()
Removes all collision listeners from this world.void
removeAllListeners()
Removes all listeners from this world.boolean
removeBody(int index)
Removes theCollisionBody
at the given index from thisCollisionWorld
.boolean
removeBody(T body)
Removes the givenCollisionBody
from thisCollisionWorld
.boolean
removeBoundsListener(BoundsListener<T,E> listener)
Removes the given bounds listener from this world and returns true if it was removed.boolean
removeCollisionListener(CollisionListener<T,E> listener)
Removes the given collision listener from this world and returns true if it was removed.void
setBounds(Bounds bounds)
Sets the bounds of thisCollisionWorld
.void
setBroadphaseDetector(BroadphaseDetector<T,E> broadphaseDetector)
Sets the broad-phase collision detection algorithm.void
setBroadphaseFilter(BroadphaseFilter<T,E> filter)
Sets theBroadphaseFilter
used when detecting collisions for each time step.void
setManifoldSolver(ManifoldSolver manifoldSolver)
Sets the manifold solver.void
setNarrowphaseDetector(NarrowphaseDetector narrowphaseDetector)
Sets the narrow-phase collision detection algorithm.void
setNarrowphasePostProcessor(NarrowphasePostProcessor narrowphasePostProcessor)
Sets the narrow-phase post processing algorithm.void
setRaycastDetector(RaycastDetector raycastDetector)
Sets the raycast detector.void
setTimeOfImpactDetector(TimeOfImpactDetector timeOfImpactDetector)
Sets the time of impact detector.void
setUserData(Object data)
Sets the custom user data to the given data.void
shift(Vector2 shift)
Translates the object to match the given coordinate shift.
-
-
-
Constructor Detail
-
AbstractCollisionWorld
public AbstractCollisionWorld()
Default constructor.Uses the
CollisionWorld.DEFAULT_INITIAL_BODY_CAPACITY
as the initial capacity.
-
AbstractCollisionWorld
public AbstractCollisionWorld(int initialBodyCapacity)
Optional constructor.- Parameters:
initialBodyCapacity
- the default initial body capacity
-
-
Method Detail
-
addBody
public void addBody(T body)
Description copied from interface:CollisionWorld
Adds the givenCollisionBody
to thisCollisionWorld
.- Specified by:
addBody
in interfaceCollisionWorld<T extends CollisionBody<E>,E extends Fixture,V extends CollisionData<T,E>>
- Parameters:
body
- theCollisionBody
to add
-
removeAllBodies
public void removeAllBodies()
Description copied from interface:CollisionWorld
Removes all bodies from this world.- Specified by:
removeAllBodies
in interfaceCollisionWorld<T extends CollisionBody<E>,E extends Fixture,V extends CollisionData<T,E>>
-
containsBody
public boolean containsBody(T body)
Description copied from interface:CollisionWorld
Returns true if this world contains the given body.- Specified by:
containsBody
in interfaceCollisionWorld<T extends CollisionBody<E>,E extends Fixture,V extends CollisionData<T,E>>
- Parameters:
body
- theCollisionBody
to test for- Returns:
- boolean true if the body is contained in this world
-
removeBody
public boolean removeBody(int index)
Description copied from interface:CollisionWorld
Removes theCollisionBody
at the given index from thisCollisionWorld
.- Specified by:
removeBody
in interfaceCollisionWorld<T extends CollisionBody<E>,E extends Fixture,V extends CollisionData<T,E>>
- Parameters:
index
- the index of the body to remove.- Returns:
- boolean true if the body was removed
-
removeBody
public boolean removeBody(T body)
Description copied from interface:CollisionWorld
Removes the givenCollisionBody
from thisCollisionWorld
.- Specified by:
removeBody
in interfaceCollisionWorld<T extends CollisionBody<E>,E extends Fixture,V extends CollisionData<T,E>>
- Parameters:
body
- theCollisionBody
to remove.- Returns:
- boolean true if the body was removed
-
getBodies
public List<T> getBodies()
Description copied from interface:CollisionWorld
Returns an unmodifiable list containing all the bodies in this world.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
CollisionWorld.getBodyIterator()
method instead.- Specified by:
getBodies
in interfaceCollisionWorld<T extends CollisionBody<E>,E extends Fixture,V extends CollisionData<T,E>>
- Returns:
- List<
CollisionBody
> - See Also:
CollisionWorld.getBodyIterator()
-
getBody
public T getBody(int index)
Description copied from interface:CollisionWorld
Returns theCollisionBody
at the given index.- Specified by:
getBody
in interfaceCollisionWorld<T extends CollisionBody<E>,E extends Fixture,V extends CollisionData<T,E>>
- Parameters:
index
- the index- Returns:
CollisionBody
-
getBodyCount
public int getBodyCount()
Description copied from interface:CollisionWorld
Returns the number ofCollisionBody
s in thisCollisionWorld
.- Specified by:
getBodyCount
in interfaceCollisionWorld<T extends CollisionBody<E>,E extends Fixture,V extends CollisionData<T,E>>
- Returns:
- int the number of bodies
-
isEmpty
public boolean isEmpty()
Description copied from interface:CollisionWorld
Returns true if this world doesn't contain any bodies or joints.- Specified by:
isEmpty
in interfaceCollisionWorld<T extends CollisionBody<E>,E extends Fixture,V extends CollisionData<T,E>>
- Returns:
- boolean
-
getBodyIterator
public Iterator<T> getBodyIterator()
Description copied from interface:CollisionWorld
Returns an iterator for iterating over the bodies in this world.The returned iterator supports the
remove
method.- Specified by:
getBodyIterator
in interfaceCollisionWorld<T extends CollisionBody<E>,E extends Fixture,V extends CollisionData<T,E>>
- Returns:
- Iterator<
CollisionBody
>
-
setBounds
public void setBounds(Bounds bounds)
Description copied from interface:CollisionWorld
Sets the bounds of thisCollisionWorld
.- Specified by:
setBounds
in interfaceCollisionWorld<T extends CollisionBody<E>,E extends Fixture,V extends CollisionData<T,E>>
- Parameters:
bounds
- the bounds; can be null
-
getBounds
public Bounds getBounds()
Description copied from interface:CollisionWorld
Returns the bounds of this world.This will return null if no bounds were initially set or if it was set to null via the
CollisionWorld.setBounds(Bounds)
method.- Specified by:
getBounds
in interfaceCollisionWorld<T extends CollisionBody<E>,E extends Fixture,V extends CollisionData<T,E>>
- Returns:
Bounds
the bounds or null
-
setBroadphaseDetector
public void setBroadphaseDetector(BroadphaseDetector<T,E> broadphaseDetector)
Description copied from interface:CollisionWorld
Sets the broad-phase collision detection algorithm.- Specified by:
setBroadphaseDetector
in interfaceCollisionWorld<T extends CollisionBody<E>,E extends Fixture,V extends CollisionData<T,E>>
- Parameters:
broadphaseDetector
- the broad-phase collision detection algorithm
-
getBroadphaseDetector
public BroadphaseDetector<T,E> getBroadphaseDetector()
Description copied from interface:CollisionWorld
Returns the broad-phase collision detection algorithm.- Specified by:
getBroadphaseDetector
in interfaceCollisionWorld<T extends CollisionBody<E>,E extends Fixture,V extends CollisionData<T,E>>
- Returns:
BroadphaseDetector
the broad-phase collision detection algorithm
-
setBroadphaseFilter
public void setBroadphaseFilter(BroadphaseFilter<T,E> filter)
Description copied from interface:CollisionWorld
Sets theBroadphaseFilter
used when detecting collisions for each time step.This should always be an instance of a class that extends the
PhysicsBodyBroadphaseFilter
so that the standard filters are retained.- Specified by:
setBroadphaseFilter
in interfaceCollisionWorld<T extends CollisionBody<E>,E extends Fixture,V extends CollisionData<T,E>>
- Parameters:
filter
- the filter
-
getBroadphaseFilter
public BroadphaseFilter<T,E> getBroadphaseFilter()
Description copied from interface:CollisionWorld
Returns theBroadphaseFilter
used when detecting collisions for each time step.- Specified by:
getBroadphaseFilter
in interfaceCollisionWorld<T extends CollisionBody<E>,E extends Fixture,V extends CollisionData<T,E>>
- Returns:
BroadphaseFilter
-
setNarrowphaseDetector
public void setNarrowphaseDetector(NarrowphaseDetector narrowphaseDetector)
Description copied from interface:CollisionWorld
Sets the narrow-phase collision detection algorithm.- Specified by:
setNarrowphaseDetector
in interfaceCollisionWorld<T extends CollisionBody<E>,E extends Fixture,V extends CollisionData<T,E>>
- Parameters:
narrowphaseDetector
- the narrow-phase collision detection algorithm
-
getNarrowphaseDetector
public NarrowphaseDetector getNarrowphaseDetector()
Description copied from interface:CollisionWorld
Returns the narrow-phase collision detection algorithm.- Specified by:
getNarrowphaseDetector
in interfaceCollisionWorld<T extends CollisionBody<E>,E extends Fixture,V extends CollisionData<T,E>>
- Returns:
NarrowphaseDetector
the narrow-phase collision detection algorithm
-
setNarrowphasePostProcessor
public void setNarrowphasePostProcessor(NarrowphasePostProcessor narrowphasePostProcessor)
Description copied from interface:CollisionWorld
Sets the narrow-phase post processing algorithm.- Specified by:
setNarrowphasePostProcessor
in interfaceCollisionWorld<T extends CollisionBody<E>,E extends Fixture,V extends CollisionData<T,E>>
- Parameters:
narrowphasePostProcessor
- the narrow-phase post processing algorithm
-
getNarrowphasePostProcessor
public NarrowphasePostProcessor getNarrowphasePostProcessor()
Description copied from interface:CollisionWorld
Returns the narrow-phase post processing algorithm.- Specified by:
getNarrowphasePostProcessor
in interfaceCollisionWorld<T extends CollisionBody<E>,E extends Fixture,V extends CollisionData<T,E>>
- Returns:
NarrowphasePostProcessor
the narrow-phase post processing algorithm
-
setManifoldSolver
public void setManifoldSolver(ManifoldSolver manifoldSolver)
Description copied from interface:CollisionWorld
Sets the manifold solver.- Specified by:
setManifoldSolver
in interfaceCollisionWorld<T extends CollisionBody<E>,E extends Fixture,V extends CollisionData<T,E>>
- Parameters:
manifoldSolver
- the manifold solver
-
getManifoldSolver
public ManifoldSolver getManifoldSolver()
Description copied from interface:CollisionWorld
Returns the manifold solver.- Specified by:
getManifoldSolver
in interfaceCollisionWorld<T extends CollisionBody<E>,E extends Fixture,V extends CollisionData<T,E>>
- Returns:
ManifoldSolver
the manifold solver
-
setRaycastDetector
public void setRaycastDetector(RaycastDetector raycastDetector)
Description copied from interface:CollisionWorld
Sets the raycast detector.- Specified by:
setRaycastDetector
in interfaceCollisionWorld<T extends CollisionBody<E>,E extends Fixture,V extends CollisionData<T,E>>
- Parameters:
raycastDetector
- the raycast detector
-
getRaycastDetector
public RaycastDetector getRaycastDetector()
Description copied from interface:CollisionWorld
Returns the raycast detector.- Specified by:
getRaycastDetector
in interfaceCollisionWorld<T extends CollisionBody<E>,E extends Fixture,V extends CollisionData<T,E>>
- Returns:
RaycastDetector
the raycast detector
-
setTimeOfImpactDetector
public void setTimeOfImpactDetector(TimeOfImpactDetector timeOfImpactDetector)
Description copied from interface:CollisionWorld
Sets the time of impact detector.- Specified by:
setTimeOfImpactDetector
in interfaceCollisionWorld<T extends CollisionBody<E>,E extends Fixture,V extends CollisionData<T,E>>
- Parameters:
timeOfImpactDetector
- the time of impact detector
-
getTimeOfImpactDetector
public TimeOfImpactDetector getTimeOfImpactDetector()
Description copied from interface:CollisionWorld
Returns the time of impact detector.- Specified by:
getTimeOfImpactDetector
in interfaceCollisionWorld<T extends CollisionBody<E>,E extends Fixture,V extends CollisionData<T,E>>
- Returns:
TimeOfImpactDetector
the time of impact detector
-
shift
public void shift(Vector2 shift)
Description copied from interface:Shiftable
Translates the object to match the given coordinate shift.
-
getCollisionDataIterator
public Iterator<V> getCollisionDataIterator()
Description copied from interface:CollisionWorld
Returns an iterator that can be used to enumerate all the collisions in this world.This returns the collision data for any pair that was detected in the broadphase. Use the
CollisionData.isBroadphaseCollision()
,CollisionData.isManifoldCollision()
, etc. methods to inspect the type of collision or the details about the collision.NOTE: This iterator does NOT support removal.
- Specified by:
getCollisionDataIterator
in interfaceCollisionWorld<T extends CollisionBody<E>,E extends Fixture,V extends CollisionData<T,E>>
- Returns:
- Iterator<V>
-
getCollisionData
public V getCollisionData(T body1, E fixture1, T body2, E fixture2)
Description copied from interface:CollisionWorld
Returns the collision data for the given body-fixture pairs.This returns the collision data for any pair that was detected in the broadphase. Use the
CollisionData.isBroadphaseCollision()
,CollisionData.isManifoldCollision()
, etc. methods to inspect the type of collision or the details about the collision.Returns null if the body-fixtures are not colliding or if either no longer exist in the world.
- Specified by:
getCollisionData
in interfaceCollisionWorld<T extends CollisionBody<E>,E extends Fixture,V extends CollisionData<T,E>>
- Parameters:
body1
- the first bodyfixture1
- the first body's fixturebody2
- the second bodyfixture2
- the second body's fixture- Returns:
- V
-
getBoundsListeners
public List<BoundsListener<T,E>> getBoundsListeners()
Description copied from interface:CollisionWorld
Returns an unmodifiable list of all the bounds listeners registered to this world.- Specified by:
getBoundsListeners
in interfaceCollisionWorld<T extends CollisionBody<E>,E extends Fixture,V extends CollisionData<T,E>>
- Returns:
- List<
BoundsListener
>
-
getCollisionListeners
public List<CollisionListener<T,E>> getCollisionListeners()
Description copied from interface:CollisionWorld
Returns an unmodifiable list of all the collision listeners registered to this world.- Specified by:
getCollisionListeners
in interfaceCollisionWorld<T extends CollisionBody<E>,E extends Fixture,V extends CollisionData<T,E>>
- Returns:
- List<
CollisionListener
>
-
removeAllListeners
public void removeAllListeners()
Description copied from interface:CollisionWorld
Removes all listeners from this world.- Specified by:
removeAllListeners
in interfaceCollisionWorld<T extends CollisionBody<E>,E extends Fixture,V extends CollisionData<T,E>>
-
removeAllBoundsListeners
public void removeAllBoundsListeners()
Description copied from interface:CollisionWorld
Removes all bounds listeners from this world.- Specified by:
removeAllBoundsListeners
in interfaceCollisionWorld<T extends CollisionBody<E>,E extends Fixture,V extends CollisionData<T,E>>
-
removeAllCollisionListeners
public void removeAllCollisionListeners()
Description copied from interface:CollisionWorld
Removes all collision listeners from this world.- Specified by:
removeAllCollisionListeners
in interfaceCollisionWorld<T extends CollisionBody<E>,E extends Fixture,V extends CollisionData<T,E>>
-
removeBoundsListener
public boolean removeBoundsListener(BoundsListener<T,E> listener)
Description copied from interface:CollisionWorld
Removes the given bounds listener from this world and returns true if it was removed.This method will return false if the listener was not found in this world.
- Specified by:
removeBoundsListener
in interfaceCollisionWorld<T extends CollisionBody<E>,E extends Fixture,V extends CollisionData<T,E>>
- Parameters:
listener
- the listener- Returns:
- boolean
-
removeCollisionListener
public boolean removeCollisionListener(CollisionListener<T,E> listener)
Description copied from interface:CollisionWorld
Removes the given collision listener from this world and returns true if it was removed.This method will return false if the listener was not found in this world.
- Specified by:
removeCollisionListener
in interfaceCollisionWorld<T extends CollisionBody<E>,E extends Fixture,V extends CollisionData<T,E>>
- Parameters:
listener
- the listener- Returns:
- boolean
-
addBoundsListener
public boolean addBoundsListener(BoundsListener<T,E> listener)
Description copied from interface:CollisionWorld
Adds the givenBoundsListener
to this world.NOTE: No effort is made to prevent duplicate listeners from being added.
- Specified by:
addBoundsListener
in interfaceCollisionWorld<T extends CollisionBody<E>,E extends Fixture,V extends CollisionData<T,E>>
- Parameters:
listener
- the listener to add- Returns:
- boolean
-
addCollisionListener
public boolean addCollisionListener(CollisionListener<T,E> listener)
Description copied from interface:CollisionWorld
Adds the givenCollisionListener
to this world.NOTE: No effort is made to prevent duplicate listeners from being added.
- Specified by:
addCollisionListener
in interfaceCollisionWorld<T extends CollisionBody<E>,E extends Fixture,V extends CollisionData<T,E>>
- Parameters:
listener
- the listener to add- Returns:
- boolean
-
getUserData
public Object getUserData()
Description copied from interface:DataContainer
Gets the custom user data.- Specified by:
getUserData
in interfaceDataContainer
- Returns:
- Object will return null if not set
-
setUserData
public void setUserData(Object data)
Description copied from interface:DataContainer
Sets the custom user data to the given data.- Specified by:
setUserData
in interfaceDataContainer
- Parameters:
data
- the user data
-
detect
public List<DetectResult<T,E>> detect(AABB aabb, DetectFilter<T,E> filter)
Description copied from interface:CollisionWorld
Returns a list ofDetectResult
s containing all the body-fixtures that overlap with the givenAABB
using the current state of theBroadphaseDetector
.- Specified by:
detect
in interfaceCollisionWorld<T extends CollisionBody<E>,E extends Fixture,V extends CollisionData<T,E>>
- Parameters:
aabb
- the aabbfilter
- the filter; can be null- Returns:
- List<
DetectResult
>
-
detectIterator
public Iterator<DetectResult<T,E>> detectIterator(AABB aabb, DetectFilter<T,E> filter)
Description copied from interface:CollisionWorld
Returns an iterator ofDetectResult
s containing all the body-fixtures that overlap with the givenAABB
using the current state of theBroadphaseDetector
.NOTE: The returned
DetectResult
s are reused internally. You should call theDetectResult.copy()
method to create a copy of the result if you need to keep it outside of the iteration.- Specified by:
detectIterator
in interfaceCollisionWorld<T extends CollisionBody<E>,E extends Fixture,V extends CollisionData<T,E>>
- Parameters:
aabb
- the aabbfilter
- the filter; can be null- Returns:
- Iterator<
DetectResult
>
-
detect
public List<DetectResult<T,E>> detect(AABB aabb, T body, DetectFilter<T,E> filter)
Description copied from interface:CollisionWorld
Returns a list ofDetectResult
s containing all the body-fixtures that overlap with the givenAABB
using the current state of theBroadphaseDetector
, only testing against the givenCollisionBody
.- Specified by:
detect
in interfaceCollisionWorld<T extends CollisionBody<E>,E extends Fixture,V extends CollisionData<T,E>>
- Parameters:
aabb
- the aabbbody
- the bodyfilter
- the filter; can be null- Returns:
- List<
DetectResult
>
-
detectIterator
public Iterator<DetectResult<T,E>> detectIterator(AABB aabb, T body, DetectFilter<T,E> filter)
Description copied from interface:CollisionWorld
Returns an iterator ofDetectResult
s containing all the body-fixtures that overlap with the givenAABB
using the current state of theBroadphaseDetector
, only testing against the givenCollisionBody
.NOTE: The returned
DetectResult
s are reused internally. You should call theDetectResult.copy()
method to create a copy of the result if you need to keep it outside of the iteration.- Specified by:
detectIterator
in interfaceCollisionWorld<T extends CollisionBody<E>,E extends Fixture,V extends CollisionData<T,E>>
- Parameters:
aabb
- the aabbbody
- the bodyfilter
- the filter; can be null- Returns:
- Iterator<
DetectResult
>
-
detect
public List<ConvexDetectResult<T,E>> detect(Convex convex, Transform transform, DetectFilter<T,E> filter)
Description copied from interface:CollisionWorld
Returns a list ofConvexDetectResult
s containing all the body-fixtures that overlap with the givenConvex
using the current state of theBroadphaseDetector
.- Specified by:
detect
in interfaceCollisionWorld<T extends CollisionBody<E>,E extends Fixture,V extends CollisionData<T,E>>
- Parameters:
convex
- the convextransform
- the transformfilter
- the filter; can be null- Returns:
- List<
ConvexDetectResult
>
-
detectIterator
public Iterator<ConvexDetectResult<T,E>> detectIterator(Convex convex, Transform transform, DetectFilter<T,E> filter)
Description copied from interface:CollisionWorld
Returns an iterator ofConvexDetectResult
s containing all the body-fixtures that overlapped with the givenConvex
using the current state of theBroadphaseDetector
.- Specified by:
detectIterator
in interfaceCollisionWorld<T extends CollisionBody<E>,E extends Fixture,V extends CollisionData<T,E>>
- Parameters:
convex
- the convextransform
- the transformfilter
- the filter; can be null- Returns:
- Iterator<
ConvexDetectResult
>
-
detect
public List<ConvexDetectResult<T,E>> detect(Convex convex, Transform transform, T body, DetectFilter<T,E> filter)
Description copied from interface:CollisionWorld
Returns a list ofConvexDetectResult
s containing all the body-fixtures that overlapped with the givenConvex
using the current state of theBroadphaseDetector
, only testing against the givenCollisionBody
.- Specified by:
detect
in interfaceCollisionWorld<T extends CollisionBody<E>,E extends Fixture,V extends CollisionData<T,E>>
- Parameters:
convex
- the convextransform
- the transformbody
- the bodyfilter
- the filter; can be null- Returns:
- List<
ConvexDetectResult
>
-
detectIterator
public Iterator<ConvexDetectResult<T,E>> detectIterator(Convex convex, Transform transform, T body, DetectFilter<T,E> filter)
Description copied from interface:CollisionWorld
Returns an iterator ofConvexDetectResult
s containing all the body-fixtures that overlapped with the givenConvex
using the current state of theBroadphaseDetector
, only testing against the givenCollisionBody
.- Specified by:
detectIterator
in interfaceCollisionWorld<T extends CollisionBody<E>,E extends Fixture,V extends CollisionData<T,E>>
- Parameters:
convex
- the convextransform
- the transformbody
- the bodyfilter
- the filter; can be null- Returns:
- Iterator<
ConvexDetectResult
>
-
raycast
public List<RaycastResult<T,E>> raycast(Ray ray, double maxLength, DetectFilter<T,E> filter)
Description copied from interface:CollisionWorld
Returns a list ofRaycastResult
s containing all the body-fixtures that overlap with the givenRay
using the current state of theBroadphaseDetector
.If the ray begins inside a fixture, that fixture will not be included in the results.
- Specified by:
raycast
in interfaceCollisionWorld<T extends CollisionBody<E>,E extends Fixture,V extends CollisionData<T,E>>
- Parameters:
ray
- the raymaxLength
- the max length of the ray; any value less than or equal to zero represents infinite lengthfilter
- the filter; can be null- Returns:
- List<
RaycastResult
>
-
raycastIterator
public Iterator<RaycastResult<T,E>> raycastIterator(Ray ray, double maxLength, DetectFilter<T,E> filter)
Description copied from interface:CollisionWorld
Returns an iterator ofRaycastResult
s containing all the body-fixtures that overlap with the givenRay
using the current state of theBroadphaseDetector
.If the ray begins inside a fixture, that fixture will not be included in the results.
- Specified by:
raycastIterator
in interfaceCollisionWorld<T extends CollisionBody<E>,E extends Fixture,V extends CollisionData<T,E>>
- Parameters:
ray
- the raymaxLength
- the max length of the ray; any value less than or equal to zero represents infinite lengthfilter
- the filter; can be null- Returns:
- Iterator<
RaycastResult
>
-
raycast
public List<RaycastResult<T,E>> raycast(Ray ray, double maxLength, T body, DetectFilter<T,E> filter)
Description copied from interface:CollisionWorld
Returns a list ofRaycastResult
s containing all the body-fixtures that overlap with the givenRay
only testing against the givenCollisionBody
.This method does not use the current state of the
BroadphaseDetector
and instead tests the given body's fixtures directly.If the ray begins inside a fixture, that fixture will not be included in the results.
- Specified by:
raycast
in interfaceCollisionWorld<T extends CollisionBody<E>,E extends Fixture,V extends CollisionData<T,E>>
- Parameters:
ray
- the raymaxLength
- the max length of the ray; any value less than or equal to zero represents infinite lengthbody
- the bodyfilter
- the filter; can be null- Returns:
- List<
RaycastResult
>
-
raycastIterator
public Iterator<RaycastResult<T,E>> raycastIterator(Ray ray, double maxLength, T body, DetectFilter<T,E> filter)
Description copied from interface:CollisionWorld
Returns an iterator ofRaycastResult
s containing all the body-fixtures that overlap with the givenRay
only testing against the givenCollisionBody
.This method does not use the current state of the
BroadphaseDetector
and instead tests the given body's fixtures directly.If the ray begins inside a fixture, that fixture will not be included in the results.
- Specified by:
raycastIterator
in interfaceCollisionWorld<T extends CollisionBody<E>,E extends Fixture,V extends CollisionData<T,E>>
- Parameters:
ray
- the raymaxLength
- the max length of the ray; any value less than or equal to zero represents infinite lengthbody
- the bodyfilter
- the filter; can be null- Returns:
- Iterator<
RaycastResult
>
-
raycastClosest
public RaycastResult<T,E> raycastClosest(Ray ray, double maxLength, DetectFilter<T,E> filter)
Description copied from interface:CollisionWorld
Returns the closestRaycastResult
that overlaps with the givenRay
using the current state of theBroadphaseDetector
.The closest is defined as the closest intersection of the ray and a fixture to the ray's start point.
If the ray begins inside a fixture, that fixture will not be included in the results.
- Specified by:
raycastClosest
in interfaceCollisionWorld<T extends CollisionBody<E>,E extends Fixture,V extends CollisionData<T,E>>
- Parameters:
ray
- the raymaxLength
- the max length of the ray; any value less than or equal to zero represents infinite lengthfilter
- the filter; can be null- Returns:
RaycastResult
-
raycastClosest
public RaycastResult<T,E> raycastClosest(Ray ray, double maxLength, T body, DetectFilter<T,E> filter)
Description copied from interface:CollisionWorld
Returns the closestRaycastResult
that overlaps with the givenRay
only testing against the givenCollisionBody
.The closest is defined as the closest intersection of the ray and a fixture to the ray's start point.
This method does not use the current state of the
BroadphaseDetector
and instead tests the given body's fixtures directly.If the ray begins inside a fixture, that fixture will not be included in the results.
- Specified by:
raycastClosest
in interfaceCollisionWorld<T extends CollisionBody<E>,E extends Fixture,V extends CollisionData<T,E>>
- Parameters:
ray
- the raymaxLength
- the max length of the ray; any value less than or equal to zero represents infinite lengthbody
- the bodyfilter
- the filter; can be null- Returns:
RaycastResult
-
convexCastClosest
public ConvexCastResult<T,E> convexCastClosest(Convex convex, Transform transform, Vector2 deltaPosition, double deltaAngle, T body, DetectFilter<T,E> filter)
Description copied from interface:CollisionWorld
Returns the closestConvexCastResult
that overlaps with the givenConvex
over the given deltaPosition and deltaAngle only testing against the givenCollisionBody
.The closest is defined as the closest intersection from the initial position/rotation of the given convex.
The deltaPosition and deltaAngle parameters define the cast of the convex. Imagine moving the given convex from it's current transform position to the given position and rotating the given convex from it's current transform rotation to the given rotation. This method detects if there was any collisions between these start and end states.
This method assumes linear motion, meaning that the direction of motion is in the same direction for the start and end states as defined by the deltaPosition parameter.
- Specified by:
convexCastClosest
in interfaceCollisionWorld<T extends CollisionBody<E>,E extends Fixture,V extends CollisionData<T,E>>
- Parameters:
convex
- the convextransform
- the transformdeltaPosition
- the change in position of the convexdeltaAngle
- the change in rotation of the convexbody
- the bodyfilter
- the filter; can be null- Returns:
ConvexCastResult
-
convexCast
public List<ConvexCastResult<T,E>> convexCast(Convex convex, Transform transform, Vector2 deltaPosition, double deltaAngle, DetectFilter<T,E> filter)
Description copied from interface:CollisionWorld
Returns a list ofConvexCastResult
s containing all the body-fixtures that overlap with the givenConvex
over the given deltaPosition and deltaAngle using the current state of theBroadphaseDetector
.The deltaPosition and deltaAngle parameters define the cast of the convex. Imagine moving the given convex from it's current transform position to the given position and rotating the given convex from it's current transform rotation to the given rotation. This method detects if there was any collisions between these start and end states.
This method assumes linear motion, meaning that the direction of motion is in the same direction for the start and end states as defined by the deltaPosition parameter.
- Specified by:
convexCast
in interfaceCollisionWorld<T extends CollisionBody<E>,E extends Fixture,V extends CollisionData<T,E>>
- Parameters:
convex
- the convextransform
- the transformdeltaPosition
- the change in position of the convexdeltaAngle
- the change in rotation of the convexfilter
- the filter; can be null- Returns:
- List<
ConvexCastResult
>
-
convexCastClosest
public ConvexCastResult<T,E> convexCastClosest(Convex convex, Transform transform, Vector2 deltaPosition, double deltaAngle, DetectFilter<T,E> filter)
Description copied from interface:CollisionWorld
Returns the closestConvexCastResult
that overlaps with the givenConvex
over the given deltaPosition and deltaAngle using the current state of theBroadphaseDetector
.The closest is defined as the closest intersection from the initial position/rotation of the given convex.
The deltaPosition and deltaAngle parameters define the cast of the convex. Imagine moving the given convex from it's current transform position to the given position and rotating the given convex from it's current transform rotation to the given rotation. This method detects if there was any collisions between these start and end states.
This method assumes linear motion, meaning that the direction of motion is in the same direction for the start and end states as defined by the deltaPosition parameter.
- Specified by:
convexCastClosest
in interfaceCollisionWorld<T extends CollisionBody<E>,E extends Fixture,V extends CollisionData<T,E>>
- Parameters:
convex
- the convextransform
- the transformdeltaPosition
- the change in position of the convexdeltaAngle
- the change in rotation of the convexfilter
- the filter; can be null- Returns:
ConvexCastResult
-
convexCastIterator
public Iterator<ConvexCastResult<T,E>> convexCastIterator(Convex convex, Transform transform, Vector2 deltaPosition, double deltaAngle, DetectFilter<T,E> filter)
Description copied from interface:CollisionWorld
Returns an iterator ofConvexCastResult
s containing all the body-fixtures that overlap with the givenConvex
over the given deltaPosition and deltaAngle using the current state of theBroadphaseDetector
.The deltaPosition and deltaAngle parameters define the cast of the convex. Imagine moving the given convex from it's current transform position to the given position and rotating the given convex from it's current transform rotation to the given rotation. This method detects if there was any collisions between these start and end states.
This method assumes linear motion, meaning that the direction of motion is in the same direction for the start and end states as defined by the deltaPosition parameter.
- Specified by:
convexCastIterator
in interfaceCollisionWorld<T extends CollisionBody<E>,E extends Fixture,V extends CollisionData<T,E>>
- Parameters:
convex
- the convextransform
- the transformdeltaPosition
- the change in position of the convexdeltaAngle
- the change in rotation of the convexfilter
- the filter; can be null- Returns:
- Iterator<
ConvexCastResult
>
-
-