Class AbstractBroadphaseDetector<T extends CollisionBody<E>,E extends Fixture>
- Object
-
- AbstractBroadphaseDetector<T,E>
-
- Type Parameters:
T
- theCollisionBody
typeE
- theFixture
type
- All Implemented Interfaces:
BroadphaseDetector<T,E>
,Shiftable
- Direct Known Subclasses:
BruteForceBroadphase
,DynamicAABBTree
,LazyAABBTree
,Sap
public abstract class AbstractBroadphaseDetector<T extends CollisionBody<E>,E extends Fixture> extends Object implements BroadphaseDetector<T,E>
Abstract implementation of aBroadphaseDetector
.- Since:
- 1.0.0
- Version:
- 4.0.0
- Author:
- William Bittle
-
-
Field Summary
-
Fields inherited from interface BroadphaseDetector
DEFAULT_AABB_EXPANSION, DEFAULT_INITIAL_CAPACITY
-
-
Constructor Summary
Constructors Constructor Description AbstractBroadphaseDetector()
Default constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
add(T body)
Adds a newCollisionBody
to the broad-phase.boolean
contains(T body)
Returns true if all theFixture
s on the givenCollisionBody
have been added to this broad-phase.List<CollisionPair<T,E>>
detect()
Performs collision detection on allCollisionBody
Fixture
s that have been added to thisBroadphaseDetector
and returns the list of potential pairs.List<CollisionPair<T,E>>
detect(boolean forceFullDetection)
Performs collision detection onCollisionBody
Fixture
s that have been added to thisBroadphaseDetector
and returns the list of potential pairs.List<CollisionPair<T,E>>
detect(BroadphaseFilter<T,E> filter)
Deprecated.List<CollisionItem<T,E>>
detect(AABB aabb)
Performs a broad-phase collision test using the givenAABB
and returns the items that overlap.List<CollisionItem<T,E>>
detect(AABB aabb, BroadphaseFilter<T,E> filter)
Deprecated.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 bodies to be in collision.AABB
getAABB(T body)
Returns the AABB for the givenCollisionBody
.AABB
getAABB(T body, E fixture)
Returns the AABB for the givenCollisionBody
Fixture
.double
getAABBExpansion()
Returns theAABB
expansion value used to improve performance of broad-phase updates.boolean
isAABBExpansionSupported()
Returns whether this particularBroadphaseDetector
supports expanding AABBs.boolean
isUpdated(T body)
Returns true if any of theFixture
s on the givenCollisionBody
are included in the updated list.boolean
isUpdateTrackingEnabled()
Returns true if this broadphase is tracking updated items.boolean
isUpdateTrackingSupported()
Returns whether this particularBroadphaseDetector
supports update tracking.List<CollisionItem<T,E>>
raycast(Ray ray, double length)
Performs a raycast over all the bodies in the broad-phase and returns the items that intersect.List<CollisionItem<T,E>>
raycast(Ray ray, double length, BroadphaseFilter<T,E> filter)
Deprecated.void
remove(T body)
Removes the givenCollisionBody
from the broad-phase.void
setAABBExpansion(double expansion)
Sets theAABB
expansion value used to improve performance of broad-phase updates.void
setUpdated(T body)
TheBroadphaseDetector.update(CollisionBody)
method will only mark aCollisionBody
as updated if it's fixtures have moved enough to change the internally stored AABB.void
setUpdateTrackingEnabled(boolean flag)
Sets the update tracking to the given flag.boolean
supportsAABBExpansion()
Deprecated.void
update(T body)
Updates all theFixture
s on the givenCollisionBody
.-
Methods inherited from class Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface BroadphaseDetector
add, clear, clearUpdates, contains, contains, detectIterator, detectIterator, getAABB, isUpdated, isUpdated, optimize, raycastIterator, remove, remove, setUpdated, size, update
-
-
-
-
Method Detail
-
add
public void add(T body)
Description copied from interface:BroadphaseDetector
Adds a newCollisionBody
to the broad-phase.This will add all the given
CollisionBody
'sFixture
s to the broad-phase.If the body has no fixtures, nothing will be added to this broad-phase.
If the
CollisionBody
'sFixture
s have already been added to this broad-phase they will instead be updated.If a
Fixture
has been added to theCollisionBody
and theCollisionBody
has already been added to this broadphase, any newFixture
s will be added, and the existing ones will be updated.If a fixture is removed from a
CollisionBody
, the calling code must call theBroadphaseDetector.remove(CollisionBody, Fixture)
method for that fixture to be removed from the broad-phase. This method makes no effort to remove fixtures no longer attached to the given body.- Specified by:
add
in interfaceBroadphaseDetector<T extends CollisionBody<E>,E extends Fixture>
- Parameters:
body
- theCollisionBody
-
remove
public void remove(T body)
Description copied from interface:BroadphaseDetector
Removes the givenCollisionBody
from the broad-phase.This method removes all the
Fixture
s attached to the givenCollisionBody
from the broad-phase.If a fixture is removed from a
CollisionBody
, the calling code must call theBroadphaseDetector.remove(CollisionBody, Fixture)
method for that fixture to be removed from the broad-phase. This method makes no effort to remove fixtures no longer attached to the given body.- Specified by:
remove
in interfaceBroadphaseDetector<T extends CollisionBody<E>,E extends Fixture>
- Parameters:
body
- theCollisionBody
-
update
public void update(T body)
Description copied from interface:BroadphaseDetector
Updates all theFixture
s on the givenCollisionBody
.Used when the body or its fixtures have moved or rotated.
This method updates all the
Fixture
s attached to the givenCollisionBody
from the broad-phase, if they exist. If the fixtures on the given body do not exist in the broad-phase, they are added.If a fixture is removed from a
CollisionBody
, the calling code must call theBroadphaseDetector.remove(CollisionBody, Fixture)
method for that fixture to be removed from the broad-phase. This method makes no effort to remove fixtures no longer attached to the given body.- Specified by:
update
in interfaceBroadphaseDetector<T extends CollisionBody<E>,E extends Fixture>
- Parameters:
body
- theCollisionBody
-
setUpdated
public void setUpdated(T body)
Description copied from interface:BroadphaseDetector
TheBroadphaseDetector.update(CollisionBody)
method will only mark aCollisionBody
as updated if it's fixtures have moved enough to change the internally stored AABB.This method is intended to force the broadphase to include this
CollisionBody
'sFixture
s in the updated list to ensure they are checked in the updated-only detection routine.- Specified by:
setUpdated
in interfaceBroadphaseDetector<T extends CollisionBody<E>,E extends Fixture>
- Parameters:
body
- theCollisionBody
-
isUpdated
public boolean isUpdated(T body)
Description copied from interface:BroadphaseDetector
Returns true if any of theFixture
s on the givenCollisionBody
are included in the updated list.If
BroadphaseDetector.isUpdateTrackingEnabled()
is false, this method will always return true.Returns false if the given body is not part of this broadphase.
- Specified by:
isUpdated
in interfaceBroadphaseDetector<T extends CollisionBody<E>,E extends Fixture>
- Parameters:
body
- theCollisionBody
- Returns:
- boolean
-
detect
public boolean detect(T a, T b)
Description copied from interface:BroadphaseDetector
Returns true if this broad-phase detector considers the given bodies to be in collision.- Specified by:
detect
in interfaceBroadphaseDetector<T extends CollisionBody<E>,E extends Fixture>
- Parameters:
a
- the firstCollisionBody
b
- the secondCollisionBody
- Returns:
- boolean
-
getAABB
public AABB getAABB(T body)
Description copied from interface:BroadphaseDetector
Returns the AABB for the givenCollisionBody
.The AABB returned is an AABB encompasing all fixtures on the given
CollisionBody
. When possible, AABBs from the broad-phase will be used to create this, otherwise new AABBs will be created and unioned.In all cases this method returns the expanded AABB in the case this detector supports it.
If the body doesn't have any fixtures a degenerate AABB is returned.
- Specified by:
getAABB
in interfaceBroadphaseDetector<T extends CollisionBody<E>,E extends Fixture>
- Parameters:
body
- theCollisionBody
- Returns:
AABB
-
getAABB
public AABB getAABB(T body, E fixture)
Description copied from interface:BroadphaseDetector
Returns the AABB for the givenCollisionBody
Fixture
.If the body and its fixture have not been added to this broad-phase, a new AABB is created and returned (but not added to broad-phase).
In all cases this method returns the expanded AABB in the case this detector supports it.
NOTE: The
AABB
returned from this method should not be modified. Instead use theAABB.copy()
method to create a new instance to modify.- Specified by:
getAABB
in interfaceBroadphaseDetector<T extends CollisionBody<E>,E extends Fixture>
- Parameters:
body
- theCollisionBody
fixture
- theFixture
- Returns:
AABB
-
detect
public boolean detect(Convex convex1, Transform transform1, Convex convex2, Transform transform2)
Description copied from interface:BroadphaseDetector
-
contains
public boolean contains(T body)
Description copied from interface:BroadphaseDetector
Returns true if all theFixture
s on the givenCollisionBody
have been added to this broad-phase.If a body is added without any fixtures, this method will return false, since the fixtures, not the body, are added to the broad-phase.
- Specified by:
contains
in interfaceBroadphaseDetector<T extends CollisionBody<E>,E extends Fixture>
- Parameters:
body
- theCollisionBody
- Returns:
- boolean
-
detect
public List<CollisionPair<T,E>> detect()
Description copied from interface:BroadphaseDetector
Performs collision detection on allCollisionBody
Fixture
s that have been added to thisBroadphaseDetector
and returns the list of potential pairs.- Specified by:
detect
in interfaceBroadphaseDetector<T extends CollisionBody<E>,E extends Fixture>
- Returns:
- List<
BroadphasePair
>
-
detect
public List<CollisionPair<T,E>> detect(boolean forceFullDetection)
Description copied from interface:BroadphaseDetector
Performs collision detection onCollisionBody
Fixture
s that have been added to thisBroadphaseDetector
and returns the list of potential pairs.The returned pairs from this method will depend on the
BroadphaseDetector.isUpdateTrackingEnabled()
flag. If the flag is true, then only updated pairs will be emitted, otherwise all pairs are emitted.Use the forceFullDetection parameter to override this behavior for this call.
- Specified by:
detect
in interfaceBroadphaseDetector<T extends CollisionBody<E>,E extends Fixture>
- Parameters:
forceFullDetection
- true if a full detection should be performed- Returns:
- List<
BroadphasePair
>
-
detect
@Deprecated public List<CollisionPair<T,E>> detect(BroadphaseFilter<T,E> filter)
Deprecated.Description copied from interface:BroadphaseDetector
Performs collision detection on allCollisionBody
Fixture
s that have been added to thisBroadphaseDetector
and returns the list of potential pairs.Use the
filter
parameter to further reduce the number of potential pairs.- Specified by:
detect
in interfaceBroadphaseDetector<T extends CollisionBody<E>,E extends Fixture>
- Parameters:
filter
- the broad-phase filter- Returns:
- List<
BroadphasePair
> - See Also:
BroadphaseDetector.detect()
-
detect
public List<CollisionItem<T,E>> 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 extends CollisionBody<E>,E extends Fixture>
- Parameters:
aabb
- theAABB
to test- Returns:
- List<
CollisionItem
>
-
detect
@Deprecated public List<CollisionItem<T,E>> detect(AABB aabb, BroadphaseFilter<T,E> filter)
Deprecated.Description copied from interface:BroadphaseDetector
Performs a broad-phase collision test using the givenAABB
and returns the items that overlap.Use the
filter
parameter to further reduce the number of items returned.- Specified by:
detect
in interfaceBroadphaseDetector<T extends CollisionBody<E>,E extends Fixture>
- Parameters:
aabb
- theAABB
to testfilter
- the broad-phase filter- Returns:
- List<
CollisionItem
> - See Also:
BroadphaseDetector.detect(AABB)
-
raycast
public List<CollisionItem<T,E>> raycast(Ray ray, double length)
Description copied from interface:BroadphaseDetector
Performs a raycast over all the bodies in the broad-phase and returns the items that intersect.- Specified by:
raycast
in interfaceBroadphaseDetector<T extends CollisionBody<E>,E extends Fixture>
- Parameters:
ray
- theRay
length
- the length of the ray; 0.0 for infinite length- Returns:
- List<
CollisionItem
>
-
raycast
@Deprecated public List<CollisionItem<T,E>> raycast(Ray ray, double length, BroadphaseFilter<T,E> filter)
Deprecated.Description copied from interface:BroadphaseDetector
Performs a preliminary raycast over all the bodies in the broad-phase and returns the items that intersect.Use the
filter
parameter to further reduce the number of items returned.- Specified by:
raycast
in interfaceBroadphaseDetector<T extends CollisionBody<E>,E extends Fixture>
- Parameters:
ray
- theRay
length
- the length of the ray; 0.0 for infinite lengthfilter
- the broad-phase filter- Returns:
- List<
BroadphaseItem
> - See Also:
BroadphaseDetector.raycast(Ray, double)
-
supportsAABBExpansion
@Deprecated public boolean supportsAABBExpansion()
Deprecated.Description copied from interface:BroadphaseDetector
Returns whether this particularBroadphaseDetector
supports expanding AABBs.- Specified by:
supportsAABBExpansion
in interfaceBroadphaseDetector<T extends CollisionBody<E>,E extends Fixture>
- Returns:
- boolean
-
isAABBExpansionSupported
public boolean isAABBExpansionSupported()
Description copied from interface:BroadphaseDetector
Returns whether this particularBroadphaseDetector
supports expanding AABBs.- Specified by:
isAABBExpansionSupported
in interfaceBroadphaseDetector<T extends CollisionBody<E>,E extends Fixture>
- Returns:
- boolean
-
isUpdateTrackingSupported
public boolean isUpdateTrackingSupported()
Description copied from interface:BroadphaseDetector
Returns whether this particularBroadphaseDetector
supports update tracking.- Specified by:
isUpdateTrackingSupported
in interfaceBroadphaseDetector<T extends CollisionBody<E>,E extends Fixture>
- Returns:
- boolean
-
getAABBExpansion
public double getAABBExpansion()
Description copied from interface:BroadphaseDetector
Returns theAABB
expansion value used to improve performance of broad-phase updates.If supportsAABBExpansion() returns false the value returned is unspecified and should not be taken into account.
- Specified by:
getAABBExpansion
in interfaceBroadphaseDetector<T extends CollisionBody<E>,E extends Fixture>
- Returns:
- double
- See Also:
BroadphaseDetector.setAABBExpansion(double)
-
setAABBExpansion
public void setAABBExpansion(double expansion)
Description copied from interface:BroadphaseDetector
Sets theAABB
expansion value used to improve performance of broad-phase updates.Increasing this value will cause less updates to the broad-phase but will cause more pairs to be sent to the narrow-phase.
Note that a broadphase implementation may ignore this value, if supportsAABBExpansion() returns false.
- Specified by:
setAABBExpansion
in interfaceBroadphaseDetector<T extends CollisionBody<E>,E extends Fixture>
- Parameters:
expansion
- the expansion
-
isUpdateTrackingEnabled
public boolean isUpdateTrackingEnabled()
Description copied from interface:BroadphaseDetector
Returns true if this broadphase is tracking updated items.Tracking updates to the broadphase can have huge performance gains if the majority of objects are stationary or moving slowly enough.
- Specified by:
isUpdateTrackingEnabled
in interfaceBroadphaseDetector<T extends CollisionBody<E>,E extends Fixture>
- 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 broadphase 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 broadphase manually to ensure the updates set is non-empty. Typically this will self heal in the next iteration though.
NOTE: Some broadphase detectors may not support this feature.
- Specified by:
setUpdateTrackingEnabled
in interfaceBroadphaseDetector<T extends CollisionBody<E>,E extends Fixture>
- Parameters:
flag
- true to turn on update tracking- See Also:
BroadphaseDetector.isUpdateTrackingSupported()
-
-