Module org.dyn4j

Class Fixture

  • All Implemented Interfaces:
    DataContainer
    Direct Known Subclasses:
    BodyFixture

    public class Fixture
    extends java.lang.Object
    implements DataContainer
    Represents a geometric piece of a Collidable.

    A Fixture has a one-to-one relationship with a Convex Shape, storing additional collision specific information.

    A Collidable is composed of many Fixtures to represent its physical shape. While the only shapes supported by the collision detection system are Convex shapes, the composition of multiple Fixtures in a Collidable allows the collidables to be non-convex.

    The Fixture's Shape should be translated and rotated using the Shape's methods to move the shape relative to the containing Collidable. Other modifications to the shape is not recommended after adding it to a Fixture. To change the shape of a fixture, remove the existing Fixture from the Collidable and add a new Fixture with an updated shape instead.

    There's no restriction on reusing Shapes and Fixtures between Collidables, but this is also discouraged to reduce confusion and unexpected behavior (primarily local translations and rotations).

    A Fixture can have a Filter assigned to enable filtering of collisions between it and other fixtures.

    A Fixture can be flagged as a sensor fixture to enable standard collision detection, but disable collision resolution (response).

    Since:
    2.0.0
    Version:
    3.2.0
    Author:
    William Bittle
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected Filter filter
      The collision filter
      protected java.util.UUID id
      The id for the fixture
      protected boolean sensor
      Whether the fixture only senses contact
      protected Convex shape
      The convex shape for this fixture
      protected java.lang.Object userData
      The user data
    • Constructor Summary

      Constructors 
      Constructor Description
      Fixture​(Convex shape)
      Minimal constructor.
    • Method Summary

      All Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      Filter getFilter()
      Returns the collision filter for this fixture.
      java.util.UUID getId()
      Deprecated.
      ID schemes should be implemented by the user where needed; since 3.4.0
      Convex getShape()
      The Convex Shape representing the geometry of this fixture.
      java.lang.Object getUserData()
      Gets the custom user data.
      boolean isSensor()
      Returns true if this fixture is a sensor.
      void setFilter​(Filter filter)
      Sets the collision filter for this fixture.
      void setSensor​(boolean flag)
      Toggles this fixture as a sensor fixture.
      void setUserData​(java.lang.Object userData)
      Sets the custom user data to the given data.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • id

        protected final java.util.UUID id
        The id for the fixture
      • shape

        protected final Convex shape
        The convex shape for this fixture
      • filter

        protected Filter filter
        The collision filter
      • sensor

        protected boolean sensor
        Whether the fixture only senses contact
      • userData

        protected java.lang.Object userData
        The user data
    • Constructor Detail

      • Fixture

        public Fixture​(Convex shape)
        Minimal constructor.
        Parameters:
        shape - the Convex Shape for this fixture
        Throws:
        java.lang.NullPointerException - if shape is null
    • Method Detail

      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • getId

        @Deprecated
        public java.util.UUID getId()
        Deprecated.
        ID schemes should be implemented by the user where needed; since 3.4.0
        Returns the id for this fixture.

        This identifier is constant for the life of this Fixture.

        Returns:
        UUID
      • getFilter

        public Filter getFilter()
        Returns the collision filter for this fixture.
        Returns:
        Filter
      • setFilter

        public void setFilter​(Filter filter)
        Sets the collision filter for this fixture.
        Parameters:
        filter - the collision filter
        Throws:
        java.lang.NullPointerException - if filter is null; Use Filter.DEFAULT_FILTER instead
      • isSensor

        public boolean isSensor()
        Returns true if this fixture is a sensor.

        A sensor fixture is a fixture that participates in collision detection but does not participate in collision resolution (response).

        Returns:
        boolean
      • setSensor

        public void setSensor​(boolean flag)
        Toggles this fixture as a sensor fixture.

        A sensor fixture is a fixture that participates in collision detection but does not participate in collision resolution (response).

        Parameters:
        flag - true if this fixture should only sense contacts
      • 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