Module org.dyn4j

Class World

  • All Implemented Interfaces:
    DataContainer, Shiftable

    public class World
    extends java.lang.Object
    implements Shiftable, DataContainer
    Manages the logic of collision detection, resolution, and reporting.

    Interfacing with dyn4j starts with this class. Create a new instance of this class and add bodies and joints. Then call one of the update or step methods in your game loop to move the physics engine forward in time.

    Via the addListener(Listener) method, a World instance can have multiple listeners for all the listener types. Some listener types return a boolean to indicate continuing or allowing something, like CollisionListener. If, for example, there are multiple CollisionListeners and any one of them returns false for an event, the collision is skipped. However, all listeners will still be called no matter if the first returned false.

    Since:
    1.0.0
    Version:
    3.4.0
    Author:
    William Bittle
    • Constructor Detail

      • World

        public World​(Capacity initialCapacity)
        Optional constructor.

        Defaults to using EARTH_GRAVITY, DynamicAABBTree broad-phase, Gjk narrow-phase, and ClippingManifoldSolver.

        The initial capacity specifies the estimated number of bodies that the simulation will have at any one time. This is used to size internal structures to improve performance. The internal structures can grow past the initial capacity.

        Parameters:
        initialCapacity - the initial capacity settings
        Since:
        3.1.1
      • World

        public World​(Capacity initialCapacity,
                     Bounds bounds)
        Full constructor.

        Defaults to using EARTH_GRAVITY, DynamicAABBTree broad-phase, Gjk narrow-phase, and ClippingManifoldSolver.

        The initial capacity specifies the estimated number of bodies that the simulation will have at any one time. This is used to size internal structures to improve performance. The internal structures can grow past the initial capacity.

        Parameters:
        initialCapacity - the initial capacity settings
        bounds - the bounds of the World; can be null
        Throws:
        java.lang.NullPointerException - if initialCapacity is null
        Since:
        3.1.1
    • Method Detail

      • update

        public boolean update​(double elapsedTime)
        Updates the World.

        This method will only update the world given the step frequency contained in the Settings object. You can use the StepListener interface to listen for when a step is actually performed. In addition, this method will return true if a step was performed.

        This method performs, at maximum, one simulation step. Any remaining time from the previous call of this method is added to the given elapsed time to determine if a step needs to be performed. If the given elapsed time is usually greater than the step frequency, consider using the update(double, int) method instead.

        Alternatively you can call the updatev(double) method to use a variable time step.

        Parameters:
        elapsedTime - the elapsed time in seconds
        Returns:
        boolean true if the World performed a simulation step
        See Also:
        update(double, int), updatev(double), getAccumulatedTime()
      • update

        public boolean update​(double elapsedTime,
                              int maximumSteps)
        Updates the World.

        This method will only update the world given the step frequency contained in the Settings object. You can use the StepListener interface to listen for when a step is actually performed.

        Unlike the update(double) method, this method will perform more than one step based on the given elapsed time. For example, if the given elapsed time + the remaining time from the last call of this method is 2 * step frequency, then 2 steps will be performed. Use the maximumSteps parameter to put an upper bound on the number of steps performed.

        Alternatively you can call the updatev(double) method to use a variable time step.

        Parameters:
        elapsedTime - the elapsed time in seconds
        maximumSteps - the maximum number of steps to perform
        Returns:
        boolean true if the World performed at least one simulation step
        Since:
        3.1.10
        See Also:
        update(double), updatev(double), getAccumulatedTime()
      • update

        public boolean update​(double elapsedTime,
                              double stepElapsedTime)
        Updates the World.

        This method will only update the world given the step frequency contained in the Settings object. You can use the StepListener interface to listen for when a step is actually performed. In addition, this method will return true if a step was performed.

        This method performs, at maximum, one simulation step. Any remaining time from the previous call of this method is added to the given elapsed time to determine if a step needs to be performed. If the given elapsed time is usually greater than the step frequency, consider using the update(double, int) method instead.

        The stepElapsedTime parameter provides a way for the World to continue to update at the frequency defined in the Settings object, but advance the simulation by the given time.

        Alternatively you can call the updatev(double) method to use a variable time step.

        Parameters:
        elapsedTime - the elapsed time in seconds
        stepElapsedTime - the time, in seconds, that the simulation should be advanced
        Returns:
        boolean true if the World performed at least one simulation step
        Since:
        3.2.4
        See Also:
        update(double), updatev(double), getAccumulatedTime()
      • update

        public boolean update​(double elapsedTime,
                              double stepElapsedTime,
                              int maximumSteps)
        Updates the World.

        This method will only update the world given the step frequency contained in the Settings object. You can use the StepListener interface to listen for when a step is actually performed.

        Unlike the update(double) method, this method will perform more than one step based on the given elapsed time. For example, if the given elapsed time + the remaining time from the last call of this method is 2 * step frequency, then 2 steps will be performed. Use the maximumSteps parameter to put an upper bound on the number of steps performed.

        The stepElapsedTime parameter provides a way for the World to continue to update at the frequency defined in the Settings object, but advance the simulation by the given time.

        Alternatively you can call the updatev(double) method to use a variable time step.

        Parameters:
        elapsedTime - the elapsed time in seconds
        stepElapsedTime - the time, in seconds, that the simulation should be advanced for each step; if less than or equal to zero Settings.getStepFrequency() will be used
        maximumSteps - the maximum number of steps to perform
        Returns:
        boolean true if the World performed at least one simulation step
        Since:
        3.2.4
        See Also:
        update(double), updatev(double), getAccumulatedTime()
      • updatev

        public void updatev​(double elapsedTime)
        Updates the World.

        This method will update the world on every call. Unlike the update(double) method, this method uses the given elapsed time and does not attempt to update the world on a set interval.

        This method immediately returns if the given elapsedTime is less than or equal to zero.

        Parameters:
        elapsedTime - the elapsed time in seconds
        See Also:
        update(double), update(double, int)
      • step

        public void step​(int steps)
        Performs the given number of simulation steps using the step frequency in Settings.

        This method immediately returns if the given step count is less than or equal to zero.

        Parameters:
        steps - the number of simulation steps to perform
      • step

        public void step​(int steps,
                         double elapsedTime)
        Performs the given number of simulation steps using the given elapsed time for each step.

        This method immediately returns if the given elapsedTime or step count is less than or equal to zero.

        Parameters:
        steps - the number of simulation steps to perform
        elapsedTime - the elapsed time for each step
      • step

        protected void step()
        Performs one time step of the World using the current Step.

        This method advances the world by the elapsed time in the Step object and performs collision resolution and constraint solving.

        This method will perform a collision detection sweep at the end to ensure that callers of the world have the latest collision information. If the isUpdateRequired() method returns true, a collision detection sweep will be performed before doing collision resolution. See the setUpdateRequired(boolean) method for details on when this flag should be set.

        Use the various listeners to listen for events during the execution of this method.

        If possible use the StepListener.postSolve(Step, World) method to update any bodies or joints to increase performance.

        Most Listeners do not allow modification of the world, bodies, joints, etc in there methods. It's recommended that any of modification be performed in a StepListener or after this method has returned.

      • detect

        protected void detect()
        Finds new contacts for all bodies in this world.

        This method performs the following:

        1. Checks for out of bound bodies
        2. Updates the broad-phase using the current body positions
        3. Performs broad-phase collision detection
        4. Performs narrow-phase collision detection
        5. Performs manifold solving
        6. Adds contacts to the contact manager
        7. Warm starts the contacts

        This method will notify all bounds and collision listeners. If any CollisionListener returns false, the collision is ignored.

        This method also notifies any ContactListeners.

        Since:
        3.0.0
      • solveTOI

        protected void solveTOI​(ContinuousDetectionMode mode)
        Solves the time of impact for all the Bodys in this World.

        This method solves for the time of impact for each Body iteratively and pairwise.

        The cases considered are dependent on the given collision detection mode.

        Cases skipped (including the converse of the above):

        • Inactive, asleep, or non-moving bodies
        • Bodies connected via a joint with the collision flag set to false
        • Bodies already in contact
        • Fixtures whose filters return false
        • Sensor fixtures
        Parameters:
        mode - the continuous collision detection mode
        Since:
        1.2.0
        See Also:
        ContinuousDetectionMode
      • solveTOI

        protected void solveTOI​(Body body1,
                                java.util.List<TimeOfImpactListener> listeners)
        Solves the time of impact for the given Body.

        This method will find the first Body that the given Body collides with unless ignored via the TimeOfImpactListener.

        If any TimeOfImpactListener doesn't allow the collision then the collision is ignored.

        After the first Body is found the two Bodys are interpolated to the time of impact.

        Then the Bodys are position solved using the TimeOfImpactSolver to force the Bodys into collision. This causes the discrete collision detector to detect the collision on the next time step.

        Parameters:
        body1 - the Body
        listeners - the list of TimeOfImpactListeners
        Since:
        3.1.0
      • raycast

        public boolean raycast​(Vector2 start,
                               Vector2 end,
                               boolean ignoreSensors,
                               boolean all,
                               java.util.List<RaycastResult> results)
        Performs a raycast against all the Bodys in the World.

        The given RaycastResult list, results, will be filled with the raycast results if the given ray intersected any bodies.

        The RaycastResult class implements the Comparable interface to allow sorting by distance from the ray's origin.

        If the all flag is false, the results list will only contain the closest result (if any).

        All raycasts pass through the RaycastListeners before being tested. If any RaycastListener doesn't allow the raycast then the body will not be tested.

        Bodies that contain the start of the ray will not be included in the results.

        Inactive bodies are ignored in this test.

        Parameters:
        start - the start point
        end - the end point
        ignoreSensors - true if sensor BodyFixtures should be ignored
        all - true if all intersected Bodys should be returned; false if only the closest Body should be returned
        results - a list to contain the results of the raycast
        Returns:
        boolean true if at least one Body was intersected by the Ray
        Throws:
        java.lang.NullPointerException - if start, end, or results is null
        Since:
        2.0.0
        See Also:
        raycast(Ray, double, boolean, boolean, List), RaycastListener.allow(Ray, Body, BodyFixture)
      • raycast

        public boolean raycast​(Vector2 start,
                               Vector2 end,
                               boolean ignoreSensors,
                               boolean ignoreInactive,
                               boolean all,
                               java.util.List<RaycastResult> results)
        Performs a raycast against all the Bodys in the World.

        The given RaycastResult list, results, will be filled with the raycast results if the given ray intersected any bodies.

        The RaycastResult class implements the Comparable interface to allow sorting by distance from the ray's origin.

        If the all flag is false, the results list will only contain the closest result (if any).

        All raycasts pass through the RaycastListeners before being tested. If any RaycastListener doesn't allow the raycast then the body will not be tested.

        Bodies that contain the start of the ray will not be included in the results.

        Parameters:
        start - the start point
        end - the end point
        ignoreSensors - true if sensor BodyFixtures should be ignored
        ignoreInactive - true if inactive bodies should be ignored
        all - true if all intersected Bodys should be returned; false if only the closest Body should be returned
        results - a list to contain the results of the raycast
        Returns:
        boolean true if at least one Body was intersected by the Ray
        Throws:
        java.lang.NullPointerException - if start, end, or results is null
        Since:
        3.1.9
        See Also:
        raycast(Ray, double, boolean, boolean, boolean, List), RaycastListener.allow(Ray, Body, BodyFixture)
      • raycast

        public boolean raycast​(Vector2 start,
                               Vector2 end,
                               Filter filter,
                               boolean ignoreSensors,
                               boolean ignoreInactive,
                               boolean all,
                               java.util.List<RaycastResult> results)
        Performs a raycast against all the Bodys in the World.

        The given RaycastResult list, results, will be filled with the raycast results if the given ray intersected any bodies.

        The RaycastResult class implements the Comparable interface to allow sorting by distance from the ray's origin.

        If the all flag is false, the results list will only contain the closest result (if any).

        All raycasts pass through the RaycastListeners before being tested. If any RaycastListener doesn't allow the raycast then the body will not be tested.

        Bodies that contain the start of the ray will not be included in the results.

        Parameters:
        start - the start point
        end - the end point
        filter - the Filter to use against the fixtures; can be null
        ignoreSensors - true if sensor BodyFixtures should be ignored
        ignoreInactive - true if inactive bodies should be ignored
        all - true if all intersected Bodys should be returned; false if only the closest Body should be returned
        results - a list to contain the results of the raycast
        Returns:
        boolean true if at least one Body was intersected by the Ray
        Throws:
        java.lang.NullPointerException - if start, end, or results is null
        Since:
        3.1.9
        See Also:
        raycast(Ray, double, Filter, boolean, boolean, boolean, List), RaycastListener.allow(Ray, Body, BodyFixture)
      • raycast

        public boolean raycast​(Ray ray,
                               double maxLength,
                               boolean ignoreSensors,
                               boolean all,
                               java.util.List<RaycastResult> results)
        Performs a raycast against all the Bodys in the World.

        The given RaycastResult list, results, will be filled with the raycast results if the given ray intersected any bodies.

        The RaycastResult class implements the Comparable interface to allow sorting by distance from the ray's origin.

        If the all flag is false, the results list will only contain the closest result (if any).

        Pass 0 into the maxLength field to specify an infinite length Ray.

        All raycasts pass through the RaycastListeners before being tested. If any RaycastListener doesn't allow the raycast then the body will not be tested.

        Bodies that contain the start of the ray will not be included in the results.

        Inactive bodies are ignored in this test.

        Parameters:
        ray - the Ray
        maxLength - the maximum length of the ray; 0 for infinite length
        ignoreSensors - true if sensor BodyFixtures should be ignored
        all - true if all intersected Bodys should be returned; false if only the closest Body should be returned
        results - a list to contain the results of the raycast
        Returns:
        boolean true if at least one Body was intersected by the given Ray
        Throws:
        java.lang.NullPointerException - if ray or results is null
        Since:
        2.0.0
        See Also:
        raycast(Vector2, Vector2, boolean, boolean, List), RaycastListener.allow(Ray, Body, BodyFixture)
      • raycast

        public boolean raycast​(Ray ray,
                               double maxLength,
                               boolean ignoreSensors,
                               boolean ignoreInactive,
                               boolean all,
                               java.util.List<RaycastResult> results)
        Performs a raycast against all the Bodys in the World.

        The given RaycastResult list, results, will be filled with the raycast results if the given ray intersected any bodies.

        The RaycastResult class implements the Comparable interface to allow sorting by distance from the ray's origin.

        If the all flag is false, the results list will only contain the closest result (if any).

        Pass 0 into the maxLength field to specify an infinite length Ray.

        All raycasts pass through the RaycastListeners before being tested. If any RaycastListener doesn't allow the raycast then the body will not be tested.

        Bodies that contain the start of the ray will not be included in the results.

        Parameters:
        ray - the Ray
        maxLength - the maximum length of the ray; 0 for infinite length
        ignoreSensors - true if sensor BodyFixtures should be ignored
        ignoreInactive - true if inactive bodies should be ignored
        all - true if all intersected Bodys should be returned; false if only the closest Body should be returned
        results - a list to contain the results of the raycast
        Returns:
        boolean true if at least one Body was intersected by the given Ray
        Throws:
        java.lang.NullPointerException - if ray or results is null
        Since:
        3.1.9
        See Also:
        raycast(Vector2, Vector2, boolean, boolean, boolean, List), RaycastListener.allow(Ray, Body, BodyFixture)
      • raycast

        public boolean raycast​(Ray ray,
                               double maxLength,
                               Filter filter,
                               boolean ignoreSensors,
                               boolean ignoreInactive,
                               boolean all,
                               java.util.List<RaycastResult> results)
        Performs a raycast against all the Bodys in the World.

        The given RaycastResult list, results, will be filled with the raycast results if the given ray intersected any bodies.

        The RaycastResult class implements the Comparable interface to allow sorting by distance from the ray's origin.

        If the all flag is false, the results list will only contain the closest result (if any).

        Pass 0 into the maxLength field to specify an infinite length Ray.

        All raycasts pass through the RaycastListeners before being tested. If any RaycastListener doesn't allow the raycast then the body will not be tested.

        Bodies that contain the start of the ray will not be included in the results.

        Parameters:
        ray - the Ray
        maxLength - the maximum length of the ray; 0 for infinite length
        filter - the Filter to use against the fixtures; can be null
        ignoreSensors - true if sensor BodyFixtures should be ignored
        ignoreInactive - true if inactive bodies should be ignored
        all - true if all intersected Bodys should be returned; false if only the closest Body should be returned
        results - a list to contain the results of the raycast
        Returns:
        boolean true if at least one Body was intersected by the given Ray
        Throws:
        java.lang.NullPointerException - if ray or results is null
        Since:
        3.1.9
        See Also:
        raycast(Vector2, Vector2, Filter, boolean, boolean, boolean, List), RaycastListener.allow(Ray, Body, BodyFixture)
      • raycast

        public boolean raycast​(Vector2 start,
                               Vector2 end,
                               Body body,
                               boolean ignoreSensors,
                               RaycastResult result)
        Performs a raycast against the given Body and returns true if the ray intersects the body.

        The given RaycastResult object, result, will be filled with the raycast result if the given ray intersected the given body.

        All raycasts pass through the RaycastListeners before being tested. If any RaycastListener doesn't allow the raycast then the body will not be tested.

        Returns false if the start position of the ray lies inside the given body.

        Parameters:
        start - the start point
        end - the end point
        body - the Body to test
        ignoreSensors - whether or not to ignore sensor BodyFixtures
        result - the raycast result
        Returns:
        boolean true if the Ray intersects the Body
        Throws:
        java.lang.NullPointerException - if start, end, body, or result is null
        Since:
        2.0.0
        See Also:
        raycast(Ray, Body, double, boolean, RaycastResult), RaycastListener.allow(Ray, Body, BodyFixture)
      • raycast

        public boolean raycast​(Vector2 start,
                               Vector2 end,
                               Body body,
                               Filter filter,
                               boolean ignoreSensors,
                               RaycastResult result)
        Performs a raycast against the given Body and returns true if the ray intersects the body.

        The given RaycastResult object, result, will be filled with the raycast result if the given ray intersected the given body.

        All raycasts pass through the RaycastListeners before being tested. If any RaycastListener doesn't allow the raycast then the body will not be tested.

        Returns false if the start position of the ray lies inside the given body.

        Parameters:
        start - the start point
        end - the end point
        body - the Body to test
        filter - the Filter to use against the fixtures; can be null
        ignoreSensors - whether or not to ignore sensor BodyFixtures
        result - the raycast result
        Returns:
        boolean true if the Ray intersects the Body
        Throws:
        java.lang.NullPointerException - if start, end, body, or result is null
        Since:
        3.1.9
        See Also:
        raycast(Ray, Body, double, Filter, boolean, RaycastResult), RaycastListener.allow(Ray, Body, BodyFixture)
      • raycast

        public boolean raycast​(Ray ray,
                               Body body,
                               double maxLength,
                               boolean ignoreSensors,
                               RaycastResult result)
        Performs a raycast against the given Body and returns true if the ray intersects the body.

        The given RaycastResult object, result, will be filled with the raycast result if the given ray intersected the given body.

        Pass 0 into the maxLength field to specify an infinite length Ray.

        All raycasts pass through the RaycastListeners before being tested. If any RaycastListener doesn't allow the raycast then the body will not be tested.

        Returns false if the start position of the ray lies inside the given body.

        Parameters:
        ray - the Ray to cast
        body - the Body to test
        maxLength - the maximum length of the ray; 0 for infinite length
        ignoreSensors - whether or not to ignore sensor BodyFixtures
        result - the raycast result
        Returns:
        boolean true if the Ray intersects the Body
        Throws:
        java.lang.NullPointerException - if ray, body, or result is null
        Since:
        2.0.0
        See Also:
        raycast(Vector2, Vector2, Body, boolean, RaycastResult), RaycastListener.allow(Ray, Body, BodyFixture)
      • raycast

        public boolean raycast​(Ray ray,
                               Body body,
                               double maxLength,
                               Filter filter,
                               boolean ignoreSensors,
                               RaycastResult result)
        Performs a raycast against the given Body and returns true if the ray intersects the body.

        The given RaycastResult object, result, will be filled with the raycast result if the given ray intersected the given body.

        Pass 0 into the maxLength field to specify an infinite length Ray.

        All raycasts pass through the RaycastListeners before being tested. If any RaycastListener doesn't allow the raycast then the body will not be tested.

        Returns false if the start position of the ray lies inside the given body.

        Parameters:
        ray - the Ray to cast
        body - the Body to test
        maxLength - the maximum length of the ray; 0 for infinite length
        filter - the Filter to use against the fixtures; can be null
        ignoreSensors - whether or not to ignore sensor BodyFixtures
        result - the raycast result
        Returns:
        boolean true if the Ray intersects the Body
        Throws:
        java.lang.NullPointerException - if ray, body, or result is null
        Since:
        3.1.9
        See Also:
        raycast(Vector2, Vector2, Body, Filter, boolean, RaycastResult), RaycastListener.allow(Ray, Body, BodyFixture)
      • convexCast

        public boolean convexCast​(Convex convex,
                                  Transform transform,
                                  Vector2 deltaPosition,
                                  boolean ignoreSensors,
                                  boolean all,
                                  java.util.List<ConvexCastResult> results)
        Performs a linear convex cast on the world, placing any detected collisions into the given results list.

        This method does a static test of bodies (in other words, does not take into account the bodies linear or angular velocity, but rather assumes they are stationary).

        The deltaPosition parameter is the linear cast vector determining the direction and magnitude of the cast.

        The ConvexCastResult class implements the Comparable interface to allow sorting by the time of impact.

        If the all flag is false, the results list will only contain the closest result (if any).

        All convex casts pass through the ConvexCastListeners before being tested. If any ConvexCastListener doesn't allow the convex cast, then the body will not be tested.

        For multi-fixtured bodies, only the fixture that has the minimum time of impact will be added to the results list.

        Bodies in collision with the given convex at the beginning of the cast are not included in the results.

        Inactive bodies are ignored in this test.

        Parameters:
        convex - the convex to cast
        transform - the initial position and orientation of the convex
        deltaPosition - Δposition; the change in position (the cast length and direction basically)
        ignoreSensors - true if sensor fixtures should be ignored in the tests
        all - true if all hits should be returned; false if only the first should be returned
        results - the list to add the results to
        Returns:
        boolean true if a collision was found
        Since:
        3.1.5
        See Also:
        convexCast(Convex, Transform, Vector2, double, boolean, boolean, boolean, List)
      • convexCast

        public boolean convexCast​(Convex convex,
                                  Transform transform,
                                  Vector2 deltaPosition,
                                  boolean ignoreSensors,
                                  boolean ignoreInactive,
                                  boolean all,
                                  java.util.List<ConvexCastResult> results)
        Performs a linear convex cast on the world, placing any detected collisions into the given results list.

        This method does a static test of bodies (in other words, does not take into account the bodies linear or angular velocity, but rather assumes they are stationary).

        The deltaPosition parameter is the linear cast vector determining the direction and magnitude of the cast.

        The ConvexCastResult class implements the Comparable interface to allow sorting by the time of impact.

        If the all flag is false, the results list will only contain the closest result (if any).

        All convex casts pass through the ConvexCastListeners before being tested. If any ConvexCastListener doesn't allow the convex cast, then the body will not be tested.

        For multi-fixtured bodies, only the fixture that has the minimum time of impact will be added to the results list.

        Bodies in collision with the given convex at the beginning of the cast are not included in the results.

        Parameters:
        convex - the convex to cast
        transform - the initial position and orientation of the convex
        deltaPosition - Δposition; the change in position (the cast length and direction basically)
        ignoreSensors - true if sensor fixtures should be ignored in the tests
        ignoreInactive - true if inactive bodies should be ignored in the tests
        all - true if all hits should be returned; false if only the first should be returned
        results - the list to add the results to
        Returns:
        boolean true if a collision was found
        Since:
        3.1.9
        See Also:
        convexCast(Convex, Transform, Vector2, double, boolean, boolean, boolean, List)
      • convexCast

        public boolean convexCast​(Convex convex,
                                  Transform transform,
                                  Vector2 deltaPosition,
                                  double deltaAngle,
                                  boolean ignoreSensors,
                                  boolean all,
                                  java.util.List<ConvexCastResult> results)
        Performs a linear convex cast on the world, placing any detected collisions into the given results list.

        This method does a static test of bodies (in other words, does not take into account the bodies linear or angular velocity, but rather assumes they are stationary).

        The deltaPosition parameter is the linear cast vector determining the direction and magnitude of the cast. The deltaAngle parameter is the change in angle over the linear cast and is interpolated linearly during detection.

        The ConvexCastResult class implements the Comparable interface to allow sorting by the time of impact.

        If the all flag is false, the results list will only contain the closest result (if any).

        All convex casts pass through the ConvexCastListeners before being tested. If any ConvexCastListener doesn't allow the convex cast, then the body will not be tested.

        For multi-fixtured bodies, only the fixture that has the minimum time of impact will be added to the results list.

        Bodies in collision with the given convex at the beginning of the cast are not included in the results.

        Inactive bodies are ignored in this test.

        Parameters:
        convex - the convex to cast
        transform - the initial position and orientation of the convex
        deltaPosition - Δposition; the change in position (the cast length and direction basically)
        deltaAngle - Δangle; the change in the angle; this is the change in the angle over the linear period
        ignoreSensors - true if sensor fixtures should be ignored in the tests
        all - true if all hits should be returned; false if only the first should be returned
        results - the list to add the results to
        Returns:
        boolean true if a collision was found
        Since:
        3.1.5
        See Also:
        convexCast(Convex, Transform, Vector2, double, boolean, boolean, boolean, List)
      • convexCast

        public boolean convexCast​(Convex convex,
                                  Transform transform,
                                  Vector2 deltaPosition,
                                  double deltaAngle,
                                  boolean ignoreSensors,
                                  boolean ignoreInactive,
                                  boolean all,
                                  java.util.List<ConvexCastResult> results)
        Performs a linear convex cast on the world, placing any detected collisions into the given results list.

        This method does a static test of bodies (in other words, does not take into account the bodies linear or angular velocity, but rather assumes they are stationary).

        The deltaPosition parameter is the linear cast vector determining the direction and magnitude of the cast. The deltaAngle parameter is the change in angle over the linear cast and is interpolated linearly during detection.

        The ConvexCastResult class implements the Comparable interface to allow sorting by the time of impact.

        If the all flag is false, the results list will only contain the closest result (if any).

        All convex casts pass through the ConvexCastListeners before being tested. If any ConvexCastListener doesn't allow the convex cast, then the body will not be tested.

        For multi-fixtured bodies, only the fixture that has the minimum time of impact will be added to the results list.

        Bodies in collision with the given convex at the beginning of the cast are not included in the results.

        Parameters:
        convex - the convex to cast
        transform - the initial position and orientation of the convex
        deltaPosition - Δposition; the change in position (the cast length and direction basically)
        deltaAngle - Δangle; the change in the angle; this is the change in the angle over the linear period
        ignoreSensors - true if sensor fixtures should be ignored in the tests
        ignoreInactive - true if inactive bodies should be ignored in the tests
        all - true if all hits should be returned; false if only the first should be returned
        results - the list to add the results to
        Returns:
        boolean true if a collision was found
        Since:
        3.1.9
      • convexCast

        public boolean convexCast​(Convex convex,
                                  Transform transform,
                                  Vector2 deltaPosition,
                                  double deltaAngle,
                                  Filter filter,
                                  boolean ignoreSensors,
                                  boolean ignoreInactive,
                                  boolean all,
                                  java.util.List<ConvexCastResult> results)
        Performs a linear convex cast on the world, placing any detected collisions into the given results list.

        This method does a static test of bodies (in other words, does not take into account the bodies linear or angular velocity, but rather assumes they are stationary).

        The deltaPosition parameter is the linear cast vector determining the direction and magnitude of the cast. The deltaAngle parameter is the change in angle over the linear cast and is interpolated linearly during detection.

        The ConvexCastResult class implements the Comparable interface to allow sorting by the time of impact.

        If the all flag is false, the results list will only contain the closest result (if any).

        All convex casts pass through the ConvexCastListeners before being tested. If any ConvexCastListener doesn't allow the convex cast, then the body will not be tested.

        For multi-fixtured bodies, only the fixture that has the minimum time of impact will be added to the results list.

        Bodies in collision with the given convex at the beginning of the cast are not included in the results.

        Parameters:
        convex - the convex to cast
        transform - the initial position and orientation of the convex
        deltaPosition - Δposition; the change in position (the cast length and direction basically)
        deltaAngle - Δangle; the change in the angle; this is the change in the angle over the linear period
        filter - the Filter to use against the fixtures; can be null
        ignoreSensors - true if sensor fixtures should be ignored in the tests
        ignoreInactive - true if inactive bodies should be ignored in the tests
        all - true if all hits should be returned; false if only the first should be returned
        results - the list to add the results to
        Returns:
        boolean true if a collision was found
        Since:
        3.1.9
      • convexCast

        public boolean convexCast​(Convex convex,
                                  Transform transform,
                                  Vector2 deltaPosition,
                                  Body body,
                                  boolean ignoreSensors,
                                  ConvexCastResult result)
        Performs a linear convex cast on the given body, placing a detected collision into the given result object.

        This method does a static test of the body (in other words, does not take into account the body's linear or angular velocity, but rather assumes it is stationary).

        The deltaPosition parameter is the linear cast vector determining the direction and magnitude of the cast.

        All convex casts pass through the ConvexCastListeners before being tested. If any ConvexCastListener doesn't allow the convex cast, then the body will not be tested.

        For multi-fixtured bodies, the fixture that has the minimum time of impact will be the result.

        Returns false if the given body and convex are in collision at the beginning of the cast.

        Parameters:
        convex - the convex to cast
        transform - the initial position and orientation of the convex
        deltaPosition - Δposition; the change in position (the cast length and direction basically)
        body - the body to cast against
        ignoreSensors - true if sensor fixtures should be ignored in the tests
        result - the convex cast result
        Returns:
        boolean true if a collision was found
        Since:
        3.1.5
      • convexCast

        public boolean convexCast​(Convex convex,
                                  Transform transform,
                                  Vector2 deltaPosition,
                                  double deltaAngle,
                                  Body body,
                                  boolean ignoreSensors,
                                  ConvexCastResult result)
        Performs a linear convex cast on the given body, placing a detected collision into the given result object.

        This method does a static test of the body (in other words, does not take into account the body's linear or angular velocity, but rather assumes it is stationary).

        The deltaPosition parameter is the linear cast vector determining the direction and magnitude of the cast. The deltaAngle parameter is the change in angle over the linear cast and is interpolated linearly during detection.

        All convex casts pass through the ConvexCastListeners before being tested. If any ConvexCastListener doesn't allow the convex cast, then the body will not be tested.

        For multi-fixtured bodies, the fixture that has the minimum time of impact will be the result.

        Returns false if the given body and convex are in collision at the beginning of the cast.

        Parameters:
        convex - the convex to cast
        transform - the initial position and orientation of the convex
        deltaPosition - Δposition; the change in position (the cast length and direction basically)
        deltaAngle - Δangle; the change in the angle; this is the change in the angle over the linear period
        body - the body to cast against
        ignoreSensors - true if sensor fixtures should be ignored in the tests
        result - the convex cast result
        Returns:
        boolean true if a collision was found
        Since:
        3.1.5
      • convexCast

        public boolean convexCast​(Convex convex,
                                  Transform transform,
                                  Vector2 deltaPosition,
                                  double deltaAngle,
                                  Body body,
                                  Filter filter,
                                  boolean ignoreSensors,
                                  ConvexCastResult result)
        Performs a linear convex cast on the given body, placing a detected collision into the given result object.

        This method does a static test of the body (in other words, does not take into account the body's linear or angular velocity, but rather assumes it is stationary).

        The deltaPosition parameter is the linear cast vector determining the direction and magnitude of the cast. The deltaAngle parameter is the change in angle over the linear cast and is interpolated linearly during detection.

        All convex casts pass through the ConvexCastListeners before being tested. If any ConvexCastListener doesn't allow the convex cast, then the body will not be tested.

        For multi-fixtured bodies, the fixture that has the minimum time of impact will be the result.

        Returns false if the given body and convex are in collision at the beginning of the cast.

        Parameters:
        convex - the convex to cast
        transform - the initial position and orientation of the convex
        deltaPosition - Δposition; the change in position (the cast length and direction basically)
        deltaAngle - Δangle; the change in the angle; this is the change in the angle over the linear period
        body - the body to cast against
        filter - the Filter to use against the fixtures; can be null
        ignoreSensors - true if sensor fixtures should be ignored in the tests
        result - the convex cast result
        Returns:
        boolean true if a collision was found
        Since:
        3.1.9
      • detect

        public boolean detect​(AABB aabb,
                              java.util.List<DetectResult> results)
        Returns true if the given AABB overlaps a Body in this World.

        If any part of a body is overlaping the AABB, the body is added to the list.

        This performs a static collision test of the world using the BroadphaseDetector.

        This may return bodies who only have sensor fixtures overlapping.

        Inactive bodies are ignored in this test.

        Parameters:
        aabb - the world space AABB
        results - the list of overlapping bodies and fixtures
        Returns:
        boolean true if the AABB overlaps any body
        Since:
        3.1.9
      • detect

        public boolean detect​(AABB aabb,
                              boolean ignoreInactive,
                              java.util.List<DetectResult> results)
        Returns true if the given AABB overlaps a Body Fixture in this World.

        If any part of a body is overlaping the AABB, the body and that respective fixture is added to the returned list.

        This performs a static collision test of the world using the BroadphaseDetector.

        This may return bodies who only have sensor fixtures overlapping.

        Parameters:
        aabb - the world space AABB
        ignoreInactive - true if inactive bodies should be ignored
        results - the list of overlapping bodies and fixtures
        Returns:
        boolean true if the AABB overlaps any body
        Since:
        3.1.9
      • detect

        public boolean detect​(AABB aabb,
                              boolean ignoreSensors,
                              boolean ignoreInactive,
                              java.util.List<DetectResult> results)
        Returns true if the given AABB overlaps a Body in this World.

        If this method returns true, the results list will contain the bodies and fixtures that the convex overlaps.

        Parameters:
        aabb - the world space AABB
        ignoreSensors - true if sensor fixtures should be ignored
        ignoreInactive - true if inactive bodies should be ignored
        results - the list of overlapping bodies and fixtures
        Returns:
        boolean true if the AABB overlaps any fixture
        Since:
        3.1.9
      • detect

        public boolean detect​(AABB aabb,
                              Filter filter,
                              boolean ignoreSensors,
                              boolean ignoreInactive,
                              java.util.List<DetectResult> results)
        Returns true if the given AABB overlaps a Body in this World.

        If this method returns true, the results list will contain the bodies and fixtures that the convex overlaps.

        Parameters:
        aabb - the world space AABB
        filter - the Filter to use against the fixtures; can be null
        ignoreSensors - true if sensor fixtures should be ignored
        ignoreInactive - true if inactive bodies should be ignored
        results - the list of overlapping bodies and fixtures
        Returns:
        boolean true if the AABB overlaps any fixture
        Since:
        3.1.9
      • detect

        public boolean detect​(Convex convex,
                              java.util.List<DetectResult> results)
        Returns true if the given Convex overlaps a body in the world.

        If this method returns true, the results list will contain the bodies and fixtures that the convex overlaps.

        Use the Body.isInContact(Body) method instead if you want to test if two bodies are colliding.

        The returned results may include sensor fixutres.

        Inactive bodies are ignored in this test.

        The results from this test will not include Penetration objects.

        Parameters:
        convex - the convex shape in world coordinates
        results - the list of overlapping bodies and fixtures
        Returns:
        boolean true if an overlap was found
        Since:
        3.1.9
        See Also:
        detect(Convex, boolean, List)
      • detect

        public boolean detect​(Convex convex,
                              boolean ignoreSensors,
                              java.util.List<DetectResult> results)
        Returns true if the given Convex overlaps a body in the world.

        If this method returns true, the results list will contain the bodies and fixtures that the convex overlaps.

        Use the Body.isInContact(Body) method instead if you want to test if two bodies are colliding.

        Inactive bodies are ignored in this test.

        The results from this test will not include Penetration objects.

        Parameters:
        convex - the convex shape in world coordinates
        ignoreSensors - true if sensor fixtures should be ignored
        results - the list of overlapping bodies and fixtures
        Returns:
        boolean true if an overlap was found
        Since:
        3.1.9
        See Also:
        detect(Convex, boolean, boolean, List)
      • detect

        public boolean detect​(Convex convex,
                              boolean ignoreSensors,
                              boolean ignoreInactive,
                              java.util.List<DetectResult> results)
        Returns true if the given Convex overlaps a body in the world.

        If this method returns true, the results list will contain the bodies and fixtures that the convex overlaps.

        Use the Body.isInContact(Body) method instead if you want to test if two bodies are colliding.

        The results from this test will not include Penetration objects.

        Parameters:
        convex - the convex shape in world coordinates
        ignoreSensors - true if sensor fixtures should be ignored
        ignoreInactive - true if inactive bodies should be ignored
        results - the list of overlapping bodies and fixtures
        Returns:
        boolean true if an overlap was found
        Since:
        3.1.9
        See Also:
        detect(Convex, Transform, Filter, boolean, boolean, List)
      • detect

        public boolean detect​(Convex convex,
                              Filter filter,
                              boolean ignoreSensors,
                              boolean ignoreInactive,
                              java.util.List<DetectResult> results)
        Returns true if the given Convex overlaps a body in the world.

        If this method returns true, the results list will contain the bodies and fixtures that the convex overlaps.

        Use the Body.isInContact(Body) method instead if you want to test if two bodies are colliding.

        The results from this test will not include Penetration objects.

        Parameters:
        convex - the convex shape in world coordinates
        filter - the Filter to use against the fixtures; can be null
        ignoreSensors - true if sensor fixtures should be ignored
        ignoreInactive - true if inactive bodies should be ignored
        results - the list of overlapping bodies and fixtures
        Returns:
        boolean true if an overlap was found
        Since:
        3.1.9
        See Also:
        detect(Convex, Transform, Filter, boolean, boolean, boolean, List)
      • detect

        public boolean detect​(Convex convex,
                              Filter filter,
                              boolean ignoreSensors,
                              boolean ignoreInactive,
                              boolean includeCollisionData,
                              java.util.List<DetectResult> results)
        Returns true if the given Convex overlaps a body in the world.

        If this method returns true, the results list will contain the bodies and fixtures that the convex overlaps.

        Use the Body.isInContact(Body) method instead if you want to test if two bodies are colliding.

        Use the includeCollisionData parameter to have the Penetration object filled in the DetectResults. Including this information will have a performance impact.

        Parameters:
        convex - the convex shape in world coordinates
        filter - the Filter to use against the fixtures; can be null
        ignoreSensors - true if sensor fixtures should be ignored
        ignoreInactive - true if inactive bodies should be ignored
        includeCollisionData - true if the overlap Penetration should be returned
        results - the list of overlapping bodies and fixtures
        Returns:
        boolean true if an overlap was found
        Since:
        3.1.9
      • detect

        public boolean detect​(Convex convex,
                              Transform transform,
                              java.util.List<DetectResult> results)
        Returns true if the given Convex overlaps a body in the world.

        If this method returns true, the results list will contain the bodies and fixtures that the convex overlaps.

        Use the Body.isInContact(Body) method instead if you want to test if two bodies are colliding.

        The returned results may include sensor fixutres.

        Inactive bodies are ignored in this test.

        The results from this test will not include Penetration objects.

        Parameters:
        convex - the convex shape in local coordinates
        transform - the convex shape's world transform
        results - the list of overlapping bodies and fixtures
        Returns:
        boolean true if an overlap was found
        Since:
        3.1.9
        See Also:
        detect(Convex, Transform, boolean, List)
      • detect

        public boolean detect​(Convex convex,
                              Transform transform,
                              boolean ignoreSensors,
                              java.util.List<DetectResult> results)
        Returns true if the given Convex overlaps a body in the world.

        If this method returns true, the results list will contain the bodies and fixtures that the convex overlaps.

        Use the Body.isInContact(Body) method instead if you want to test if two bodies are colliding.

        Inactive bodies are ignored in this test.

        The results from this test will not include Penetration objects.

        Parameters:
        convex - the convex shape in local coordinates
        transform - the convex shape's world transform
        ignoreSensors - true if sensor fixtures should be ignored
        results - the list of overlapping bodies and fixtures
        Returns:
        boolean true if an overlap was found
        Since:
        3.1.9
        See Also:
        detect(Convex, Transform, boolean, boolean, List)
      • detect

        public boolean detect​(Convex convex,
                              Transform transform,
                              boolean ignoreSensors,
                              boolean ignoreInactive,
                              java.util.List<DetectResult> results)
        Returns true if the given Convex overlaps a body in the world.

        If this method returns true, the results list will contain the bodies and fixtures that the convex overlaps.

        Use the Body.isInContact(Body) method instead if you want to test if two bodies are colliding.

        The results from this test will not include Penetration objects.

        Parameters:
        convex - the convex shape in local coordinates
        transform - the convex shape's world transform
        ignoreSensors - true if sensor fixtures should be ignored
        ignoreInactive - true if inactive bodies should be ignored
        results - the list of overlapping bodies and fixtures
        Returns:
        boolean true if an overlap was found
        Since:
        3.1.9
        See Also:
        detect(Convex, Transform, Filter, boolean, boolean, List)
      • detect

        public boolean detect​(Convex convex,
                              Transform transform,
                              Filter filter,
                              boolean ignoreSensors,
                              boolean ignoreInactive,
                              java.util.List<DetectResult> results)
        Returns true if the given Convex overlaps a body in the world.

        If this method returns true, the results list will contain the bodies and fixtures that the convex overlaps.

        Use the Body.isInContact(Body) method instead if you want to test if two bodies are colliding.

        The results from this test will not include Penetration objects.

        Parameters:
        convex - the convex shape in local coordinates
        transform - the convex shape's world transform
        filter - the Filter to use against the fixtures; can be null
        ignoreSensors - true if sensor fixtures should be ignored
        ignoreInactive - true if inactive bodies should be ignored
        results - the list of overlapping bodies and fixtures
        Returns:
        boolean true if an overlap was found
        Since:
        3.1.9
        See Also:
        detect(Convex, Transform, Filter, boolean, boolean, boolean, List)
      • detect

        public boolean detect​(Convex convex,
                              Transform transform,
                              Filter filter,
                              boolean ignoreSensors,
                              boolean ignoreInactive,
                              boolean includeCollisionData,
                              java.util.List<DetectResult> results)
        Returns true if the given Convex overlaps a body in the world.

        If this method returns true, the results list will contain the bodies and fixtures that the convex overlaps.

        Use the Body.isInContact(Body) method instead if you want to test if two bodies are colliding.

        Use the includeCollisionData parameter to have the Penetration object filled in the DetectResults. Including this information will have a performance impact.

        Parameters:
        convex - the convex shape in local coordinates
        transform - the convex shape's world transform
        filter - the Filter to use against the fixtures; can be null
        ignoreSensors - true if sensor fixtures should be ignored
        ignoreInactive - true if inactive bodies should be ignored
        includeCollisionData - true if the overlap Penetration should be returned
        results - the list of overlapping bodies and fixtures
        Returns:
        boolean true if an overlap was found
        Since:
        3.1.9
      • detect

        public boolean detect​(AABB aabb,
                              Body body,
                              boolean ignoreSensors,
                              java.util.List<DetectResult> results)
        Returns true if the given AABB overlaps the given body in the world.

        If this method returns true, the results list will contain the bodies and fixtures that the AABB overlaps.

        Use the Body.isInContact(Body) method instead if you want to test if two bodies are colliding.

        Parameters:
        aabb - the AABB in world coordinates
        body - the Body to test against
        ignoreSensors - true if sensor fixtures should be ignored
        results - the list of overlapping bodies and fixtures
        Returns:
        boolean true if an overlap was found
        Since:
        3.1.9
      • detect

        public boolean detect​(AABB aabb,
                              Body body,
                              Filter filter,
                              boolean ignoreSensors,
                              java.util.List<DetectResult> results)
        Returns true if the given AABB overlaps the given body in the world.

        If this method returns true, the results list will contain the bodies and fixtures that the AABB overlaps.

        Use the Body.isInContact(Body) method instead if you want to test if two bodies are colliding.

        Parameters:
        aabb - the AABB in world coordinates
        body - the Body to test against
        filter - the Filter to use against the fixtures; can be null
        ignoreSensors - true if sensor fixtures should be ignored
        results - the list of overlapping bodies and fixtures
        Returns:
        boolean true if an overlap was found
        Since:
        3.1.9
      • detect

        public boolean detect​(Convex convex,
                              Body body,
                              boolean ignoreSensors,
                              java.util.List<DetectResult> results)
        Returns true if the given Convex overlaps the given body in the world.

        If this method returns true, the results list will contain the bodies and fixtures that the convex overlaps.

        Use the Body.isInContact(Body) method instead if you want to test if two bodies are colliding.

        The results from this test will not include Penetration objects.

        Parameters:
        convex - the Convex in world coordinates
        body - the Body to test against
        ignoreSensors - true if sensor fixtures should be ignored
        results - the list of overlapping bodies and fixtures
        Returns:
        boolean true if an overlap was found
        Since:
        3.1.9
      • detect

        public boolean detect​(Convex convex,
                              Body body,
                              Filter filter,
                              boolean ignoreSensors,
                              java.util.List<DetectResult> results)
        Returns true if the given Convex overlaps the given body in the world.

        If this method returns true, the results list will contain the bodies and fixtures that the convex overlaps.

        Use the Body.isInContact(Body) method instead if you want to test if two bodies are colliding.

        The results from this test will not include Penetration objects.

        Parameters:
        convex - the Convex in world coordinates
        body - the Body to test against
        filter - the Filter to use against the fixtures; can be null
        ignoreSensors - true if sensor fixtures should be ignored
        results - the list of overlapping bodies and fixtures
        Returns:
        boolean true if an overlap was found
        Since:
        3.1.9
      • detect

        public boolean detect​(Convex convex,
                              Body body,
                              Filter filter,
                              boolean ignoreSensors,
                              boolean includeCollisionData,
                              java.util.List<DetectResult> results)
        Returns true if the given Convex overlaps the given body in the world.

        If this method returns true, the results list will contain the bodies and fixtures that the convex overlaps.

        Use the Body.isInContact(Body) method instead if you want to test if two bodies are colliding.

        Use the includeCollisionData parameter to have the Penetration object filled in the DetectResults. Including this information negatively impacts performance.

        Parameters:
        convex - the Convex in world coordinates
        body - the Body to test against
        filter - the Filter to use against the fixtures; can be null
        includeCollisionData - true if the overlap Penetration should be returned
        ignoreSensors - true if sensor fixtures should be ignored
        results - the list of overlapping bodies and fixtures
        Returns:
        boolean true if an overlap was found
        Since:
        3.1.9
      • detect

        public boolean detect​(Convex convex,
                              Transform transform,
                              Body body,
                              boolean ignoreSensors,
                              java.util.List<DetectResult> results)
        Returns true if the given Convex overlaps the given body in the world.

        If this method returns true, the results list will contain the bodies and fixtures that the convex overlaps.

        Use the Body.isInContact(Body) method instead if you want to test if two bodies are colliding.

        The results from this test will not include Penetration objects.

        Parameters:
        convex - the Convex in local coordinates
        transform - the convex shape's world Transform
        body - the Body to test against
        ignoreSensors - true if sensor fixtures should be ignored
        results - the list of overlapping bodies and fixtures
        Returns:
        boolean true if an overlap was found
        Since:
        3.1.9
      • detect

        public boolean detect​(Convex convex,
                              Transform transform,
                              Body body,
                              Filter filter,
                              boolean ignoreSensors,
                              java.util.List<DetectResult> results)
        Returns true if the given Convex overlaps the given body in the world.

        If this method returns true, the results list will contain the bodies and fixtures that the convex overlaps.

        Use the Body.isInContact(Body) method instead if you want to test if two bodies are colliding.

        The results from this test will not include Penetration objects.

        Parameters:
        convex - the Convex in local coordinates
        transform - the convex shape's world Transform
        body - the Body to test against
        filter - the Filter to use against the fixtures; can be null
        ignoreSensors - true if sensor fixtures should be ignored
        results - the list of overlapping bodies and fixtures
        Returns:
        boolean true if an overlap was found
        Since:
        3.1.9
      • detect

        public boolean detect​(Convex convex,
                              Transform transform,
                              Body body,
                              Filter filter,
                              boolean ignoreSensors,
                              boolean includeCollisionData,
                              java.util.List<DetectResult> results)
        Returns true if the given Convex overlaps the given body in the world.

        If this method returns true, the results list will contain the bodies and fixtures that the convex overlaps.

        Use the Body.isInContact(Body) method instead if you want to test if two bodies are colliding.

        Use the includeCollisionData parameter to have the Penetration object filled in the DetectResults. Including this information negatively impacts performance.

        Parameters:
        convex - the Convex in local coordinates
        transform - the convex shape's world Transform
        body - the Body to test against
        filter - the Filter to use against the fixtures; can be null
        includeCollisionData - true if the overlap Penetration should be returned
        ignoreSensors - true if sensor fixtures should be ignored
        results - the list of overlapping bodies and fixtures
        Returns:
        boolean true if an overlap was found
        Since:
        3.1.9
      • shift

        public void shift​(Vector2 shift)
        Shifts the coordinates of the entire world by the given amount.
         NewPosition = OldPosition + shift
         
        This method is useful in situations where the world is very large causing very large numbers to be used in the computations. Shifting the coordinate system allows the computations to be localized and retain accuracy.

        This method modifies the coordinates of every body and joint in the world.

        Adding joints or bodies after this method is called should consider that everything has been shifted.

        This method does NOT require a call to setUpdateRequired(boolean).

        Specified by:
        shift in interface Shiftable
        Parameters:
        shift - the distance to shift along the x and y axes
        Since:
        3.2.0
      • addBody

        public void addBody​(Body body)
        Adds the given Body to the World.
        Parameters:
        body - the Body to add
        Throws:
        java.lang.NullPointerException - if body is null
        java.lang.IllegalArgumentException - if body has already been added to this world or if its a member of another world instance
        Since:
        3.1.1
      • addJoint

        public void addJoint​(Joint joint)
        Adds the given Joint to the World.
        Parameters:
        joint - the Joint to add
        Throws:
        java.lang.NullPointerException - if joint is null
        java.lang.IllegalArgumentException - if joint has already been added to this world or if its a member of another world instance
        Since:
        3.1.1
      • containsBody

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

        public boolean containsJoint​(Joint joint)
        Returns true if this world contains the given joint.
        Parameters:
        joint - the Joint to test for
        Returns:
        boolean true if the joint is contained in this world
        Since:
        3.1.1
      • removeBody

        public boolean removeBody​(int index)
        Removes the Body at the given index from this World.

        Use the removeBody(int, boolean) method to enable implicit destruction notification.

        Parameters:
        index - the index of the body to remove.
        Returns:
        boolean true if the body was removed
        Since:
        3.2.0
      • removeBody

        public boolean removeBody​(int index,
                                  boolean notify)
        Removes the Body at the given index from this World.

        When a body is removed, joints and contacts may be implicitly destroyed. Pass true to the notify parameter to be notified of the destruction of these objects via the DestructionListeners.

        This method does not trigger ContactListener.end(ContactPoint) events for the contacts that are being removed.

        Parameters:
        index - the index of the body to remove.
        notify - true if implicit destruction should be notified
        Returns:
        boolean true if the body was removed
        Since:
        3.2.0
      • removeBody

        public boolean removeBody​(Body body)
        Removes the given Body from this World.

        Use the removeBody(Body, boolean) method to enable implicit destruction notification.

        Parameters:
        body - the Body to remove.
        Returns:
        boolean true if the body was removed
      • removeBody

        public boolean removeBody​(Body body,
                                  boolean notify)
        Removes the given Body from this World.

        When a body is removed, joints and contacts may be implicitly destroyed. Pass true to the notify parameter to be notified of the destruction of these objects via the DestructionListeners.

        This method does not trigger ContactListener.end(ContactPoint) events for the contacts that are being removed.

        Parameters:
        body - the Body to remove
        notify - true if implicit destruction should be notified
        Returns:
        boolean true if the body was removed
        Since:
        3.1.1
      • removeJoint

        public boolean removeJoint​(int index)
        Removes the Joint at the given index from this World.

        No other objects are implicitly destroyed with joints are removed.

        Parameters:
        index - the index of the Joint to remove
        Returns:
        boolean true if the Joint was removed
        Since:
        3.2.0
      • removeJoint

        public boolean removeJoint​(Joint joint)
        Removes the given Joint from this World.

        No other objects are implicitly destroyed with joints are removed.

        Parameters:
        joint - the Joint to remove
        Returns:
        boolean true if the Joint was removed
      • removeAllBodiesAndJoints

        public void removeAllBodiesAndJoints()
        Removes all the joints and bodies from this world.

        This method does not notify of destroyed objects.

        Since:
        3.1.1
        See Also:
        removeAllBodiesAndJoints(boolean)
      • removeAllBodiesAndJoints

        public void removeAllBodiesAndJoints​(boolean notify)
        Removes all the joints and bodies from this world.
        Parameters:
        notify - true if destruction of joints and contacts should be notified of by the DestructionListener
        Since:
        3.1.1
      • removeAllBodies

        public void removeAllBodies()
        This is a convenience method for the removeAllBodiesAndJoints() method since all joints will be removed when all bodies are removed anyway.

        This method does not notify of the destroyed contacts, joints, etc.

        Since:
        3.0.1
        See Also:
        removeAllBodies(boolean)
      • removeAllBodies

        public void removeAllBodies​(boolean notify)
        This is a convenience method for the removeAllBodiesAndJoints(boolean) method since all joints will be removed when all bodies are removed anyway.
        Parameters:
        notify - true if destruction of joints and contacts should be notified of by the DestructionListener
        Since:
        3.0.1
      • removeAllJoints

        public void removeAllJoints()
        Removes all Joints from this World.

        This method does not notify of the joints removed.

        Since:
        3.0.1
        See Also:
        removeAllJoints(boolean)
      • removeAllJoints

        public void removeAllJoints​(boolean notify)
        Removes all Joints from this World.
        Parameters:
        notify - true if destruction of joints should be notified of by the DestructionListener
        Since:
        3.0.1
      • isUpdateRequired

        public boolean isUpdateRequired()
        Returns true if upon the next time step the contacts must be updated.

        This is typically set via user code when something about the simulation changes that can affect collision detection.

        Returns:
        boolean
        See Also:
        setUpdateRequired(boolean)
      • setUpdateRequired

        public void setUpdateRequired​(boolean flag)
        Sets the update required flag.

        Set this flag to true if any of the following conditions have been met:

        • If a Body has been added or removed from the World
        • If a Body has been translated or rotated
        • If a Body's state has been manually changed via the Body.setActive(boolean) method
        • If a BodyFixture has been added or removed from a Body
        • If a BodyFixture's sensor flag has been manually changed via the BodyFixture.setSensor(boolean) method
        • If a BodyFixture's filter has been manually changed via the BodyFixture.setFilter(boolean) method
        • If a BodyFixture's restitution or friction coefficient has changed
        • If a BodyFixture's Shape has been translated or rotated
        • If a BodyFixture's Shape has been changed (vertices, radius, etc.)
        • If a Body's type has changed to or from Static (this is caused by the using setMassType(Mass.INFINITE/Mass.NORMAL) method)
        • If a Joint has been added or removed from the World in which the joined bodies should not be allowed to collide
        • If the World's CoefficientMixer has been changed
        Parameters:
        flag - the flag
      • getId

        @Deprecated
        public java.util.UUID getId()
        Deprecated.
        ID schemes should be implemented by the user where needed; since 3.4.0
        Returns the world id.
        Returns:
        UUID
        Since:
        3.2.0
      • getSettings

        public Settings getSettings()
        Returns the settings for this world.
        Returns:
        Settings
        Since:
        3.0.3
      • setSettings

        public void setSettings​(Settings settings)
        Sets the dynamics settings for this world.
        Parameters:
        settings - the desired settings
        Throws:
        java.lang.NullPointerException - if the given settings is null
        Since:
        3.0.3
      • setGravity

        public void setGravity​(Vector2 gravity)
        Sets the acceleration due to gravity.
        Parameters:
        gravity - the gravity in meters/second2
        Throws:
        java.lang.NullPointerException - if gravity is null
      • getGravity

        public Vector2 getGravity()
        Returns the acceleration due to gravity.
        Returns:
        Vector2 the gravity in meters/second2
      • setBounds

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

        public 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
      • getListeners

        public <T extends Listener> java.util.List<T> getListeners​(java.lang.Class<T> clazz)
        Returns the listeners that are of the given type (or sub types) of the given type.

        Returns an empty list if no listeners for the given type are found.

        Returns null if clazz is null.

        Example usage:

         world.getListeners(ContactListener.class);
         
        Type Parameters:
        T - the listener type
        Parameters:
        clazz - the type of listener to get
        Returns:
        List<T>
        Since:
        3.1.0
      • getListeners

        public <T extends Listener> void getListeners​(java.lang.Class<T> clazz,
                                                      java.util.List<T> listeners)
        Returns the listeners of the given type (or sub types) in the given list.

        This method does not clear the given listeners list before adding the listeners.

        If clazz or listeners is null, this method immediately returns.

        Example usage:

         List<ContactListener> list = ...;
         world.getListeners(ContactListener.class, list);
         
        Type Parameters:
        T - the listener type
        Parameters:
        clazz - the type of listener to get
        listeners - the list to add the listeners to
        Since:
        3.1.1
      • addListener

        public void addListener​(Listener listener)
        Adds the given listener to the list of listeners.
        Parameters:
        listener - the listener
        Throws:
        java.lang.NullPointerException - if the given listener is null
        java.lang.IllegalArgumentException - if the given listener has already been added to this world
        Since:
        3.1.0
      • containsListener

        public boolean containsListener​(Listener listener)
        Returns true if the given listener is already attached to this world.
        Parameters:
        listener - the listener
        Returns:
        boolean
        Since:
        3.1.1
      • removeListener

        public boolean removeListener​(Listener listener)
        Removes the given listener from this world.
        Parameters:
        listener - the listener to remove
        Returns:
        boolean true if the listener was removed
        Since:
        3.1.0
      • removeAllListeners

        public int removeAllListeners()
        Removes all the listeners.
        Returns:
        int the number of listeners removed
        Since:
        3.1.1
      • removeAllListeners

        public <T extends Listener> int removeAllListeners​(java.lang.Class<T> clazz)
        Removes all the listeners of the specified type (or sub types).

        Returns zero if the given type is null or there are zero listeners attached.

        Example usage:

         world.removeAllListeners(ContactListener.class);
         
        Type Parameters:
        T - the listener type
        Parameters:
        clazz - the listener type
        Returns:
        int the number of listeners removed
        Since:
        3.1.1
      • getListenerCount

        public int getListenerCount()
        Returns the total number of listeners attached to this world.
        Returns:
        int
        Since:
        3.1.1
      • getListenerCount

        public <T extends Listener> int getListenerCount​(java.lang.Class<T> clazz)
        Returns the total number of listeners of the given type (or sub types) attached to this world.

        Returns zero if the given class type is null.

        Example usage:

         world.getListenerCount(BoundsListener.class);
         
        Type Parameters:
        T - the listener type
        Parameters:
        clazz - the listener type
        Returns:
        int
        Since:
        3.1.1
      • setBroadphaseDetector

        public void setBroadphaseDetector​(BroadphaseDetector<Body,​BodyFixture> broadphaseDetector)
        Sets the broad-phase collision detection algorithm.
        Parameters:
        broadphaseDetector - the broad-phase collision detection algorithm
        Throws:
        java.lang.NullPointerException - if broadphaseDetector is null
      • setDetectBroadphaseFilter

        public void setDetectBroadphaseFilter​(BroadphaseFilter<Body,​BodyFixture> filter)
        Sets the BroadphaseFilter used when detecting collisions for each time step.

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

        Parameters:
        filter - the filter
        Since:
        3.2.2
      • setNarrowphaseDetector

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

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

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

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

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

        public RaycastDetector getRaycastDetector()
        Returns the raycast detector.
        Returns:
        RaycastDetector the raycast detector
        Since:
        2.0.0
      • setCoefficientMixer

        public void setCoefficientMixer​(CoefficientMixer coefficientMixer)
        Sets the CoefficientMixer.

        A CoefficientMixer is an implementation of mixing functions for various coefficients used in contact solving. Common coefficients are restitution and friction. Since each BodyFixture can have it's own value for these coefficients, the CoefficientMixer is used to mathematically combine them into one coefficient to be used in contact resolution.

        CoefficientMixer.DEFAULT_MIXER is the default.

        Parameters:
        coefficientMixer - the coefficient mixer
        Throws:
        java.lang.NullPointerException - if coefficientMixer is null
        See Also:
        CoefficientMixer
      • setContactManager

        public void setContactManager​(ContactManager contactManager)
        Sets the ContactManager.

        A ContactManager manages the contacts detected in the detect() method and performs notification of ContactListeners. ContactManagers can also contain specialized logic for improving performance and simulation quality.

        Changing the contact manager requires an update to be performed on the next update of this world and any cached information will be lost.

        The default is the DefaultContactManager.

        Parameters:
        contactManager - the contact manager
        Throws:
        java.lang.NullPointerException - if contactManager is null
        Since:
        3.2.0
        See Also:
        ContactManager
      • getUserData

        public java.lang.Object getUserData()
        Description copied from interface: DataContainer
        Gets the custom user data.
        Specified by:
        getUserData in interface DataContainer
        Returns:
        Object will return null if not set
      • setUserData

        public void setUserData​(java.lang.Object userData)
        Description copied from interface: DataContainer
        Sets the custom user data to the given data.
        Specified by:
        setUserData in interface DataContainer
        Parameters:
        userData - the user data
      • getBodyCount

        public int getBodyCount()
        Returns the number of Bodys in this World.
        Returns:
        int the number of bodies
      • getBody

        public Body getBody​(int index)
        Returns the Body at the given index.
        Parameters:
        index - the index
        Returns:
        Body
      • getBodies

        public java.util.List<Body> 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<Body>
        Since:
        3.1.5
        See Also:
        getBodyIterator()
      • getBodyIterator

        public java.util.Iterator<Body> getBodyIterator()
        Returns an iterator for iterating over the bodies in this world.

        The returned iterator supports the remove method.

        Returns:
        Iterator<Body>
        Since:
        3.2.0
      • getJointCount

        public int getJointCount()
        Returns the number of Joints in this World.
        Returns:
        int the number of joints
      • getJoint

        public Joint getJoint​(int index)
        Returns the Joint at the given index.
        Parameters:
        index - the index
        Returns:
        Joint
      • getJoints

        public java.util.List<Joint> getJoints()
        Returns an unmodifiable list containing all the joints in this world.

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

        Returns:
        List<Joint>
        Since:
        3.1.5
        See Also:
        getJointIterator()
      • getJointIterator

        public java.util.Iterator<Joint> getJointIterator()
        Returns an iterator for iterating over the joints in this world.

        The returned iterator supports the remove method.

        Returns:
        Iterator<Joint>
        Since:
        3.2.0
      • getStep

        public Step getStep()
        Returns the Step object used to advance the simulation.

        The returned object contains the step information (elapsed time) for the last and the previous time step.

        Returns:
        Step the current step object
      • isEmpty

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

        public double getAccumulatedTime()
        Returns the current accumulated time.

        This is the time that has elapsed since the last step of the engine.

        This time is used and/or accumulated on each call of the update(double) and update(double, int) methods.

        This time is reduced by the step frequency for each step of the engine.

        Returns:
        double
        Since:
        3.1.10
      • setAccumulatedTime

        public void setAccumulatedTime​(double elapsedTime)
        Sets the current accumulated time.

        A typical use case would be to throw away any remaining time that the update(double) or update(double, int) methods didn't use:

         boolean updated = world.update(elapsedTime);
         // the check if the world actually updated is crutial in this example
         if (updated) {
                // throw away any remaining time we didnt use
                world.setAccumulatedTime(0);
         }
         
        Or, in the case of reusing the same World object, you could use this method to clear any accumulated time.

        If elapsedTime is less than zero, this method immediately returns.

        Parameters:
        elapsedTime - the desired elapsed time
        Since:
        3.1.10
        See Also:
        getAccumulatedTime()