Module org.dyn4j

Class AbstractBroadphaseDetector<T>

    • 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 filter
        aabbProducer - the AABB producer
        aabbExpansionMethod - 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 interface BroadphaseDetector<T>
        Parameters:
        a - the first object
        b - the second object
        Returns:
        boolean
      • detect

        public List<CollisionPair<T>> detect()
        Description copied from interface: BroadphaseDetector
        Performs collision detection on all objects that have been added to this BroadphaseDetector 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 interface BroadphaseDetector<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 this BroadphaseDetector 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 interface BroadphaseDetector<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 this BroadphaseDetector 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 CollisionPairs that are mutable internally. If you need to store the pairs outside of the iteration, be sure to call the Copyable.copy() method to create a copy of the pair data.

        Specified by:
        detectIterator in interface BroadphaseDetector<T>
        Returns:
        Iterator<CollisionPair>
      • detect

        public List<T> detect​(AABB aabb)
        Description copied from interface: BroadphaseDetector
        Performs a broad-phase collision test using the given AABB and returns the items that overlap.
        Specified by:
        detect in interface BroadphaseDetector<T>
        Parameters:
        aabb - the AABB 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 interface BroadphaseDetector<T>
        Parameters:
        ray - the Ray
        length - the length of the ray; 0.0 for infinite length
        Returns:
        List<T>
      • 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 interface BroadphaseDetector<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 interface BroadphaseDetector<T>
        Parameters:
        flag - true to turn on update tracking
        See Also:
        BroadphaseDetector.isUpdateTrackingSupported()