Module org.dyn4j

Class Fixture

  • All Implemented Interfaces:
    Direct Known Subclasses:

    public class Fixture
    extends Object
    implements DataContainer
    Represents a geometric piece of a CollisionBody.

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

    A CollisionBody 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 CollisionBody allows the bodies 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 CollisionBody. 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 CollisionBody and add a new Fixture with an updated shape instead.

    There's no restriction on reusing Shapes and Fixtures between CollisionBodys, 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).

    William Bittle
    • Field Detail

      • 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 Object userData
        The user data
    • Method Detail

      • getFilter

        public Filter getFilter()
        Returns the collision filter for this fixture.
      • 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).

      • 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).

        flag - true if this fixture should only sense contacts
      • getUserData

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

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