- Object
-
- AbstractBroadphaseDetector<T>
-
- Type Parameters:
T
- the object type
- All Implemented Interfaces:
BroadphaseDetector<T>
,Shiftable
- Direct Known Subclasses:
BruteForceBroadphase
,DynamicAABBTree
,Sap
public abstract class AbstractBroadphaseDetector<T> extends Object implements BroadphaseDetector<T>
Abstract implementation of aBroadphaseDetector
.- Since:
- 1.0.0
- Version:
- 5.0.0
- Author:
- William Bittle
-
-
Field Summary
Fields Modifier and Type Field Description protected static double
AABB_REDUCTION_RATIO
A multiplier used when determining if we should update an AABB regardless if it fits within the existing AABBprotected AABBExpansionMethod<T>
aabbExpansionMethod
The AABB expansion methodprotected AABBProducer<T>
aabbProducer
The AABB producerprotected BroadphaseFilter<T>
broadphaseFilter
The broadphase filter to cull pairsprotected boolean
updateTrackingEnabled
True if update tracking is enabled-
Fields inherited from interface BroadphaseDetector
DEFAULT_INITIAL_CAPACITY
-
-
Constructor Summary
Constructors Constructor Description AbstractBroadphaseDetector(BroadphaseFilter<T> broadphaseFilter, AABBProducer<T> aabbProducer, AABBExpansionMethod<T> aabbExpansionMethod)
Minimal constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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 aabb)
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.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.boolean
isUpdateTrackingEnabled()
Returns true if this broad-phase is tracking updated items.List<T>
raycast(Ray ray, double length)
Performs a raycast over all the objects in this broad-phase and returns the items that intersect.void
setUpdateTrackingEnabled(boolean flag)
Sets the update tracking to the given flag.-
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface BroadphaseDetector
add, clear, clearUpdates, contains, detectIterator, detectIterator, getAABB, isUpdated, isUpdateTrackingSupported, optimize, raycastIterator, remove, setUpdated, size, update, update
-
-
-
-
Field Detail
-
AABB_REDUCTION_RATIO
protected static final double AABB_REDUCTION_RATIO
A multiplier used when determining if we should update an AABB regardless if it fits within the existing AABB- See Also:
- Constant Field Values
-
aabbProducer
protected final AABBProducer<T> aabbProducer
The AABB producer
-
aabbExpansionMethod
protected final AABBExpansionMethod<T> aabbExpansionMethod
The AABB expansion method
-
broadphaseFilter
protected final BroadphaseFilter<T> broadphaseFilter
The broadphase filter to cull pairs
-
updateTrackingEnabled
protected boolean updateTrackingEnabled
True if update tracking is enabled
-
-
Constructor Detail
-
AbstractBroadphaseDetector
public AbstractBroadphaseDetector(BroadphaseFilter<T> broadphaseFilter, AABBProducer<T> aabbProducer, AABBExpansionMethod<T> aabbExpansionMethod)
Minimal constructor.- Parameters:
broadphaseFilter
- the broadphase filteraabbProducer
- the AABB produceraabbExpansionMethod
- the AABB expansion method- Throws:
NullPointerException
- if broadphaseFilter, aabbProducer or aabbExpansionMethod are null
-
-
Method Detail
-
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
-
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
>
-
detect
public List<T> detect(AABB aabb)
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:
aabb
- theAABB
to test- Returns:
- List<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>
-
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
-
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()
-
-