Module org.dyn4j

Class Sap<T>

    • Constructor Detail

      • Sap

        public Sap​(BroadphaseFilter<T> broadphaseFilter,
                   AABBProducer<T> aabbProducer,
                   AABBExpansionMethod<T> aabbExpansionMethod)
        Default constructor.
        Parameters:
        broadphaseFilter - the broadphase filter
        aabbProducer - the AABB producer
        aabbExpansionMethod - the AABB expansion method
        Throws:
        NullPointerException - if broadphaseFilter, aabbProducer or aabbExpansionMethod are null
      • Sap

        public Sap​(BroadphaseFilter<T> broadphaseFilter,
                   AABBProducer<T> aabbProducer,
                   AABBExpansionMethod<T> aabbExpansionMethod,
                   int initialCapacity)
        Full constructor.

        Allows fine tuning of the initial capacity of local storage for faster running times.

        Parameters:
        broadphaseFilter - the broadphase filter
        aabbProducer - the AABB producer
        aabbExpansionMethod - the AABB expansion method
        initialCapacity - the initial capacity of local storage
        Throws:
        NullPointerException - if broadphaseFilter, aabbProducer or aabbExpansionMethod are null
        IllegalArgumentException - if initialCapacity is less than zero
        Since:
        3.1.1
    • Method Detail

      • remove

        public boolean remove​(T object)
        Description copied from interface: BroadphaseDetector
        Removes the given object from this broad-phase.
        Specified by:
        remove in interface BroadphaseDetector<T>
        Parameters:
        object - the object to remove
        Returns:
        boolean true if the object was removed
      • update

        public void update​(T object)
        Description copied from interface: BroadphaseDetector
        Updates the broad-phase representation of the given object.

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

        Specified by:
        update in interface BroadphaseDetector<T>
        Parameters:
        object - the object
      • setUpdated

        public void setUpdated​(T object)
        Description copied from interface: BroadphaseDetector
        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 BroadphaseDetector.update(Object) method will only mark an object as updated if it's fixtures have moved enough to change the internally stored AABB.

        Specified by:
        setUpdated in interface BroadphaseDetector<T>
        Parameters:
        object - the object
      • clearUpdates

        public void clearUpdates()
        Description copied from interface: BroadphaseDetector
        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.

        Specified by:
        clearUpdates in interface BroadphaseDetector<T>
      • contains

        public boolean contains​(T object)
        Description copied from interface: BroadphaseDetector
        Returns true if the given object exists in this broad-phase.
        Specified by:
        contains in interface BroadphaseDetector<T>
        Parameters:
        object - the object
        Returns:
        boolean
      • size

        public int size()
        Description copied from interface: BroadphaseDetector
        Returns the number of objects managed in this broad-phase.
        Specified by:
        size in interface BroadphaseDetector<T>
        Returns:
        int
      • 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>
        Overrides:
        setUpdateTrackingEnabled in class AbstractBroadphaseDetector<T>
        Parameters:
        flag - true to turn on update tracking
        See Also:
        BroadphaseDetector.isUpdateTrackingSupported()
      • detectIterator

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

        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.

        Specified by:
        detectIterator in interface BroadphaseDetector<T>
        Parameters:
        forceFullDetection - true if a full detection should be performed
        Returns:
        Iterator<CollisionPair>
      • raycastIterator

        public Iterator<T> raycastIterator​(Ray ray,
                                           double length)
        Description copied from interface: BroadphaseDetector
        Performs a raycast over all the objects in the broad-phase and returns the items that intersect.
        Specified by:
        raycastIterator in interface BroadphaseDetector<T>
        Parameters:
        ray - the Ray
        length - the length of the ray; 0.0 for infinite length
        Returns:
        Iterator<T>
      • shift

        public void shift​(Vector2 shift)
        Description copied from interface: Shiftable
        Translates the object to match the given coordinate shift.
        Specified by:
        shift in interface Shiftable
        Parameters:
        shift - the amount to shift along the x and y axes
      • optimize

        public void optimize()
        Description copied from interface: BroadphaseDetector
        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.

        Specified by:
        optimize in interface BroadphaseDetector<T>