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:
    5.0.1
    Author:
    William Bittle
    • Field Detail

      • contacts

        protected final List<SolvableContact> contacts
        The Contacts
      • contactsUnmodifiable

        protected final List<SolvableContact> contactsUnmodifiable
        An unmodifiable view of the Contacts
      • normal

        protected final Vector2 normal
        The penetration normal
      • tangent

        protected final Vector2 tangent
        The tangent of the normal
      • friction

        protected double friction
        The coefficient of friction
      • restitution

        protected double restitution
        The coefficient of restitution
      • restitutionVelocity

        protected double restitutionVelocity
        The minimum velocity at which to apply 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
      • size

        protected int size
        The number of contacts to solve
    • 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 an unmodifiable list of SolvableContacts.

        The contacts returned here implement the SolvedContact interface, but may not have been solved yet. This will be the case for contacts discovered at the end of a world update. In addition, when contacts are not persisted, the SolvedContact interface methods will return default values since it's technically a new contact.

        If you want the most up to date contact information, use this method inside a world listener that is triggered before the collision detection phase.

        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

        @Deprecated
        public void setFriction​(double friction)
        Deprecated.
        Removed in 5.0.1. Set the body friction coefficients instead.
        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

        @Deprecated
        public void setRestitution​(double restitution)
        Deprecated.
        Removed in 5.0.1. Set the body restitution coefficients instead.
        Sets the coefficient of restitution for this contact constraint.
        Parameters:
        restitution - the restitution; must be zero or greater
        Since:
        3.0.2
      • getRestitutionVelocity

        public double getRestitutionVelocity()
        Returns the minimum velocity required for restitution to be applied.
        Returns:
        double
        Since:
        4.2.0
      • setRestitutionVelocity

        @Deprecated
        public void setRestitutionVelocity​(double restitutionVelocity)
        Deprecated.
        Removed in 5.0.1. Set the body restitution velocity instead.
        Sets the minimum velocity required for restitution to be applied.
        Parameters:
        restitutionVelocity - the restitution velocity
        Since:
        4.2.0
      • isSensor

        public boolean isSensor()
        Returns true if this ContactConstraint is a sensor.
        Returns:
        boolean
        Since:
        1.0.1
      • setSensor

        @Deprecated
        public void setSensor​(boolean flag)
        Deprecated.
        Removed in 5.0.1. Set the body fixture sensor flag instead.
        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, which is the default.

        NOTE: The tangent velocity of this contact constraint is retained across simulation steps. If the contact constraint is removed (because the bodies separated), then upon the bodies colliding again, the tangent velocity will be reset to it's default value.

        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.

        NOTE: The enabled state of this contact constraint is retained across simulation steps. If the contact constraint is removed (because the bodies separated), then upon the bodies colliding again, the enable state will be reset to the 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