Module org.dyn4j

Class FallbackNarrowphaseDetector

  • All Implemented Interfaces:

    public class FallbackNarrowphaseDetector
    extends Object
    implements NarrowphaseDetector
    Represents a delegating NarrowphaseDetector that uses a primary NarrowphaseDetector and fallback NarrowphaseDetector.

    The fallback NarrowphaseDetector is used when any of the FallbackConditions added have been met.

    FallbackConditions 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. A TypedFallbackCondition can be used to fallback to the Gjk 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 the FallbackCondition 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 FallbackNarrowphaseDetectors as well allowing for a chain of fallbacks.

    William Bittle