Module org.dyn4j

Class AbstractPhysicsBody

    • Constructor Detail

      • AbstractPhysicsBody

        public AbstractPhysicsBody()
        Default constructor.
      • AbstractPhysicsBody

        public AbstractPhysicsBody​(int fixtureCount)
        Optional constructor.

        Creates a new AbstractPhysicsBody using the given estimated fixture count. Assignment of the initial fixture count allows sizing of internal structures for optimal memory/performance. This estimated fixture count is not a limit on the number of fixtures.

        Parameters:
        fixtureCount - the estimated number of fixtures
        Throws:
        IllegalArgumentException - if fixtureCount less than zero
        Since:
        3.1.1
    • Method Detail

      • setMass

        @Deprecated
        public AbstractPhysicsBody setMass()
        Deprecated.
        Description copied from interface: PhysicsBody
        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.

        Specified by:
        setMass in interface PhysicsBody
        Returns:
        PhysicsBody this body
      • setMass

        public AbstractPhysicsBody setMass​(MassType type)
        Description copied from interface: PhysicsBody
        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.

        Specified by:
        setMass in interface PhysicsBody
        Parameters:
        type - the mass type
        Returns:
        PhysicsBody this body
      • setMassType

        public AbstractPhysicsBody setMassType​(MassType type)
        Description copied from interface: PhysicsBody
        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.

        Specified by:
        setMassType in interface PhysicsBody
        Parameters:
        type - the desired type
        Returns:
        PhysicsBody this body
      • applyImpulse

        public AbstractPhysicsBody applyImpulse​(Vector2 impulse)
        Description copied from interface: PhysicsBody
        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.

        Specified by:
        applyImpulse in interface PhysicsBody
        Parameters:
        impulse - the impulse to apply
        Returns:
        PhysicsBody this body
      • applyImpulse

        public AbstractPhysicsBody applyImpulse​(double impulse)
        Description copied from interface: PhysicsBody
        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.

        Specified by:
        applyImpulse in interface PhysicsBody
        Parameters:
        impulse - the impulse to apply
        Returns:
        PhysicsBody this body
      • applyImpulse

        public AbstractPhysicsBody applyImpulse​(Vector2 impulse,
                                                Vector2 point)
        Description copied from interface: PhysicsBody
        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.

        Specified by:
        applyImpulse in interface PhysicsBody
        Parameters:
        impulse - the impulse to apply
        point - the world space point to apply the impulse
        Returns:
        PhysicsBody this body
      • clearAccumulatedForce

        public void clearAccumulatedForce()
        Description copied from interface: PhysicsBody
        Clears the forces stored in the force accumulator.

        Renamed from clearForces (3.0.0 and below).

        Specified by:
        clearAccumulatedForce in interface PhysicsBody
      • clearAccumulatedTorque

        public void clearAccumulatedTorque()
        Description copied from interface: PhysicsBody
        Clears the torques stored in the torque accumulator.

        Renamed from clearTorques (3.0.0 and below).

        Specified by:
        clearAccumulatedTorque in interface PhysicsBody
      • integrateVelocity

        public void integrateVelocity​(Vector2 gravity,
                                      TimeStep timestep,
                                      Settings settings)
        Description copied from interface: PhysicsBody
        Integrates the forces, torques, and gravity to update the linear and angular velocity of this body.
        Specified by:
        integrateVelocity in interface PhysicsBody
        Parameters:
        gravity - the world gravity
        timestep - the timestep information
        settings - the world settings
      • integratePosition

        public void integratePosition​(TimeStep timestep,
                                      Settings settings)
        Description copied from interface: PhysicsBody
        Integrates the linear and angular velocities to update the position and rotation of this body
        Specified by:
        integratePosition in interface PhysicsBody
        Parameters:
        timestep - the timestep information
        settings - the world settings
      • updateAtRestTime

        public double updateAtRestTime​(TimeStep timestep,
                                       Settings settings)
        Description copied from interface: PhysicsBody
        Updates the at-rest time for this body based on the given timestep and returns the current at-rest time.

        For PhysicsBody.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.

        Specified by:
        updateAtRestTime in interface PhysicsBody
        Parameters:
        timestep - the timestep information
        settings - the world settings
        Returns:
        double
      • isStatic

        public boolean isStatic()
        Description copied from interface: PhysicsBody
        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.
        Specified by:
        isStatic in interface PhysicsBody
        Returns:
        boolean
      • isKinematic

        public boolean isKinematic()
        Description copied from interface: PhysicsBody
        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).
        Specified by:
        isKinematic in interface PhysicsBody
        Returns:
        boolean
      • setAtRestDetectionEnabled

        public void setAtRestDetectionEnabled​(boolean flag)
        Description copied from interface: PhysicsBody
        Determines whether this PhysicsBody can participate in automatic at-rest detection.
        Specified by:
        setAtRestDetectionEnabled in interface PhysicsBody
        Parameters:
        flag - true if it should
      • setAsleep

        @Deprecated
        public void setAsleep​(boolean flag)
        Deprecated.
        Description copied from interface: PhysicsBody
        Sets whether this PhysicsBody is awake or not.

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

        Specified by:
        setAsleep in interface PhysicsBody
        Parameters:
        flag - true if the body should be put to sleep
      • setAtRest

        public void setAtRest​(boolean flag)
        Description copied from interface: PhysicsBody
        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.

        Specified by:
        setAtRest in interface PhysicsBody
        Parameters:
        flag - true if the body should be at-rest
      • setBullet

        public void setBullet​(boolean flag)
        Description copied from interface: PhysicsBody
        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.

        Specified by:
        setBullet in interface PhysicsBody
        Parameters:
        flag - true if this PhysicsBody is a bullet
      • createSweptAABB

        public AABB createSweptAABB()
        Description copied from interface: PhysicsBody
        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.

        Specified by:
        createSweptAABB in interface PhysicsBody
        Returns:
        AABB
      • createSweptAABB

        public AABB createSweptAABB​(Transform initialTransform,
                                    Transform finalTransform)
        Description copied from interface: PhysicsBody
        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.

        Specified by:
        createSweptAABB in interface PhysicsBody
        Parameters:
        initialTransform - the initial Transform
        finalTransform - the final Transform
        Returns:
        AABB
      • getChangeInPosition

        public Vector2 getChangeInPosition()
        Description copied from interface: PhysicsBody
        Returns the change in position computed from last frame's transform and this frame's transform.
        Specified by:
        getChangeInPosition in interface PhysicsBody
        Returns:
        Vector2
      • getChangeInOrientation

        public double getChangeInOrientation()
        Description copied from interface: PhysicsBody
        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.

        Specified by:
        getChangeInOrientation in interface PhysicsBody
        Returns:
        double
      • getLinearVelocity

        public Vector2 getLinearVelocity​(Vector2 point)
        Description copied from interface: PhysicsBody
        Returns the velocity of this body at the given world space point.
        Specified by:
        getLinearVelocity in interface PhysicsBody
        Parameters:
        point - the point in world space
        Returns:
        Vector2
      • getAngularVelocity

        public double getAngularVelocity()
        Description copied from interface: PhysicsBody
        Returns the angular velocity.
        Specified by:
        getAngularVelocity in interface PhysicsBody
        Returns:
        double
      • getForce

        public Vector2 getForce()
        Description copied from interface: PhysicsBody
        Returns the force applied in the last iteration.

        This is the accumulated force from the last iteration.

        Specified by:
        getForce in interface PhysicsBody
        Returns:
        Vector2
      • getTorque

        public double getTorque()
        Description copied from interface: PhysicsBody
        Returns the torque applied in the last iteration.

        This is the accumulated torque from the last iteration.

        Specified by:
        getTorque in interface PhysicsBody
        Returns:
        double
      • getAccumulatedTorque

        public double getAccumulatedTorque()
        Description copied from interface: PhysicsBody
        Returns the total torque currently stored in the torque accumulator.
        Specified by:
        getAccumulatedTorque in interface PhysicsBody
        Returns:
        double
      • setLinearDamping

        public void setLinearDamping​(double linearDamping)
        Description copied from interface: PhysicsBody
        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.

        Specified by:
        setLinearDamping in interface PhysicsBody
        Parameters:
        linearDamping - the linear damping; must be greater than or equal to zero
      • setAngularDamping

        public void setAngularDamping​(double angularDamping)
        Description copied from interface: PhysicsBody
        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.

        Specified by:
        setAngularDamping in interface PhysicsBody
        Parameters:
        angularDamping - the angular damping; must be greater than or equal to zero
      • setGravityScale

        public void setGravityScale​(double scale)
        Description copied from interface: PhysicsBody
        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.

        Specified by:
        setGravityScale in interface PhysicsBody
        Parameters:
        scale - the gravity scale for this body