- Object
-
- ContactConstraint<T>
-
- Type Parameters:
T
- ThePhysicsBody
type
- All Implemented Interfaces:
Shiftable
public final class ContactConstraint<T extends PhysicsBody> extends Object implements Shiftable
Represents aSolvableContact
constraint for eachPhysicsBody
pair.- Since:
- 1.0.0
- Version:
- 5.0.1
- Author:
- William Bittle
-
-
Field Summary
Fields Modifier and Type Field Description protected List<SolvableContact>
contacts
TheContact
sprotected List<SolvableContact>
contactsUnmodifiable
An unmodifiable view of theContact
sprotected boolean
enabled
True if the contact should be evaluatedprotected double
friction
The coefficient of frictionprotected Vector2
normal
The penetration normalprotected CollisionPair<CollisionItem<T,BodyFixture>>
pair
The collision pairprotected double
restitution
The coefficient of restitutionprotected double
restitutionVelocity
The minimum velocity at which to apply restitutionprotected boolean
sensor
Whether the contact is a sensor contact or notprotected int
size
The number of contacts to solveprotected Vector2
tangent
The tangent of the normalprotected double
tangentSpeed
The surface speed of the contact patch
-
Constructor Summary
Constructors Constructor Description ContactConstraint(CollisionPair<CollisionItem<T,BodyFixture>> pair)
Full constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description T
getBody(CollisionBody<?> body)
Returns the body that matches the given body.T
getBody1()
Returns the firstPhysicsBody
.T
getBody2()
Returns the secondPhysicsBody
.CollisionPair<CollisionItem<T,BodyFixture>>
getCollisionPair()
Returns theCollisionPair
.List<? extends SolvedContact>
getContacts()
Returns an unmodifiable list ofSolvableContact
s.BodyFixture
getFixture(CollisionBody<?> body)
Returns the fixture for the body that matches the given body.BodyFixture
getFixture1()
Returns the firstPhysicsBody
'sBodyFixture
.BodyFixture
getFixture2()
Returns the secondPhysicsBody
'sBodyFixture
.double
getFriction()
Returns the coefficient of friction for this contact constraint.Vector2
getNormal()
Returns the collision normal.T
getOtherBody(CollisionBody<?> body)
Returns the body that does not match the given body.BodyFixture
getOtherFixture(CollisionBody<?> body)
Returns the fixture for the body that does not match the given body.double
getRestitution()
Returns the coefficient of restitution for this contact constraint.double
getRestitutionVelocity()
Returns the minimum velocity required for restitution to be applied.Vector2
getTangent()
Returns the collision tangent.double
getTangentSpeed()
Returns the surface speed of the contact constraint.boolean
isEnabled()
Returns true if this contact constraint is enabled for processing by the collision resolution step.boolean
isSensor()
Returns true if thisContactConstraint
is a sensor.void
setEnabled(boolean flag)
Sets the enabled flag.void
setFriction(double friction)
Deprecated.Removed in 5.0.1.void
setRestitution(double restitution)
Deprecated.Removed in 5.0.1.void
setRestitutionVelocity(double restitutionVelocity)
Deprecated.Removed in 5.0.1.void
setSensor(boolean flag)
Deprecated.Removed in 5.0.1.void
setTangentSpeed(double speed)
Sets the target surface speed of the contact constraint.void
shift(Vector2 shift)
Translates the object to match the given coordinate shift.String
toString()
void
update(Manifold manifold, Settings settings, ContactUpdateHandler handler)
Updates thisContactConstraint
with the newManifold
information and reports begin, persist, and end events to the handler.
-
-
-
Field Detail
-
pair
protected final CollisionPair<CollisionItem<T extends PhysicsBody,BodyFixture>> pair
The collision pair
-
contactsUnmodifiable
protected final List<SolvableContact> contactsUnmodifiable
An unmodifiable view of theContact
s
-
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
-
-
Constructor Detail
-
ContactConstraint
public ContactConstraint(CollisionPair<CollisionItem<T,BodyFixture>> pair)
Full constructor.- Parameters:
pair
- the pair
-
-
Method Detail
-
update
public void update(Manifold manifold, Settings settings, ContactUpdateHandler handler)
Updates thisContactConstraint
with the newManifold
information and reports begin, persist, and end events to the handler.- Parameters:
manifold
- the new manifoldsettings
- the settingshandler
- the handler
-
shift
public void shift(Vector2 shift)
Description copied from interface:Shiftable
Translates the object to match the given coordinate shift.
-
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 ofSolvableContact
s.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, theSolvedContact
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 ofSolvableContact
s
-
getCollisionPair
public CollisionPair<CollisionItem<T,BodyFixture>> getCollisionPair()
Returns theCollisionPair
.- Returns:
CollisionPair
- Since:
- 4.0.0
-
getBody1
public T getBody1()
Returns the firstPhysicsBody
.- Returns:
PhysicsBody
-
getBody2
public T getBody2()
Returns the secondPhysicsBody
.- Returns:
PhysicsBody
-
getFixture1
public BodyFixture getFixture1()
Returns the firstPhysicsBody
'sBodyFixture
.- Returns:
BodyFixture
the firstPhysicsBody
'sBodyFixture
-
getFixture2
public BodyFixture getFixture2()
Returns the secondPhysicsBody
'sBodyFixture
.- Returns:
BodyFixture
the secondPhysicsBody
'sBodyFixture
-
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 thisContactConstraint
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
-
-