Module org.dyn4j

Class ContactConstraint

  • All Implemented Interfaces:
    Shiftable

    public class ContactConstraint
    extends Constraint
    implements Shiftable
    Represents a Contact constraint for each Body pair.
    Since:
    1.0.0
    Version:
    3.2.5
    Author:
    William Bittle
    • Field Detail

      • contacts

        protected final java.util.List<Contact> contacts
        The Contacts
      • normal

        protected Vector2 normal
        The penetration normal
      • tangent

        protected Vector2 tangent
        The tangent of the normal
      • friction

        protected double friction
        The coefficient of friction
      • restitution

        protected double restitution
        The coefficient of restitution
      • sensor

        protected boolean sensor
        Whether the contact is a sensor contact or not
      • tangentSpeed

        protected double tangentSpeed
        The surface speed of the contact patch
      • enabled

        protected boolean enabled
        True if the contact should be evaluated
      • K

        Matrix22 K
        The K matrix for block solving a contact pair
      • invK

        Matrix22 invK
        The inverse of the K matrix
    • Constructor Detail

      • ContactConstraint

        public ContactConstraint​(Body body1,
                                 BodyFixture fixture1,
                                 Body body2,
                                 BodyFixture fixture2,
                                 Manifold manifold,
                                 double friction,
                                 double restitution)
        Full constructor.
        Parameters:
        body1 - the first Body
        fixture1 - the first Body's BodyFixture
        body2 - the second Body
        fixture2 - the second Body's BodyFixture
        manifold - the contact Manifold
        friction - the friction for the contact constraint
        restitution - the restitution for the contact constraint
    • Method Detail

      • 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 java.util.List<Contact> getContacts()
        Returns the list of Contacts.

        Modification of the list is permitted.

        Returns:
        List<Contact> the list of Contacts
      • 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
        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
        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