Module org.dyn4j

Class AbstractCollidable<T extends Fixture>

    • Field Detail

      • id

        protected final java.util.UUID id
        The Collidable's unique identifier
      • fixtures

        protected java.util.List<T extends Fixture> fixtures
        The Fixture list
      • radius

        protected double radius
        The the rotation disk radius
      • userData

        protected java.lang.Object userData
        The user data associated to this Collidable
    • Constructor Detail

      • AbstractCollidable

        public AbstractCollidable()
        Default constructor.
      • AbstractCollidable

        public AbstractCollidable​(int fixtureCount)
        Optional constructor.

        Creates a new AbstractCollidable 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
    • Method Detail

      • removeFixture

        public T removeFixture​(int index)
        Description copied from interface: Collidable
        Removes the Fixture at the given index.
        Specified by:
        removeFixture in interface Collidable<T extends Fixture>
        Parameters:
        index - the index
        Returns:
        T the fixture removed
      • rotate

        public void rotate​(double theta,
                           double x,
                           double y)
        Description copied from interface: Rotatable
        Rotates the object about the given coordinates.
        Specified by:
        rotate in interface Rotatable
        Parameters:
        theta - the angle of rotation in radians
        x - the x coordinate to rotate about
        y - the y coordinate to rotate about
      • rotate

        public void rotate​(Rotation rotation,
                           double x,
                           double y)
        Description copied from interface: Rotatable
        Rotates the object about the given point.
        Specified by:
        rotate in interface Rotatable
        Parameters:
        rotation - the Rotation representing the rotation amount
        x - the x coordinate to rotate about
        y - the y coordinate to rotate about
      • rotate

        public void rotate​(double theta,
                           Vector2 point)
        Description copied from interface: Rotatable
        Rotates the object about the given point.
        Specified by:
        rotate in interface Rotatable
        Parameters:
        theta - the angle of rotation in radians
        point - the point to rotate about
      • rotate

        public void rotate​(Rotation rotation,
                           Vector2 point)
        Description copied from interface: Rotatable
        Rotates the object about the given point.
        Specified by:
        rotate in interface Rotatable
        Parameters:
        rotation - the Rotation representing the rotation amount
        point - the point to rotate about
      • rotate

        public void rotate​(double theta)
        Description copied from interface: Rotatable
        Rotates the object about the origin.
        Specified by:
        rotate in interface Rotatable
        Parameters:
        theta - the angle of rotation in radians
      • rotate

        public void rotate​(Rotation rotation)
        Description copied from interface: Rotatable
        Rotates the object about the origin.
        Specified by:
        rotate in interface Rotatable
        Parameters:
        rotation - the Rotation representing the rotation amount
      • rotateAboutCenter

        public void rotateAboutCenter​(double theta)
        Rotates the Collidable about its center of mass.
        Specified by:
        rotateAboutCenter in interface Collidable<T extends Fixture>
        Parameters:
        theta - the angle of rotation in radians
      • translate

        public void translate​(double x,
                              double y)
        Description copied from interface: Translatable
        Translates the object the given amounts in the respective directions.
        Specified by:
        translate in interface Translatable
        Parameters:
        x - the translation in the x direction
        y - the translation in the y direction
      • translate

        public void translate​(Vector2 vector)
        Description copied from interface: Translatable
        Translates the object along the given vector.
        Specified by:
        translate in interface Translatable
        Parameters:
        vector - the translation along a vector
      • translateToOrigin

        public void translateToOrigin()
        Description copied from interface: Collidable
        Translates the center of the Collidable to the world space origin (0,0).

        This method is useful if bodies have a number of fixtures and the center is not at the origin. This method will reposition this Collidable so that the center is at the origin.

        Specified by:
        translateToOrigin in interface Collidable<T extends Fixture>
      • shift

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

        public T getFixture​(int index)
        Description copied from interface: Collidable
        Returns the Fixture at the given index.
        Specified by:
        getFixture in interface Collidable<T extends Fixture>
        Parameters:
        index - the index of the Fixture
        Returns:
        T the fixture
      • getFixture

        public T getFixture​(Vector2 point)
        Description copied from interface: Collidable
        Returns the first Fixture in this Collidable, determined by the order in which they were added, that contains the given point.

        Returns null if the point is not contained in any fixture in this Collidable.

        Specified by:
        getFixture in interface Collidable<T extends Fixture>
        Parameters:
        point - a world space point
        Returns:
        T the fixture or null
      • getFixtures

        public java.util.List<T> getFixtures​(Vector2 point)
        Description copied from interface: Collidable
        Returns all the Fixtures in this Collidable that contain the given point.

        Returns an empty list if the point is not contained in any fixture in this Collidable.

        Specified by:
        getFixtures in interface Collidable<T extends Fixture>
        Parameters:
        point - a world space point
        Returns:
        List<T>
      • removeFixture

        public T removeFixture​(Vector2 point)
        Description copied from interface: Collidable
        Removes the first Fixture in this Collidable, determined by the order in which they were added, that contains the given point and returns it.

        Returns null if the point is not contained in any Fixture in this Collidable.

        Specified by:
        removeFixture in interface Collidable<T extends Fixture>
        Parameters:
        point - a world space point
        Returns:
        T the fixture or null
      • removeFixtures

        public java.util.List<T> removeFixtures​(Vector2 point)
        Description copied from interface: Collidable
        Removes all the Fixtures in this Collidable that contain the given point and returns them.

        Returns an empty list if the point is not contained in any Fixture in this Collidable.

        Specified by:
        removeFixtures in interface Collidable<T extends Fixture>
        Parameters:
        point - a world space point
        Returns:
        List<T>
      • getFixtureIterator

        public java.util.Iterator<T> getFixtureIterator()
        Description copied from interface: Collidable
        Returns an iterator for this collidable's fixtures.

        The returned iterator supports the remove method.

        Specified by:
        getFixtureIterator in interface Collidable<T extends Fixture>
        Returns:
        Iterator<T>
      • getRotationDiscRadius

        public double getRotationDiscRadius()
        Description copied from interface: Collidable
        Returns the maximum radius of the disk that the Collidable creates if rotated 360 degrees about its center.
        Specified by:
        getRotationDiscRadius in interface Collidable<T extends Fixture>
        Returns:
        double the maximum radius of the rotation disk
      • setTransform

        public void setTransform​(Transform transform)
        Description copied from interface: Collidable
        Sets this Collidable's local to world space Transform.

        If the given transform is null, this method returns immediately.

        Specified by:
        setTransform in interface Collidable<T extends Fixture>
        Parameters:
        transform - the transform
      • 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
      • getId

        @Deprecated
        public java.util.UUID getId()
        Deprecated.
        Description copied from interface: Collidable
        Returns a unique identifier for this Collidable.

        This identifier is constant for the life of this Collidable.

        Specified by:
        getId in interface Collidable<T extends Fixture>
        Returns:
        UUID the unique id
      • getLocalPoint

        public Vector2 getLocalPoint​(Vector2 worldPoint)
        Description copied from interface: Collidable
        Returns a new point in local coordinates of this Collidable given a point in world coordinates.
        Specified by:
        getLocalPoint in interface Collidable<T extends Fixture>
        Parameters:
        worldPoint - a world space point
        Returns:
        Vector2 local space point
      • getLocalVector

        public Vector2 getLocalVector​(Vector2 worldVector)
        Description copied from interface: Collidable
        Returns a new vector in local coordinates of this Collidable given a vector in world coordinates.
        Specified by:
        getLocalVector in interface Collidable<T extends Fixture>
        Parameters:
        worldVector - a world space vector
        Returns:
        Vector2 local space vector
      • contains

        public boolean contains​(Vector2 point)
        Description copied from interface: Collidable
        Returns true if the given world space point is contained in this Collidable.

        The point is contained in this Collidable if and only if the point is contained in one of this Collidable's Fixtures.

        Specified by:
        contains in interface Collidable<T extends Fixture>
        Parameters:
        point - the world space test point
        Returns:
        boolean