Module org.dyn4j

Interface BroadphaseDetector<T extends CollisionBody<E>,​E extends Fixture>

    • Field Detail

      • DEFAULT_AABB_EXPANSION

        static final double DEFAULT_AABB_EXPANSION
        The default AABB expansion value
        See Also:
        Constant Field Values
      • 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 body)
        Adds a new CollisionBody to the broad-phase.

        This will add all the given CollisionBody's Fixtures to the broad-phase.

        If the body has no fixtures, nothing will be added to this broad-phase.

        If the CollisionBody's Fixtures have already been added to this broad-phase they will instead be updated.

        If a Fixture has been added to the CollisionBody and the CollisionBody has already been added to this broadphase, any new Fixtures will be added, and the existing ones will be updated.

        If a fixture is removed from a CollisionBody, the calling code must call the 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.

        Parameters:
        body - the CollisionBody
        Since:
        3.0.0
      • add

        void add​(T body,
                 E fixture)
        Adds a new Fixture for the given CollisionBody to the broad-phase.
        Parameters:
        body - the body
        fixture - the fixture to add
        Since:
        3.2.0
      • remove

        void remove​(T body)
        Removes the given CollisionBody from the broad-phase.

        This method removes all the Fixtures attached to the given CollisionBody from the broad-phase.

        If a fixture is removed from a CollisionBody, the calling code must call the 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.

        Parameters:
        body - the CollisionBody
        Since:
        3.0.0
      • remove

        boolean remove​(T body,
                       E fixture)
        Removes the given Fixture for the given CollisionBody from the broad-phase and returns true if it was found.
        Parameters:
        body - the body
        fixture - the fixture to remove
        Returns:
        boolean true if the fixture was found and removed
        Since:
        3.2.0
      • remove

        boolean remove​(CollisionItem<T,​E> item)
        Removes the given Fixture for the given CollisionBody from the broad-phase and returns true if it was found.
        Parameters:
        item - the collision item
        Returns:
        boolean true if the fixture was found and removed
        Since:
        4.0.0
      • update

        void update​(T body)
        Updates all the Fixtures on the given CollisionBody.

        Used when the body or its fixtures have moved or rotated.

        This method updates all the Fixtures attached to the given CollisionBody 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 the 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.

        Parameters:
        body - the CollisionBody
        Since:
        3.2.0
      • update

        void update​(T body,
                    E fixture)
        Updates the given CollisionBody's Fixture.

        Used when a fixture on a CollisionBody has moved or rotated.

        This method will add the Fixture if it doesn't currently exist in this broad-phase.

        Parameters:
        body - the CollisionBody
        fixture - the Fixture that has moved
        Since:
        3.2.0
      • setUpdated

        void setUpdated​(T body)
        The update(CollisionBody) method will only mark a CollisionBody 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's Fixtures in the updated list to ensure they are checked in the updated-only detection routine.

        Parameters:
        body - the CollisionBody
        Since:
        4.0.0
      • setUpdated

        void setUpdated​(T body,
                        E fixture)
        The update(CollisionBody, Fixture) method will only mark the Fixture as updated if the Fixture has moved enough to change the internally stored AABB.

        This method is intended to force the broadphase to include the Fixture in the updated list to ensure they are checked in the updated-only detection routine.

        Parameters:
        body - the CollisionBody
        fixture - the Fixture
        Since:
        4.0.0
      • isUpdated

        boolean isUpdated​(T body)
        Returns true if any of the Fixtures on the given CollisionBody are included in the updated list.

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

        Returns false if the given body is not part of this broadphase.

        Parameters:
        body - the CollisionBody
        Returns:
        boolean
        Since:
        4.0.0
      • isUpdated

        boolean isUpdated​(T body,
                          E fixture)
        Returns true if the given Fixture is included in the updated list.

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

        Returns false if the given body-fixture pair is not part of this broadphase.

        Parameters:
        body - the CollisionBody
        fixture - the Fixture
        Returns:
        boolean
        Since:
        4.0.0
      • isUpdated

        boolean isUpdated​(CollisionItem<T,​E> item)
        Returns true if the given Fixture is included in the updated list.

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

        Returns false if the given body-fixture pair is not part of this broadphase.

        Parameters:
        item - the collision item
        Returns:
        boolean
        Since:
        4.0.0
      • clearUpdates

        void clearUpdates()
        Clears any internal state that tracks what CollisionBody Fixtures have been updated.

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

        Since:
        4.0.0
      • getAABB

        AABB getAABB​(T body)
        Returns the AABB for the given CollisionBody.

        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.

        Parameters:
        body - the CollisionBody
        Returns:
        AABB
        Since:
        3.2.0
      • getAABB

        AABB getAABB​(T body,
                     E fixture)
        Returns the AABB for the given CollisionBody 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 the AABB.copy() method to create a new instance to modify.

        Parameters:
        body - the CollisionBody
        fixture - the Fixture
        Returns:
        AABB
        Since:
        3.2.0
      • getAABB

        AABB getAABB​(CollisionItem<T,​E> item)
        Returns the AABB for the given CollisionBody 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 the AABB.copy() method to create a new instance to modify.

        Parameters:
        item - the collision item
        Returns:
        AABB
        Since:
        4.0.0
      • contains

        boolean contains​(T body)
        Returns true if all the Fixtures on the given CollisionBody 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.

        Parameters:
        body - the CollisionBody
        Returns:
        boolean
        Since:
        3.2.0
      • contains

        boolean contains​(T body,
                         E fixture)
        Returns true if the given Fixture on the given CollisionBody has been added to this broadphase.
        Parameters:
        body - the CollisionBody
        fixture - the Fixture
        Returns:
        boolean
        Since:
        3.2.0
      • contains

        boolean contains​(CollisionItem<T,​E> item)
        Returns true if the given Fixture on the given CollisionBody has been added to this broadphase.
        Parameters:
        item - the collision item
        Returns:
        boolean
        Since:
        4.0.0
      • clear

        void clear()
        Clears all the CollisionBody Fixtures from this broad-phase and any state held by this broadphase.
        Since:
        3.0.0
      • size

        int size()
        Returns the number of CollisionBody Fixtures that are being managed in this broad-phase.
        Returns:
        int
      • detect

        List<CollisionPair<T,​E>> detect​(boolean forceFullDetection)
        Performs collision detection on CollisionBody Fixtures that have been added to this BroadphaseDetector and returns the list of potential pairs.

        The returned pairs from this method will depend on the 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.

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

        Iterator<CollisionPair<T,​E>> detectIterator​(boolean forceFullDetection)
        Performs collision detection on all CollisionBody Fixtures that have been added to this BroadphaseDetector and returns the list of potential pairs.

        The returned pairs from this method will depend on the 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.

        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<CollisionItem<T,​E>> 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<CollisionItem>
        Since:
        3.0.0
      • detectIterator

        Iterator<CollisionItem<T,​E>> 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<CollisionItem>
        Since:
        4.0.0
      • raycast

        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.
        Parameters:
        ray - the Ray
        length - the length of the ray; 0.0 for infinite length
        Returns:
        List<CollisionItem>
        Since:
        3.0.0
      • raycastIterator

        Iterator<CollisionItem<T,​E>> raycastIterator​(Ray ray,
                                                           double length)
        Performs a raycast over all the bodies 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<CollisionItem>
        Since:
        4.0.0
      • raycast

        @Deprecated
        List<CollisionItem<T,​E>> raycast​(Ray ray,
                                               double length,
                                               BroadphaseFilter<T,​E> filter)
        Deprecated.
        Deprecated in 4.0.0. Use the raycast(Ray, double) method instead
        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.

        Parameters:
        ray - the Ray
        length - the length of the ray; 0.0 for infinite length
        filter - the broad-phase filter
        Returns:
        List<BroadphaseItem>
        Since:
        3.2.0
        See Also:
        raycast(Ray, double)
      • detect

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

        boolean isAABBExpansionSupported()
        Returns whether this particular BroadphaseDetector supports expanding AABBs.
        Returns:
        boolean
      • isUpdateTrackingSupported

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

        double getAABBExpansion()
        Returns the AABB 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.

        Returns:
        double
        See Also:
        setAABBExpansion(double)
      • setAABBExpansion

        void setAABBExpansion​(double expansion)
        Sets the AABB 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.

        Parameters:
        expansion - the expansion
      • isUpdateTrackingEnabled

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

        Returns:
        boolean
        Since:
        4.0.0
      • setUpdateTrackingEnabled

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

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

        void optimize()
        Attempts to optimize the broadphase 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