Module org.dyn4j

Class ContactConstraint<T extends PhysicsBody>

  • Type Parameters:
    T - The PhysicsBody type
    All Implemented Interfaces:
    Shiftable

    public final class ContactConstraint<T extends PhysicsBody>
    extends Object
    implements Shiftable
    Represents a SolvableContact constraint for each PhysicsBody pair.
    Since:
    1.0.0
    Version:
    4.0.0
    Author:
    William Bittle
    • Constructor Detail

      • ContactConstraint

        @Deprecated
        public ContactConstraint​(CollisionPair<T,​BodyFixture> pair,
                                 Manifold manifold,
                                 double friction,
                                 double restitution)
        Deprecated.
        Full constructor.
        Parameters:
        pair - the pair
        manifold - the contact Manifold
        friction - the friction for the contact constraint
        restitution - the restitution for the contact constraint
      • ContactConstraint

        public ContactConstraint​(CollisionPair<T,​BodyFixture> pair)
        Full constructor.
        Parameters:
        pair - the pair
    • Method Detail

      • update

        public void update​(Manifold manifold,
                           Settings settings,
                           ContactUpdateHandler handler)
        Updates this ContactConstraint with the new Manifold information and reports begin, persist, and end events to the handler.
        Parameters:
        manifold - the new manifold
        settings - the settings
        handler - the handler
      • 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
      • getNormal

        public Vector2 getNormal()
        Returns the collision normal.
        Returns:
        Vector2 the collision normal
      • getTangent

        public Vector2 getTangent()
        Returns the collision tangent.
        Returns:
        Vector2 the collision tangent
      • getContacts

        public List<? extends SolvedContact> getContacts()
        Returns the list of SolvableContacts.

        Modification of the list is permitted.

        Returns:
        List<SolvableContact> the list of SolvableContacts
      • getBody

        public T getBody​(CollisionBody<?> body)
        Returns the body that matches the given body.

        If the given body is neither body1 or body2, null is returned.

        Parameters:
        body - the body
        Returns:
        T
      • getFixture

        public BodyFixture getFixture​(CollisionBody<?> body)
        Returns the fixture for the body that matches the given body.

        If the given body is neither body1 or body2, null is returned.

        Parameters:
        body - the body
        Returns:
        E
      • getOtherBody

        public T getOtherBody​(CollisionBody<?> body)
        Returns the body that does not match the given body.

        If the given body is neither body1 or body2, null is returned.

        Parameters:
        body - the body
        Returns:
        T
      • getOtherFixture

        public BodyFixture getOtherFixture​(CollisionBody<?> body)
        Returns the fixture for the body that does not match the given body.

        If the given body is neither body1 or body2, null is returned.

        Parameters:
        body - the body
        Returns:
        E
      • getFriction

        public double getFriction()
        Returns the coefficient of friction for this contact constraint.
        Returns:
        double
      • setFriction

        public void setFriction​(double friction)
        Sets the coefficient of friction for this contact constraint.
        Parameters:
        friction - the friction; must be 0 or greater
        Since:
        3.0.2
      • getRestitution

        public double getRestitution()
        Returns the coefficient of restitution for this contact constraint.
        Returns:
        double
      • setRestitution

        public void setRestitution​(double restitution)
        Sets the coefficient of restitution for this contact constraint.
        Parameters:
        restitution - the restitution; must be zero or greater
        Since:
        3.0.2
      • isSensor

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

        By default a contact constraint is a sensor if either of the two BodyFixtures are sensor fixtures. This can be overridden using the setSensor(boolean) method.

        Returns:
        boolean
        Since:
        1.0.1
      • setSensor

        public void setSensor​(boolean flag)
        Sets this contact constraint to a sensor if flag is true.

        A sensor constraint is not solved.

        Parameters:
        flag - true if this contact constraint should be a sensor
        Since:
        3.0.2
      • getTangentSpeed

        public double getTangentSpeed()
        Returns the surface speed of the contact constraint.

        This will always be zero unless specified manually. This can be used to set the target velocity at the contact to simulate a conveyor belt type effect.

        Returns:
        double
        Since:
        3.0.2
      • setTangentSpeed

        public void setTangentSpeed​(double speed)
        Sets the target surface speed of the contact constraint.

        The surface speed, in meters / second, is used to simulate a conveyor belt.

        A value of zero deactivates this feature.

        Parameters:
        speed - the speed in Meters / Second
        Since:
        3.0.2
      • setEnabled

        public void setEnabled​(boolean flag)
        Sets the enabled flag.

        A value of true would enable the contact to be processed by the collision resolution step. A value of false would disable the processing of this constraint for this step only.

        True by default.

        Parameters:
        flag - true if the contact should be enabled
        Since:
        3.3.0
      • isEnabled

        public boolean isEnabled()
        Returns true if this contact constraint is enabled for processing by the collision resolution step.
        Returns:
        boolean
        Since:
        3.3.0
      • isOnIsland

        @Deprecated
        public boolean isOnIsland()
        Deprecated.
        Deprecated in 4.0.0. No replacement needed.
        Returns true if this contact constraint is on an island.
        Returns:
        boolean
      • setOnIsland

        @Deprecated
        public void setOnIsland​(boolean flag)
        Deprecated.
        Deprecated in 4.0.0. No replacement needed.
        Flags this contact constraint as being on an island.
        Parameters:
        flag - true if this contact constraint is on an island