Module org.dyn4j

Interface PhysicsBody

    • Method Detail

      • setMass

        @Deprecated
        PhysicsBody setMass()
        Deprecated.
        removed in 3.2.0 use setMass(MassType) instead
        This method should be called after fixture modification is complete.

        This method will calculate a total mass for the body given the masses of the fixtures.

        This method will always set this body's mass type to Normal.

        Returns:
        PhysicsBody this body
      • setMass

        PhysicsBody setMass​(MassType type)
        This method should be called after fixture modification is complete.

        This method will calculate a total mass for the body given the masses of the attached fixtures.

        A MassType can be used to create special mass types.

        Parameters:
        type - the mass type
        Returns:
        PhysicsBody this body
      • setMassType

        PhysicsBody setMassType​(MassType type)
        Sets the MassType of this PhysicsBody.

        This method does not compute/recompute the mass of the body but solely sets the mass type to one of the special types.

        Since its possible to create a Mass object with zero mass and/or zero inertia (Mass m = new Mass(new Vector2(), 0, 0); for example), setting the type to something other than MassType.INFINITE can have undefined results.

        Parameters:
        type - the desired type
        Returns:
        PhysicsBody this body
        Throws:
        NullPointerException - if the given mass type is null
        Since:
        2.2.3
      • applyForce

        PhysicsBody applyForce​(Vector2 force)
        Applies the given force to this PhysicsBody.

        This method will wake-up the body if its sleeping.

        This method does not apply the force if this body returns zero from the Mass.getMass() method.

        The force is not applied immediately, but instead stored in the force accumulator (getAccumulatedForce()). This is to preserve the last time step's computed force (getForce().

        The force is assumed to be in world space coordinates.

        Parameters:
        force - the force
        Returns:
        PhysicsBody this body
        Throws:
        NullPointerException - if force is null
        Since:
        3.1.1
      • applyForce

        PhysicsBody applyForce​(Force force)
        Applies the given Force to this PhysicsBody.

        This method will wake-up the body if its sleeping.

        This method does not apply the force if this body returns zero from the Mass.getMass() method.

        The force is not applied immediately, but instead stored in the force accumulator (getAccumulatedForce()). This is to preserve the last time step's computed force (getForce().

        The force is assumed to be in world space coordinates.

        Parameters:
        force - the force
        Returns:
        PhysicsBody this body
        Throws:
        NullPointerException - if force is null
        Since:
        3.1.1
      • applyTorque

        PhysicsBody applyTorque​(double torque)
        Applies the given torque about the center of this PhysicsBody.

        This method will wake-up the body if its sleeping.

        This method does not apply the torque if this body returns zero from the Mass.getInertia() method.

        The torque is not applied immediately, but instead stored in the torque accumulator (getAccumulatedTorque()). This is to preserve the last time step's computed torque (getTorque().

        Parameters:
        torque - the torque about the center
        Returns:
        PhysicsBody this body
        Since:
        3.1.1
      • applyForce

        PhysicsBody applyForce​(Vector2 force,
                               Vector2 point)
        Applies the given force to this PhysicsBody at the given point (torque).

        This method will wake-up the body if its sleeping.

        This method does not apply the force if this body returns zero from the Mass.getMass() method nor will it apply the torque if this body returns zero from the Mass.getInertia() method.

        The force/torque is not applied immediately, but instead stored in the force/torque accumulators (getAccumulatedForce() and getAccumulatedTorque()). This is to preserve the last time step's computed force (getForce() and torque (getTorque()).

        The force and point are assumed to be in world space coordinates.

        Parameters:
        force - the force
        point - the application point in world coordinates
        Returns:
        PhysicsBody this body
        Throws:
        NullPointerException - if force or point is null
        Since:
        3.1.1
      • applyImpulse

        PhysicsBody applyImpulse​(Vector2 impulse)
        Applies a linear impulse to this PhysicsBody at its center of mass.

        This method will wake-up the body if its sleeping.

        This method does not apply the impulse if this body's mass returns zero from the Mass.getInertia() method.

        NOTE: Applying an impulse differs from applying a force and/or torque. Forces and torques are stored in accumulators, but impulses are applied to the velocities of the body immediately.

        The impulse is assumed to be in world space coordinates.

        Parameters:
        impulse - the impulse to apply
        Returns:
        PhysicsBody this body
        Throws:
        NullPointerException - if impulse is null
        Since:
        3.1.1
      • applyImpulse

        PhysicsBody applyImpulse​(double impulse)
        Applies an angular impulse to this PhysicsBody about its center of mass.

        This method will wake-up the body if its sleeping.

        This method does not apply the impulse if this body's inertia returns zero from the Mass.getInertia() method.

        NOTE: Applying an impulse differs from applying a force and/or torque. Forces and torques are stored in accumulators, but impulses are applied to the velocities of the body immediately.

        Parameters:
        impulse - the impulse to apply
        Returns:
        PhysicsBody this body
        Since:
        3.1.1
      • applyImpulse

        PhysicsBody applyImpulse​(Vector2 impulse,
                                 Vector2 point)
        Applies an impulse to this PhysicsBody at the given point.

        This method will wake-up the body if its sleeping.

        This method does not apply the linear impulse if this body returns zero from the Mass.getMass() method nor will it apply the angular impulse if this body returns zero from the Mass.getInertia() method.

        NOTE: Applying an impulse differs from applying a force and/or torque. Forces and torques are stored in accumulators, but impulses are applied to the velocities of the body immediately.

        The impulse and point are assumed to be in world space coordinates.

        Parameters:
        impulse - the impulse to apply
        point - the world space point to apply the impulse
        Returns:
        PhysicsBody this body
        Throws:
        NullPointerException - if impulse or point is null
        Since:
        3.1.1
      • clearForce

        void clearForce()
        Clears the last time step's force on the PhysicsBody.
      • clearAccumulatedForce

        void clearAccumulatedForce()
        Clears the forces stored in the force accumulator.

        Renamed from clearForces (3.0.0 and below).

        Since:
        3.0.1
      • clearTorque

        void clearTorque()
        Clears the last time step's torque on the PhysicsBody.
      • clearAccumulatedTorque

        void clearAccumulatedTorque()
        Clears the torques stored in the torque accumulator.

        Renamed from clearTorques (3.0.0 and below).

        Since:
        3.0.1
      • integrateVelocity

        void integrateVelocity​(Vector2 gravity,
                               TimeStep timestep,
                               Settings settings)
        Integrates the forces, torques, and gravity to update the linear and angular velocity of this body.
        Parameters:
        gravity - the world gravity
        timestep - the timestep information
        settings - the world settings
      • integratePosition

        void integratePosition​(TimeStep timestep,
                               Settings settings)
        Integrates the linear and angular velocities to update the position and rotation of this body
        Parameters:
        timestep - the timestep information
        settings - the world settings
      • updateAtRestTime

        double updateAtRestTime​(TimeStep timestep,
                                Settings settings)
        Updates the at-rest time for this body based on the given timestep and returns the current at-rest time.

        For isStatic() bodies, this method will return -1 to indicate that this body can always be at-rest since it's velocity is zero and cannot be moved.

        Parameters:
        timestep - the timestep information
        settings - the world settings
        Returns:
        double
      • isStatic

        boolean isStatic()
        Returns true if this body's mass type is MassType.INFINITE and the linear and angular velocity are close to zero (as determined by Epsilon.E.
        Returns:
        boolean
      • isKinematic

        boolean isKinematic()
        Returns true if this body's mass type is MassType.INFINITE and either the linear or angular velocity are NOT zero (i.e. it's moving).
        Returns:
        boolean
      • isDynamic

        boolean isDynamic()
        Returns true if this body's mass type is NOT MassType.INFINITE.
        Returns:
        boolean
      • isAutoSleepingEnabled

        @Deprecated
        boolean isAutoSleepingEnabled()
        Deprecated.
        Deprecated in 4.0.0. Use isAtRestDetectionEnabled() instead.
        Returns true if this PhysicsBody is allowed to be put to sleep automatically.
        Returns:
        boolean
        Since:
        1.2.0
      • setAtRestDetectionEnabled

        void setAtRestDetectionEnabled​(boolean flag)
        Determines whether this PhysicsBody can participate in automatic at-rest detection.
        Parameters:
        flag - true if it should
        Since:
        4.0.0
      • isAtRestDetectionEnabled

        boolean isAtRestDetectionEnabled()
        Returns true if this PhysicsBody can participate in automatic at-rest detection.
        Returns:
        boolean
        Since:
        4.0.0
      • setAsleep

        @Deprecated
        void setAsleep​(boolean flag)
        Deprecated.
        Deprecated in 4.0.0. Use setAtRest(boolean) instead.
        Sets whether this PhysicsBody is awake or not.

        If flag is true, this body's velocity, angular velocity, force, torque, and accumulators are cleared.

        Parameters:
        flag - true if the body should be put to sleep
      • isAsleep

        @Deprecated
        boolean isAsleep()
        Deprecated.
        Deprecated in 4.0.0. Use isAtRest() instead.
        Returns true if this PhysicsBody is sleeping.
        Returns:
        boolean
      • setAtRest

        void setAtRest​(boolean flag)
        Sets whether this PhysicsBody is at-rest or not.

        If flag is true, this body's velocity, angular velocity, force, torque, and accumulators are cleared.

        Parameters:
        flag - true if the body should be at-rest
        Since:
        4.0.0
      • isAtRest

        boolean isAtRest()
        Returns true if this PhysicsBody is at-rest.
        Returns:
        boolean
        Since:
        4.0.0
      • setBullet

        void setBullet​(boolean flag)
        Sets the bullet flag for this PhysicsBody.

        A bullet is a very fast moving body that requires continuous collision detection with all other PhysicsBodys to ensure that no collisions are missed.

        Parameters:
        flag - true if this PhysicsBody is a bullet
        Since:
        1.2.0
      • createSweptAABB

        AABB createSweptAABB()
        Returns an AABB that contains the maximal space in which the CollisionBody exists from the initial transform to the final transform.

        This method takes the bounding circle, using the world center and rotation disc radius, at the initial and final transforms and creates an AABB containing both.

        This method will return a degenerate AABB if the body has zero fixtures. If this body has one or more fixtures, but didn't move, an AABB with a width and height equal to the rotation disc radius is returned.

        NOTE: To get an accurate result from this method, one of the setMass methods should be called to set the rotation disc radius before calling this method.

        Returns:
        AABB
        Since:
        3.1.1
      • createSweptAABB

        AABB createSweptAABB​(Transform initialTransform,
                             Transform finalTransform)
        Creates a swept AABB from the given start and end Transforms using the fixtures on this PhysicsBody.

        This method takes the bounding circle, using the world center and rotation disc radius, at the initial and final transforms and creates an AABB containing both.

        This method will return a degenerate AABB if the body has zero fixtures. If this body has one or more fixtures, but didn't move, an AABB with a width and height equal to the rotation disc radius is returned.

        NOTE: To get an accurate result from this method, one of the setMass methods should be called to set the rotation disc radius before calling this method.

        Parameters:
        initialTransform - the initial Transform
        finalTransform - the final Transform
        Returns:
        AABB
        Since:
        3.1.1
      • getChangeInPosition

        Vector2 getChangeInPosition()
        Returns the change in position computed from last frame's transform and this frame's transform.
        Returns:
        Vector2
        Since:
        3.1.5
      • getChangeInOrientation

        double getChangeInOrientation()
        Returns the change in orientation computed from last frame's transform and this frame's transform.

        This method will return a change in the range [0, 2π). This isn't as useful if the angular velocity is greater than 2π per time step. Since we don't have the timestep here, we can't compute the exact change in this case.

        If the angular velocity is zero, this method returns the minimum difference in orientation.

        Returns:
        double
        Since:
        3.1.5
      • getLinearVelocity

        Vector2 getLinearVelocity()
        Returns the linear velocity.
        Returns:
        Vector2
        Since:
        3.1.5
      • getLinearVelocity

        Vector2 getLinearVelocity​(Vector2 point)
        Returns the velocity of this body at the given world space point.
        Parameters:
        point - the point in world space
        Returns:
        Vector2
        Since:
        3.1.5
      • setLinearVelocity

        void setLinearVelocity​(double x,
                               double y)
        Sets the linear velocity.

        Call the setAsleep(boolean) method to wake up the PhysicsBody if the PhysicsBody is asleep and the velocity is not zero.

        Parameters:
        x - the linear velocity along the x-axis
        y - the linear velocity along the y-axis
        Since:
        3.1.5
      • getAngularVelocity

        double getAngularVelocity()
        Returns the angular velocity.
        Returns:
        double
      • setAngularVelocity

        void setAngularVelocity​(double angularVelocity)
        Sets the angular velocity in radians per second

        Call the setAsleep(boolean) method to wake up the PhysicsBody if the PhysicsBody is asleep and the velocity is not zero.

        Parameters:
        angularVelocity - the angular velocity in radians per second
      • getForce

        Vector2 getForce()
        Returns the force applied in the last iteration.

        This is the accumulated force from the last iteration.

        Returns:
        Vector2
      • getAccumulatedForce

        Vector2 getAccumulatedForce()
        Returns the total force currently stored in the force accumulator.
        Returns:
        Vector2
        Since:
        3.0.1
      • getTorque

        double getTorque()
        Returns the torque applied in the last iteration.

        This is the accumulated torque from the last iteration.

        Returns:
        double
      • getAccumulatedTorque

        double getAccumulatedTorque()
        Returns the total torque currently stored in the torque accumulator.
        Returns:
        double
        Since:
        3.0.1
      • getLinearDamping

        double getLinearDamping()
        Returns the linear damping.
        Returns:
        double
        See Also:
        setLinearDamping(double)
      • setLinearDamping

        void setLinearDamping​(double linearDamping)
        Sets the linear damping.

        Linear damping is used to reduce the linear velocity over time. The default is zero and larger values will cause the linear velocity to reduce faster.

        The units are seconds-1.

        Parameters:
        linearDamping - the linear damping; must be greater than or equal to zero
        Throws:
        IllegalArgumentException - if linearDamping is less than zero
      • getAngularDamping

        double getAngularDamping()
        Returns the angular damping.
        Returns:
        double
        See Also:
        setAngularDamping(double)
      • setAngularDamping

        void setAngularDamping​(double angularDamping)
        Sets the angular damping.

        Angular damping is used to reduce the angular velocity over time. The default is zero and larger values will cause the angular velocity to reduce faster.

        The units are seconds-1.

        Parameters:
        angularDamping - the angular damping; must be greater than or equal to zero
        Throws:
        IllegalArgumentException - if angularDamping is less than zero
      • getGravityScale

        double getGravityScale()
        Returns the gravity scale.
        Returns:
        double
        Since:
        3.0.0
        See Also:
        setGravityScale(double)
      • setGravityScale

        void setGravityScale​(double scale)
        Sets the gravity scale.

        The gravity scale is a multiplier applied to the acceleration due to gravity before applying the force of gravity to the body. This allows bodies to be affected differently under the same gravity.

        Parameters:
        scale - the gravity scale for this body
        Since:
        3.0.0