- Object
-
- FallbackNarrowphaseDetector
-
- All Implemented Interfaces:
NarrowphaseDetector
public class FallbackNarrowphaseDetector extends Object implements NarrowphaseDetector
Represents a delegatingNarrowphaseDetector
that uses a primaryNarrowphaseDetector
and fallbackNarrowphaseDetector
.The fallback
NarrowphaseDetector
is used when any of theFallbackCondition
s added have been met.FallbackCondition
s will be checked in order and will stop on the first matched condition. By default the conditions are ordered in the order they are added unless a condition specifies a sortIndex.For example, when the
Sat
algorithm is used, some shapes are not supported. ATypedFallbackCondition
can be used to fallback to theGjk
algorithm:FallbackNarrowphaseDetector detector = new FallbackNarrowphaseDetector(new Sat(), new Gjk()); // any Slice collisions will be handled by Gjk instead of Sat detector.addCondition(new SingleTypedFallbackCondition(Slice.class));
New condition types can be added by implementing theFallbackCondition
interface. Doing so can lead to interesting options like custom collision detectors for specific cases or custom shapes.The primary and fallback detectors can also be
FallbackNarrowphaseDetector
s as well allowing for a chain of fallbacks.- Since:
- 3.1.5
- Version:
- 3.2.0
- Author:
- William Bittle
-
-
Constructor Summary
Constructors Constructor Description FallbackNarrowphaseDetector(NarrowphaseDetector primaryNarrowphaseDetector, NarrowphaseDetector fallbackNarrowphaseDetector)
Minimal constructor.FallbackNarrowphaseDetector(NarrowphaseDetector primaryNarrowphaseDetector, NarrowphaseDetector fallbackNarrowphaseDetector, List<FallbackCondition> conditions)
Full constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addCondition(FallbackCondition condition)
Adds the given condition to the list of fallback conditions.boolean
containsCondition(FallbackCondition condition)
Returns true if the given condition is contained in this detector.boolean
detect(Convex convex1, Transform transform1, Convex convex2, Transform transform2)
boolean
detect(Convex convex1, Transform transform1, Convex convex2, Transform transform2, Penetration penetration)
Returns true if the twoConvex
Shape
s intersect and fills thePenetration
object with the penetration vector and depth.FallbackCondition
getCondition(int index)
Returns the fallback condition at the given index.int
getConditionCount()
Returns the number of fallback conditions.NarrowphaseDetector
getFallbackNarrowphaseDetector()
Returns the fallbackNarrowphaseDetector
.NarrowphaseDetector
getPrimaryNarrowphaseDetector()
Returns the primaryNarrowphaseDetector
.boolean
isFallbackRequired(Convex convex1, Convex convex2)
Returns true if the fallbackNarrowphaseDetector
should be used rather than the primary.boolean
removeCondition(FallbackCondition condition)
Removes the given condition to the list of fallback conditions and returns true if the operation was successful.
-
-
-
Constructor Detail
-
FallbackNarrowphaseDetector
public FallbackNarrowphaseDetector(NarrowphaseDetector primaryNarrowphaseDetector, NarrowphaseDetector fallbackNarrowphaseDetector)
Minimal constructor.- Parameters:
primaryNarrowphaseDetector
- the primaryNarrowphaseDetector
fallbackNarrowphaseDetector
- the fallbackNarrowphaseDetector
- Throws:
NullPointerException
- if either the primary or fallbackNarrowphaseDetector
s are null
-
FallbackNarrowphaseDetector
public FallbackNarrowphaseDetector(NarrowphaseDetector primaryNarrowphaseDetector, NarrowphaseDetector fallbackNarrowphaseDetector, List<FallbackCondition> conditions)
Full constructor.- Parameters:
primaryNarrowphaseDetector
- the primaryNarrowphaseDetector
fallbackNarrowphaseDetector
- the fallbackNarrowphaseDetector
conditions
- the fallback conditions- Throws:
NullPointerException
- if either the primary or fallbackNarrowphaseDetector
s are null
-
-
Method Detail
-
addCondition
public void addCondition(FallbackCondition condition)
Adds the given condition to the list of fallback conditions.- Parameters:
condition
- the condition
-
removeCondition
public boolean removeCondition(FallbackCondition condition)
Removes the given condition to the list of fallback conditions and returns true if the operation was successful.- Parameters:
condition
- the condition- Returns:
- boolean
-
containsCondition
public boolean containsCondition(FallbackCondition condition)
Returns true if the given condition is contained in this detector.- Parameters:
condition
- the fallback condition- Returns:
- boolean
-
getConditionCount
public int getConditionCount()
Returns the number of fallback conditions.- Returns:
- int
-
getCondition
public FallbackCondition getCondition(int index)
Returns the fallback condition at the given index.- Parameters:
index
- the index- Returns:
FallbackCondition
- Throws:
IndexOutOfBoundsException
- if index is not between 0 andgetConditionCount()
-
isFallbackRequired
public boolean isFallbackRequired(Convex convex1, Convex convex2)
Returns true if the fallbackNarrowphaseDetector
should be used rather than the primary.- Parameters:
convex1
- the first convexconvex2
- the second convex- Returns:
- boolean
-
detect
public boolean detect(Convex convex1, Transform transform1, Convex convex2, Transform transform2)
Description copied from interface:NarrowphaseDetector
Returns true if the twoConvex
Shape
s intersect.Used to quickly test if two
Convex
Shape
s intersect without incurring the cost of determiningPenetration
.
-
detect
public boolean detect(Convex convex1, Transform transform1, Convex convex2, Transform transform2, Penetration penetration)
Description copied from interface:NarrowphaseDetector
Returns true if the twoConvex
Shape
s intersect and fills thePenetration
object with the penetration vector and depth.
-
getPrimaryNarrowphaseDetector
public NarrowphaseDetector getPrimaryNarrowphaseDetector()
Returns the primaryNarrowphaseDetector
.- Returns:
NarrowphaseDetector
-
getFallbackNarrowphaseDetector
public NarrowphaseDetector getFallbackNarrowphaseDetector()
Returns the fallbackNarrowphaseDetector
.- Returns:
NarrowphaseDetector
-
-