Module org.dyn4j

Interface CollisionWorld<T extends CollisionBody<E>,​E extends Fixture,​V extends CollisionData<T,​E>>

  • Type Parameters:
    T - the CollisionBody type
    E - the Fixture type
    V - the CollisionData type
    All Superinterfaces:
    DataContainer, Shiftable
    All Known Subinterfaces:
    PhysicsWorld<T,​V>
    All Known Implementing Classes:
    AbstractCollisionWorld, AbstractPhysicsWorld, World

    public interface CollisionWorld<T extends CollisionBody<E>,​E extends Fixture,​V extends CollisionData<T,​E>>
    extends Shiftable, DataContainer
    Represents a world where CollisionBodys are added to participate in collision detection.

    Along with defining the necessary methods to maintain the CollisionBodys in an instance, this interface exposes the broad-narrow-manifold phases of collision detection allowing a user to swap implementations.

    This interface also defines the basic static queries a user would want to perform against the world including raycating, convex casting, AABB, and convex queries.

    NOTE: This interface does not define a collision detection pipeline or process. Instead it defines the necessary components to build one.

    Since:
    4.0.0
    Version:
    4.0.0
    Author:
    William Bittle
    • Method Detail

      • containsBody

        boolean containsBody​(T body)
        Returns true if this world contains the given body.
        Parameters:
        body - the CollisionBody to test for
        Returns:
        boolean true if the body is contained in this world
        Since:
        3.1.1
      • removeBody

        boolean removeBody​(int index)
        Removes the CollisionBody at the given index from this CollisionWorld.
        Parameters:
        index - the index of the body to remove.
        Returns:
        boolean true if the body was removed
        Since:
        3.2.0
      • removeAllBodies

        void removeAllBodies()
        Removes all bodies from this world.
        Since:
        3.0.1
      • getBodies

        List<T> getBodies()
        Returns an unmodifiable list containing all the bodies in this world.

        The returned list is backed by the internal list, therefore adding or removing bodies while iterating through the returned list is not permitted. Use the getBodyIterator() method instead.

        Returns:
        List<CollisionBody>
        Since:
        3.1.5
        See Also:
        getBodyIterator()
      • getBodyIterator

        Iterator<T> getBodyIterator()
        Returns an iterator for iterating over the bodies in this world.

        The returned iterator supports the remove method.

        Returns:
        Iterator<CollisionBody>
        Since:
        3.2.0
      • isEmpty

        boolean isEmpty()
        Returns true if this world doesn't contain any bodies or joints.
        Returns:
        boolean
        Since:
        3.0.1
      • setBounds

        void setBounds​(Bounds bounds)
        Sets the bounds of this CollisionWorld.
        Parameters:
        bounds - the bounds; can be null
      • getBounds

        Bounds getBounds()
        Returns the bounds of this world.

        This will return null if no bounds were initially set or if it was set to null via the setBounds(Bounds) method.

        Returns:
        Bounds the bounds or null
      • getBoundsListeners

        List<BoundsListener<T,​E>> getBoundsListeners()
        Returns an unmodifiable list of all the bounds listeners registered to this world.
        Returns:
        List<BoundsListener>
      • removeAllListeners

        void removeAllListeners()
        Removes all listeners from this world.
      • removeAllCollisionListeners

        void removeAllCollisionListeners()
        Removes all collision listeners from this world.
      • removeAllBoundsListeners

        void removeAllBoundsListeners()
        Removes all bounds listeners from this world.
      • removeCollisionListener

        boolean removeCollisionListener​(CollisionListener<T,​E> listener)
        Removes the given collision listener from this world and returns true if it was removed.

        This method will return false if the listener was not found in this world.

        Parameters:
        listener - the listener
        Returns:
        boolean
      • removeBoundsListener

        boolean removeBoundsListener​(BoundsListener<T,​E> listener)
        Removes the given bounds listener from this world and returns true if it was removed.

        This method will return false if the listener was not found in this world.

        Parameters:
        listener - the listener
        Returns:
        boolean
      • addCollisionListener

        boolean addCollisionListener​(CollisionListener<T,​E> listener)
        Adds the given CollisionListener to this world.

        NOTE: No effort is made to prevent duplicate listeners from being added.

        Parameters:
        listener - the listener to add
        Returns:
        boolean
      • addBoundsListener

        boolean addBoundsListener​(BoundsListener<T,​E> listener)
        Adds the given BoundsListener to this world.

        NOTE: No effort is made to prevent duplicate listeners from being added.

        Parameters:
        listener - the listener to add
        Returns:
        boolean
      • setBroadphaseDetector

        void setBroadphaseDetector​(BroadphaseDetector<T,​E> broadphaseDetector)
        Sets the broad-phase collision detection algorithm.
        Parameters:
        broadphaseDetector - the broad-phase collision detection algorithm
        Throws:
        NullPointerException - if broadphaseDetector is null
      • getBroadphaseDetector

        BroadphaseDetector<T,​E> getBroadphaseDetector()
        Returns the broad-phase collision detection algorithm.
        Returns:
        BroadphaseDetector the broad-phase collision detection algorithm
      • setBroadphaseFilter

        void setBroadphaseFilter​(BroadphaseFilter<T,​E> filter)
        Sets the BroadphaseFilter used when detecting collisions for each time step.

        This should always be an instance of a class that extends the PhysicsBodyBroadphaseFilter so that the standard filters are retained.

        Parameters:
        filter - the filter
        Since:
        3.2.2
      • setNarrowphaseDetector

        void setNarrowphaseDetector​(NarrowphaseDetector narrowphaseDetector)
        Sets the narrow-phase collision detection algorithm.
        Parameters:
        narrowphaseDetector - the narrow-phase collision detection algorithm
        Throws:
        NullPointerException - if narrowphaseDetector is null
      • getNarrowphaseDetector

        NarrowphaseDetector getNarrowphaseDetector()
        Returns the narrow-phase collision detection algorithm.
        Returns:
        NarrowphaseDetector the narrow-phase collision detection algorithm
      • setNarrowphasePostProcessor

        void setNarrowphasePostProcessor​(NarrowphasePostProcessor narrowphasePostProcessor)
        Sets the narrow-phase post processing algorithm.
        Parameters:
        narrowphasePostProcessor - the narrow-phase post processing algorithm
        Throws:
        NullPointerException - if narrowphasePostProcessor is null
      • setManifoldSolver

        void setManifoldSolver​(ManifoldSolver manifoldSolver)
        Sets the manifold solver.
        Parameters:
        manifoldSolver - the manifold solver
        Throws:
        NullPointerException - if manifoldSolver is null
      • setRaycastDetector

        void setRaycastDetector​(RaycastDetector raycastDetector)
        Sets the raycast detector.
        Parameters:
        raycastDetector - the raycast detector
        Throws:
        NullPointerException - if raycastDetector is null
        Since:
        2.0.0
      • setTimeOfImpactDetector

        void setTimeOfImpactDetector​(TimeOfImpactDetector timeOfImpactDetector)
        Sets the time of impact detector.
        Parameters:
        timeOfImpactDetector - the time of impact detector
        Throws:
        NullPointerException - if timeOfImpactDetector is null
        Since:
        1.2.0
      • getCollisionData

        V getCollisionData​(T body1,
                           E fixture1,
                           T body2,
                           E fixture2)
        Returns the collision data for the given body-fixture pairs.

        This returns the collision data for any pair that was detected in the broadphase. Use the CollisionData.isBroadphaseCollision(), CollisionData.isManifoldCollision(), etc. methods to inspect the type of collision or the details about the collision.

        Returns null if the body-fixtures are not colliding or if either no longer exist in the world.

        Parameters:
        body1 - the first body
        fixture1 - the first body's fixture
        body2 - the second body
        fixture2 - the second body's fixture
        Returns:
        V
      • getCollisionDataIterator

        Iterator<V> getCollisionDataIterator()
        Returns an iterator that can be used to enumerate all the collisions in this world.

        This returns the collision data for any pair that was detected in the broadphase. Use the CollisionData.isBroadphaseCollision(), CollisionData.isManifoldCollision(), etc. methods to inspect the type of collision or the details about the collision.

        NOTE: This iterator does NOT support removal.

        Returns:
        Iterator<V>
      • raycast

        List<RaycastResult<T,​E>> raycast​(Ray ray,
                                               double maxLength,
                                               DetectFilter<T,​E> filter)
        Returns a list of RaycastResults containing all the body-fixtures that overlap with the given Ray using the current state of the BroadphaseDetector.

        If the ray begins inside a fixture, that fixture will not be included in the results.

        Parameters:
        ray - the ray
        maxLength - the max length of the ray; any value less than or equal to zero represents infinite length
        filter - the filter; can be null
        Returns:
        List<RaycastResult>
      • raycastIterator

        Iterator<RaycastResult<T,​E>> raycastIterator​(Ray ray,
                                                           double maxLength,
                                                           DetectFilter<T,​E> filter)
        Returns an iterator of RaycastResults containing all the body-fixtures that overlap with the given Ray using the current state of the BroadphaseDetector.

        If the ray begins inside a fixture, that fixture will not be included in the results.

        Parameters:
        ray - the ray
        maxLength - the max length of the ray; any value less than or equal to zero represents infinite length
        filter - the filter; can be null
        Returns:
        Iterator<RaycastResult>
      • raycast

        List<RaycastResult<T,​E>> raycast​(Ray ray,
                                               double maxLength,
                                               T body,
                                               DetectFilter<T,​E> filter)
        Returns a list of RaycastResults containing all the body-fixtures that overlap with the given Ray only testing against the given CollisionBody.

        This method does not use the current state of the BroadphaseDetector and instead tests the given body's fixtures directly.

        If the ray begins inside a fixture, that fixture will not be included in the results.

        Parameters:
        ray - the ray
        maxLength - the max length of the ray; any value less than or equal to zero represents infinite length
        body - the body
        filter - the filter; can be null
        Returns:
        List<RaycastResult>
      • raycastIterator

        Iterator<RaycastResult<T,​E>> raycastIterator​(Ray ray,
                                                           double maxLength,
                                                           T body,
                                                           DetectFilter<T,​E> filter)
        Returns an iterator of RaycastResults containing all the body-fixtures that overlap with the given Ray only testing against the given CollisionBody.

        This method does not use the current state of the BroadphaseDetector and instead tests the given body's fixtures directly.

        If the ray begins inside a fixture, that fixture will not be included in the results.

        Parameters:
        ray - the ray
        maxLength - the max length of the ray; any value less than or equal to zero represents infinite length
        body - the body
        filter - the filter; can be null
        Returns:
        Iterator<RaycastResult>
      • raycastClosest

        RaycastResult<T,​E> raycastClosest​(Ray ray,
                                                double maxLength,
                                                DetectFilter<T,​E> filter)
        Returns the closest RaycastResult that overlaps with the given Ray using the current state of the BroadphaseDetector.

        The closest is defined as the closest intersection of the ray and a fixture to the ray's start point.

        If the ray begins inside a fixture, that fixture will not be included in the results.

        Parameters:
        ray - the ray
        maxLength - the max length of the ray; any value less than or equal to zero represents infinite length
        filter - the filter; can be null
        Returns:
        RaycastResult
      • raycastClosest

        RaycastResult<T,​E> raycastClosest​(Ray ray,
                                                double maxLength,
                                                T body,
                                                DetectFilter<T,​E> filter)
        Returns the closest RaycastResult that overlaps with the given Ray only testing against the given CollisionBody.

        The closest is defined as the closest intersection of the ray and a fixture to the ray's start point.

        This method does not use the current state of the BroadphaseDetector and instead tests the given body's fixtures directly.

        If the ray begins inside a fixture, that fixture will not be included in the results.

        Parameters:
        ray - the ray
        maxLength - the max length of the ray; any value less than or equal to zero represents infinite length
        body - the body
        filter - the filter; can be null
        Returns:
        RaycastResult
      • convexCast

        List<ConvexCastResult<T,​E>> convexCast​(Convex convex,
                                                     Transform transform,
                                                     Vector2 deltaPosition,
                                                     double deltaAngle,
                                                     DetectFilter<T,​E> filter)
        Returns a list of ConvexCastResults containing all the body-fixtures that overlap with the given Convex over the given deltaPosition and deltaAngle using the current state of the BroadphaseDetector.

        The deltaPosition and deltaAngle parameters define the cast of the convex. Imagine moving the given convex from it's current transform position to the given position and rotating the given convex from it's current transform rotation to the given rotation. This method detects if there was any collisions between these start and end states.

        This method assumes linear motion, meaning that the direction of motion is in the same direction for the start and end states as defined by the deltaPosition parameter.

        Parameters:
        convex - the convex
        transform - the transform
        deltaPosition - the change in position of the convex
        deltaAngle - the change in rotation of the convex
        filter - the filter; can be null
        Returns:
        List<ConvexCastResult>
      • convexCastIterator

        Iterator<ConvexCastResult<T,​E>> convexCastIterator​(Convex convex,
                                                                 Transform transform,
                                                                 Vector2 deltaPosition,
                                                                 double deltaAngle,
                                                                 DetectFilter<T,​E> filter)
        Returns an iterator of ConvexCastResults containing all the body-fixtures that overlap with the given Convex over the given deltaPosition and deltaAngle using the current state of the BroadphaseDetector.

        The deltaPosition and deltaAngle parameters define the cast of the convex. Imagine moving the given convex from it's current transform position to the given position and rotating the given convex from it's current transform rotation to the given rotation. This method detects if there was any collisions between these start and end states.

        This method assumes linear motion, meaning that the direction of motion is in the same direction for the start and end states as defined by the deltaPosition parameter.

        Parameters:
        convex - the convex
        transform - the transform
        deltaPosition - the change in position of the convex
        deltaAngle - the change in rotation of the convex
        filter - the filter; can be null
        Returns:
        Iterator<ConvexCastResult>
      • convexCastClosest

        ConvexCastResult<T,​E> convexCastClosest​(Convex convex,
                                                      Transform transform,
                                                      Vector2 deltaPosition,
                                                      double deltaAngle,
                                                      DetectFilter<T,​E> filter)
        Returns the closest ConvexCastResult that overlaps with the given Convex over the given deltaPosition and deltaAngle using the current state of the BroadphaseDetector.

        The closest is defined as the closest intersection from the initial position/rotation of the given convex.

        The deltaPosition and deltaAngle parameters define the cast of the convex. Imagine moving the given convex from it's current transform position to the given position and rotating the given convex from it's current transform rotation to the given rotation. This method detects if there was any collisions between these start and end states.

        This method assumes linear motion, meaning that the direction of motion is in the same direction for the start and end states as defined by the deltaPosition parameter.

        Parameters:
        convex - the convex
        transform - the transform
        deltaPosition - the change in position of the convex
        deltaAngle - the change in rotation of the convex
        filter - the filter; can be null
        Returns:
        ConvexCastResult
      • convexCastClosest

        ConvexCastResult<T,​E> convexCastClosest​(Convex convex,
                                                      Transform transform,
                                                      Vector2 deltaPosition,
                                                      double deltaAngle,
                                                      T body,
                                                      DetectFilter<T,​E> filter)
        Returns the closest ConvexCastResult that overlaps with the given Convex over the given deltaPosition and deltaAngle only testing against the given CollisionBody.

        The closest is defined as the closest intersection from the initial position/rotation of the given convex.

        The deltaPosition and deltaAngle parameters define the cast of the convex. Imagine moving the given convex from it's current transform position to the given position and rotating the given convex from it's current transform rotation to the given rotation. This method detects if there was any collisions between these start and end states.

        This method assumes linear motion, meaning that the direction of motion is in the same direction for the start and end states as defined by the deltaPosition parameter.

        Parameters:
        convex - the convex
        transform - the transform
        deltaPosition - the change in position of the convex
        deltaAngle - the change in rotation of the convex
        body - the body
        filter - the filter; can be null
        Returns:
        ConvexCastResult