Module org.dyn4j

Interface BroadphaseDetector<T>

    • Field Detail

      • DEFAULT_INITIAL_CAPACITY

        static final int DEFAULT_INITIAL_CAPACITY
        The default initial capacity of fixtures
        See Also:
        Constant Field Values
    • Method Detail

      • add

        void add​(T object)
        Adds a new object to this broad-phase.

        If the given object has already been added, the object is updated (update(Object)).

        Parameters:
        object - the object to add
        Since:
        3.0.0
      • remove

        boolean remove​(T object)
        Removes the given object from this broad-phase.
        Parameters:
        object - the object to remove
        Returns:
        boolean true if the object was removed
        Since:
        3.0.0
      • update

        void update()
        Updates all the currently stored objects AABBs based on their current state, the AABBProducer, and the AABBExpansionMethod.
        Since:
        4.1.0
      • update

        void update​(T object)
        Updates the broad-phase representation of the given object.

        This should be called when the object's location, rotation, or shape has changed.

        Parameters:
        object - the object
        Since:
        3.2.0
      • setUpdated

        void setUpdated​(T object)
        This method forces this broad-phase to include the given object in the updated list to ensure they are checked in the updated-only detection routine.

        The update(Object) method will only mark an object as updated if it's fixtures have moved enough to change the internally stored AABB.

        Parameters:
        object - the object
        Since:
        4.0.0
      • isUpdated

        boolean isUpdated​(T object)
        Returns true if the given object is marked as updated in this broad-phase.

        If isUpdateTrackingEnabled() is false, this method will always return true.

        Returns false if the given object is not part of this broad-phase.

        Parameters:
        object - the object
        Returns:
        boolean
        Since:
        4.0.0
      • clearUpdates

        void clearUpdates()
        Clears internal state that tracks what objects have been updated.

        Typically this method would be called from a pipeline after a broad-phase collision detection method has been called to clear the state before starting to track new updates.

        Since:
        4.0.0
      • getAABB

        AABB getAABB​(T object)
        Returns the AABB for the given object.

        NOTE: Some BroadphaseDetectors use modified (expanded for example) AABBs rather than tight fitting AABBs as a performance enhancement. This method returns the AABB used by this detector, and therefore, the modified AABB.

        NOTE: The AABB returned from this method should not be modified. Instead use the AABB.copy() method to create a new instance to modify.

        If the given object does not exist in this BroadphaseDetector a new AABB is created based on the object's shape, the getAABBProducer() and getAABBExpansionMethod().

        Parameters:
        object - the object
        Returns:
        AABB
        Since:
        3.2.0
      • contains

        boolean contains​(T object)
        Returns true if the given object exists in this broad-phase.
        Parameters:
        object - the object
        Returns:
        boolean
        Since:
        3.2.0
      • clear

        void clear()
        Clear all the internal state of this broad-phase.
        Since:
        3.0.0
      • size

        int size()
        Returns the number of objects managed in this broad-phase.
        Returns:
        int
      • detect

        List<CollisionPair<T>> detect()
        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 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.

        Returns:
        List<BroadphasePair>
        Since:
        3.0.0
      • detect

        List<CollisionPair<T>> detect​(boolean forceFullDetection)
        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 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 isUpdateTrackingEnabled() flag for this invocation.

        Parameters:
        forceFullDetection - true if a full detection should be performed
        Returns:
        List<BroadphasePair>
        Since:
        3.0.0
      • detectIterator

        Iterator<CollisionPair<T>> detectIterator()
        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 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.

        Returns:
        Iterator<CollisionPair>
        Since:
        4.1.0
      • detectIterator

        Iterator<CollisionPair<T>> detectIterator​(boolean forceFullDetection)
        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 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.

        Use the forceFullDetection parameter to override this behavior for a single call.

        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.

        Parameters:
        forceFullDetection - true if a full detection should be performed
        Returns:
        Iterator<CollisionPair>
        Since:
        4.0.0
      • detect

        List<T> detect​(AABB aabb)
        Performs a broad-phase collision test using the given AABB and returns the items that overlap.
        Parameters:
        aabb - the AABB to test
        Returns:
        List<T>
        Since:
        3.0.0
      • detectIterator

        Iterator<T> detectIterator​(AABB aabb)
        Performs a broad-phase collision test using the given AABB and returns the items that overlap.
        Parameters:
        aabb - the AABB to test
        Returns:
        Iterator<T>
        Since:
        4.0.0
      • raycast

        List<T> raycast​(Ray ray,
                        double length)
        Performs a raycast over all the objects in this broad-phase and returns the items that intersect.
        Parameters:
        ray - the Ray
        length - the length of the ray; 0.0 for infinite length
        Returns:
        List<T>
        Since:
        3.0.0
      • raycastIterator

        Iterator<T> raycastIterator​(Ray ray,
                                    double length)
        Performs a raycast over all the objects in the broad-phase and returns the items that intersect.
        Parameters:
        ray - the Ray
        length - the length of the ray; 0.0 for infinite length
        Returns:
        Iterator<T>
        Since:
        4.0.0
      • detect

        boolean detect​(T a,
                       T b)
        Returns true if this broad-phase detector considers the given objects to be in collision.
        Parameters:
        a - the first object
        b - the second object
        Returns:
        boolean
      • isUpdateTrackingSupported

        boolean isUpdateTrackingSupported()
        Returns whether this particular BroadphaseDetector supports update tracking.
        Returns:
        boolean
      • isUpdateTrackingEnabled

        boolean isUpdateTrackingEnabled()
        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.

        Returns:
        boolean
        Since:
        4.0.0
      • setUpdateTrackingEnabled

        void setUpdateTrackingEnabled​(boolean flag)
        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.

        Parameters:
        flag - true to turn on update tracking
        Since:
        4.0.0
        See Also:
        isUpdateTrackingSupported()
      • optimize

        void optimize()
        Attempts to optimize the broad-phase based on the current state.

        This method could be very intensive so should only be called if there's a clear benefit.

        Since:
        4.0.0