- Object
-
- BroadphaseDetectorDecoratorAdapter<T>
-
- Type Parameters:
T
- the object type
- All Implemented Interfaces:
BroadphaseDetector<T>
,BroadphaseDetectorDecorator<T>
,Shiftable
- Direct Known Subclasses:
CollisionItemBroadphaseDetectorAdapter
public class BroadphaseDetectorDecoratorAdapter<T> extends Object implements BroadphaseDetectorDecorator<T>, BroadphaseDetector<T>
A default implementation of the theBroadphaseDetectorDecorator
interface.- Since:
- 4.1.0
- Version:
- 4.1.0
- Author:
- William Bittle
-
-
Field Summary
Fields Modifier and Type Field Description protected BroadphaseDetector<T>
detector
The wrapped detector-
Fields inherited from interface BroadphaseDetector
DEFAULT_INITIAL_CAPACITY
-
-
Constructor Summary
Constructors Constructor Description BroadphaseDetectorDecoratorAdapter(BroadphaseDetector<T> detector)
Minimal constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(T object)
Adds a new object to this broad-phase.void
clear()
Clear all the internal state of this broad-phase.void
clearUpdates()
Clears internal state that tracks what objects have been updated.boolean
contains(T object)
Returns true if the given object exists in this broad-phase.List<CollisionPair<T>>
detect()
Performs collision detection on all objects that have been added to thisBroadphaseDetector
and returns the list of potential collision pairs (i.e.List<CollisionPair<T>>
detect(boolean forceFullDetection)
Performs collision detection on all objects that have been added to thisBroadphaseDetector
and returns the list of potential collision pairs (i.e.List<T>
detect(AABB shape)
Performs a broad-phase collision test using the givenAABB
and returns the items that overlap.boolean
detect(Convex convex1, Transform transform1, Convex convex2, Transform transform2)
boolean
detect(T a, T b)
Returns true if this broad-phase detector considers the given objects to be in collision.Iterator<CollisionPair<T>>
detectIterator()
Performs collision detection on all objects that have been added to thisBroadphaseDetector
and returns an iterator of potential collision pairs (i.e.Iterator<CollisionPair<T>>
detectIterator(boolean forceFullDetection)
Performs collision detection on all objects that have been added to thisBroadphaseDetector
and returns an iterator of potential collision pairs (i.e.Iterator<T>
detectIterator(AABB shape)
Performs a broad-phase collision test using the givenAABB
and returns the items that overlap.AABB
getAABB(T object)
Returns the AABB for the given object.AABBExpansionMethod<T>
getAABBExpansionMethod()
Returns theAABBExpansionMethod
used by this broad-phase detector.AABBProducer<T>
getAABBProducer()
Returns theAABBProducer
used by this broad-phase detector.BroadphaseFilter<T>
getBroadphaseFilter()
Returns theBroadphaseFilter
used by this broad-phase detector.BroadphaseDetector<T>
getDecoratedBroadphaseDetector()
Returns the wrappedBroadphaseDetector
.boolean
isUpdated(T object)
Returns true if the given object is marked as updated in this broad-phase.boolean
isUpdateTrackingEnabled()
Returns true if this broad-phase is tracking updated items.boolean
isUpdateTrackingSupported()
Returns whether this particularBroadphaseDetector
supports update tracking.void
optimize()
Attempts to optimize the broad-phase based on the current state.List<T>
raycast(Ray ray, double length)
Performs a raycast over all the objects in this broad-phase and returns the items that intersect.Iterator<T>
raycastIterator(Ray ray, double length)
Performs a raycast over all the objects in the broad-phase and returns the items that intersect.boolean
remove(T object)
Removes the given object from this broad-phase.void
setUpdated(T object)
This method forces this broad-phase to include the given object in the updated list to ensure they are checked in the updated-only detection routine.void
setUpdateTrackingEnabled(boolean flag)
Sets the update tracking to the given flag.void
shift(Vector2 shift)
Translates the object to match the given coordinate shift.int
size()
Returns the number of objects managed in this broad-phase.void
update()
Updates all the currently stored objects AABBs based on their current state, theAABBProducer
, and theAABBExpansionMethod
.void
update(T object)
Updates the broad-phase representation of the given object.
-
-
-
Field Detail
-
detector
protected final BroadphaseDetector<T> detector
The wrapped detector
-
-
Constructor Detail
-
BroadphaseDetectorDecoratorAdapter
public BroadphaseDetectorDecoratorAdapter(BroadphaseDetector<T> detector)
Minimal constructor.- Parameters:
detector
- the detector to delegate to
-
-
Method Detail
-
getDecoratedBroadphaseDetector
public BroadphaseDetector<T> getDecoratedBroadphaseDetector()
Description copied from interface:BroadphaseDetectorDecorator
Returns the wrappedBroadphaseDetector
.- Specified by:
getDecoratedBroadphaseDetector
in interfaceBroadphaseDetectorDecorator<T>
- Returns:
BroadphaseDetector
-
shift
public void shift(Vector2 shift)
Description copied from interface:Shiftable
Translates the object to match the given coordinate shift.
-
add
public void add(T object)
Description copied from interface:BroadphaseDetector
Adds a new object to this broad-phase.If the given object has already been added, the object is updated (
BroadphaseDetector.update(Object)
).- Specified by:
add
in interfaceBroadphaseDetector<T>
- Parameters:
object
- the object to add
-
remove
public boolean remove(T object)
Description copied from interface:BroadphaseDetector
Removes the given object from this broad-phase.- Specified by:
remove
in interfaceBroadphaseDetector<T>
- Parameters:
object
- the object to remove- Returns:
- boolean true if the object was removed
-
update
public void update()
Description copied from interface:BroadphaseDetector
Updates all the currently stored objects AABBs based on their current state, theAABBProducer
, and theAABBExpansionMethod
.- Specified by:
update
in interfaceBroadphaseDetector<T>
-
update
public void update(T object)
Description copied from interface:BroadphaseDetector
Updates the broad-phase representation of the given object.This should be called when the object's location, rotation, or shape has changed.
- Specified by:
update
in interfaceBroadphaseDetector<T>
- Parameters:
object
- the object
-
setUpdated
public void setUpdated(T object)
Description copied from interface:BroadphaseDetector
This method forces this broad-phase to include the given object in the updated list to ensure they are checked in the updated-only detection routine.The
BroadphaseDetector.update(Object)
method will only mark an object as updated if it's fixtures have moved enough to change the internally stored AABB.- Specified by:
setUpdated
in interfaceBroadphaseDetector<T>
- Parameters:
object
- the object
-
isUpdated
public boolean isUpdated(T object)
Description copied from interface:BroadphaseDetector
Returns true if the given object is marked as updated in this broad-phase.If
BroadphaseDetector.isUpdateTrackingEnabled()
is false, this method will always return true.Returns false if the given object is not part of this broad-phase.
- Specified by:
isUpdated
in interfaceBroadphaseDetector<T>
- Parameters:
object
- the object- Returns:
- boolean
-
clearUpdates
public void clearUpdates()
Description copied from interface:BroadphaseDetector
Clears internal state that tracks what objects have been updated.Typically this method would be called from a pipeline after a broad-phase collision detection method has been called to clear the state before starting to track new updates.
- Specified by:
clearUpdates
in interfaceBroadphaseDetector<T>
-
getAABB
public AABB getAABB(T object)
Description copied from interface:BroadphaseDetector
Returns the AABB for the given object.NOTE: Some
BroadphaseDetector
s use modified (expanded for example) AABBs rather than tight fitting AABBs as a performance enhancement. This method returns the AABB used by this detector, and therefore, the modified AABB.NOTE: The
AABB
returned from this method should not be modified. Instead use theAABB.copy()
method to create a new instance to modify.If the given object does not exist in this
BroadphaseDetector
a new AABB is created based on the object's shape, theBroadphaseDetector.getAABBProducer()
andBroadphaseDetector.getAABBExpansionMethod()
.- Specified by:
getAABB
in interfaceBroadphaseDetector<T>
- Parameters:
object
- the object- Returns:
AABB
-
contains
public boolean contains(T object)
Description copied from interface:BroadphaseDetector
Returns true if the given object exists in this broad-phase.- Specified by:
contains
in interfaceBroadphaseDetector<T>
- Parameters:
object
- the object- Returns:
- boolean
-
clear
public void clear()
Description copied from interface:BroadphaseDetector
Clear all the internal state of this broad-phase.- Specified by:
clear
in interfaceBroadphaseDetector<T>
-
size
public int size()
Description copied from interface:BroadphaseDetector
Returns the number of objects managed in this broad-phase.- Specified by:
size
in interfaceBroadphaseDetector<T>
- Returns:
- int
-
detect
public List<CollisionPair<T>> detect()
Description copied from interface:BroadphaseDetector
Performs collision detection on all objects that have been added to thisBroadphaseDetector
and returns the list of potential collision pairs (i.e. those pairs whose AABBs overlap).The pairs returned from this method will depend on the value of the
BroadphaseDetector.isUpdateTrackingEnabled()
flag. When false, the returned list will report all pairs, every invocation. When true, the returned list will only contain pairs whose objects moved significantly enough to generate new AABBs. As a result, this mode would not report those pairs who ARE NOT overlapping, nor would it report those pairs who ARE overlapping, but the objects didn't move enough.- Specified by:
detect
in interfaceBroadphaseDetector<T>
- Returns:
- List<
BroadphasePair
>
-
detect
public List<CollisionPair<T>> detect(boolean forceFullDetection)
Description copied from interface:BroadphaseDetector
Performs collision detection on all objects that have been added to thisBroadphaseDetector
and returns the list of potential collision pairs (i.e. those pairs whose AABBs overlap).The pairs returned from this method will depend on the value of the
BroadphaseDetector.isUpdateTrackingEnabled()
flag. When false, the returned list will report all pairs, every invocation. When true, the returned list will only contain pairs whose objects moved significantly enough to generate new AABBs. As a result, this mode would not report those pairs who ARE NOT overlapping, nor would it report those pairs who ARE overlapping, but the objects didn't move enough.Use the forceFullDetection parameter to override the
BroadphaseDetector.isUpdateTrackingEnabled()
flag for this invocation.- Specified by:
detect
in interfaceBroadphaseDetector<T>
- Parameters:
forceFullDetection
- true if a full detection should be performed- Returns:
- List<
BroadphasePair
>
-
detectIterator
public Iterator<CollisionPair<T>> detectIterator()
Description copied from interface:BroadphaseDetector
Performs collision detection on all objects that have been added to thisBroadphaseDetector
and returns an iterator of potential collision pairs (i.e. those pairs whose AABBs overlap).The pairs returned from this method will depend on the value of the
BroadphaseDetector.isUpdateTrackingEnabled()
flag. When false, the returned iterator will report all pairs, every invocation. When true, the returned iterator will only contain pairs whose objects moved significantly enough to generate new AABBs. As a result, this mode would not report those pairs who ARE NOT overlapping, nor would it report those pairs who ARE overlapping, but the objects didn't move enough.NOTE: This method returns
CollisionPair
s that are mutable internally. If you need to store the pairs outside of the iteration, be sure to call theCopyable.copy()
method to create a copy of the pair data.- Specified by:
detectIterator
in interfaceBroadphaseDetector<T>
- Returns:
- Iterator<
CollisionPair
>
-
detectIterator
public Iterator<CollisionPair<T>> detectIterator(boolean forceFullDetection)
Description copied from interface:BroadphaseDetector
Performs collision detection on all objects that have been added to thisBroadphaseDetector
and returns an iterator of potential collision pairs (i.e. those pairs whose AABBs overlap).The pairs returned from this method will depend on the value of the
BroadphaseDetector.isUpdateTrackingEnabled()
flag. When false, the returned iterator will report all pairs, every invocation. When true, the returned iterator will only contain pairs whose objects moved significantly enough to generate new AABBs. As a result, this mode would not report those pairs who ARE NOT overlapping, nor would it report those pairs who ARE overlapping, but the objects didn't move enough.Use the forceFullDetection parameter to override this behavior for a single call.
NOTE: This method returns
CollisionPair
s that are mutable internally. If you need to store the pairs outside of the iteration, be sure to call theCopyable.copy()
method to create a copy of the pair data.- Specified by:
detectIterator
in interfaceBroadphaseDetector<T>
- Parameters:
forceFullDetection
- true if a full detection should be performed- Returns:
- Iterator<
CollisionPair
>
-
detect
public List<T> detect(AABB shape)
Description copied from interface:BroadphaseDetector
Performs a broad-phase collision test using the givenAABB
and returns the items that overlap.- Specified by:
detect
in interfaceBroadphaseDetector<T>
- Parameters:
shape
- theAABB
to test- Returns:
- List<T>
-
detectIterator
public Iterator<T> detectIterator(AABB shape)
Description copied from interface:BroadphaseDetector
Performs a broad-phase collision test using the givenAABB
and returns the items that overlap.- Specified by:
detectIterator
in interfaceBroadphaseDetector<T>
- Parameters:
shape
- theAABB
to test- Returns:
- Iterator<T>
-
raycast
public List<T> raycast(Ray ray, double length)
Description copied from interface:BroadphaseDetector
Performs a raycast over all the objects in this broad-phase and returns the items that intersect.- Specified by:
raycast
in interfaceBroadphaseDetector<T>
- Parameters:
ray
- theRay
length
- the length of the ray; 0.0 for infinite length- Returns:
- List<T>
-
raycastIterator
public Iterator<T> raycastIterator(Ray ray, double length)
Description copied from interface:BroadphaseDetector
Performs a raycast over all the objects in the broad-phase and returns the items that intersect.- Specified by:
raycastIterator
in interfaceBroadphaseDetector<T>
- Parameters:
ray
- theRay
length
- the length of the ray; 0.0 for infinite length- Returns:
- Iterator<T>
-
detect
public boolean detect(T a, T b)
Description copied from interface:BroadphaseDetector
Returns true if this broad-phase detector considers the given objects to be in collision.- Specified by:
detect
in interfaceBroadphaseDetector<T>
- Parameters:
a
- the first objectb
- the second object- Returns:
- boolean
-
detect
public boolean detect(Convex convex1, Transform transform1, Convex convex2, Transform transform2)
Description copied from interface:BroadphaseDetector
-
isUpdateTrackingSupported
public boolean isUpdateTrackingSupported()
Description copied from interface:BroadphaseDetector
Returns whether this particularBroadphaseDetector
supports update tracking.- Specified by:
isUpdateTrackingSupported
in interfaceBroadphaseDetector<T>
- Returns:
- boolean
-
isUpdateTrackingEnabled
public boolean isUpdateTrackingEnabled()
Description copied from interface:BroadphaseDetector
Returns true if this broad-phase is tracking updated items.Tracking updates to the broad-phase can have huge performance gains if the majority of objects are stationary or moving slowly enough.
- Specified by:
isUpdateTrackingEnabled
in interfaceBroadphaseDetector<T>
- Returns:
- boolean
-
setUpdateTrackingEnabled
public void setUpdateTrackingEnabled(boolean flag)
Description copied from interface:BroadphaseDetector
Sets the update tracking to the given flag.Tracking updates to the broad-phase can have huge performance gains if the majority of objects are stationary or moving slowly enough.
Disabling this feature will clear the set of tracked updates (the updates themselves are not cleared). In addition, when enabling this feature (after disabling it), the user is expected to re-update all items in the broad-phase manually to ensure the updates set is non-empty. Typically this will self heal in the next iteration though.
- Specified by:
setUpdateTrackingEnabled
in interfaceBroadphaseDetector<T>
- Parameters:
flag
- true to turn on update tracking- See Also:
BroadphaseDetector.isUpdateTrackingSupported()
-
getAABBProducer
public AABBProducer<T> getAABBProducer()
Description copied from interface:BroadphaseDetector
Returns theAABBProducer
used by this broad-phase detector.- Specified by:
getAABBProducer
in interfaceBroadphaseDetector<T>
- Returns:
AABBProducer
-
getAABBExpansionMethod
public AABBExpansionMethod<T> getAABBExpansionMethod()
Description copied from interface:BroadphaseDetector
Returns theAABBExpansionMethod
used by this broad-phase detector.- Specified by:
getAABBExpansionMethod
in interfaceBroadphaseDetector<T>
- Returns:
AABBExpansionMethod
-
getBroadphaseFilter
public BroadphaseFilter<T> getBroadphaseFilter()
Description copied from interface:BroadphaseDetector
Returns theBroadphaseFilter
used by this broad-phase detector.- Specified by:
getBroadphaseFilter
in interfaceBroadphaseDetector<T>
- Returns:
BroadphaseFilter
-
optimize
public void optimize()
Description copied from interface:BroadphaseDetector
Attempts to optimize the broad-phase based on the current state.This method could be very intensive so should only be called if there's a clear benefit.
- Specified by:
optimize
in interfaceBroadphaseDetector<T>
-
-