- Object
-
- AbstractJoint<T>
-
- AbstractPairedBodyJoint<T>
-
- FrictionJoint<T>
-
- Type Parameters:
T
- thePhysicsBody
type
- All Implemented Interfaces:
DataContainer
,Joint<T>
,PairedBodyJoint<T>
,Shiftable
,Ownable
public class FrictionJoint<T extends PhysicsBody> extends AbstractPairedBodyJoint<T> implements PairedBodyJoint<T>, Joint<T>, Shiftable, DataContainer, Ownable
Implementation of a friction joint.A friction joint is a constraint that drives both linear and angular velocities to zero.
This joint is typically used with one dynamic and one static body. In this context, the joint will apply linear and angular friction to stop the body's motion. When used with two dynamic bodies, the relative linear and angular velocities are driven to zero.
Setting the maximum force and torque values will determine the rate at which the motion is stopped. These values are defaulted to 10 and 0.25 respectively.
NOTE: In versions 3.4.0 and below, the maximum force and torque values were 0 by default. This was changed in 4.0.0 to allow users to better understand the use of this joint when first using it.
- Since:
- 1.0.0
- Version:
- 5.0.0
- Author:
- William Bittle
- See Also:
- Documentation
-
-
Field Summary
Fields Modifier and Type Field Description protected Vector2
localAnchor1
The local anchor point on the firstPhysicsBody
protected Vector2
localAnchor2
The local anchor point on the secondPhysicsBody
protected double
maximumForce
The maximum force the constraint can applyprotected double
maximumTorque
The maximum torque the constraint can apply-
Fields inherited from class AbstractPairedBodyJoint
body1, body2
-
Fields inherited from class AbstractJoint
bodies, collisionAllowed, owner, userData
-
Fields inherited from interface Joint
SPRING_MODE_FREQUENCY, SPRING_MODE_STIFFNESS
-
-
Constructor Summary
Constructors Constructor Description FrictionJoint(T body1, T body2, Vector2 anchor)
Minimal constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Vector2
getAnchor1()
Returns the anchor point in world space on the firstPhysicsBody
.Vector2
getAnchor2()
Returns the anchor point in world space on the secondPhysicsBody
.double
getMaximumForce()
Returns the maximum force this constraint will apply in newtons.double
getMaximumTorque()
Returns the maximum torque this constraint will apply in newton-meters.Vector2
getReactionForce(double invdt)
Returns the force applied to thePhysicsBody
s in order to satisfy the constraint in newtons.double
getReactionTorque(double invdt)
Returns the torque applied to thePhysicsBody
s in order to satisfy the constraint in newton-meters.void
initializeConstraints(TimeStep step, Settings settings)
Performs any initialization of the velocity and position constraints.void
setMaximumForce(double maximumForce)
Sets the maximum force this constraint will apply in newtons.void
setMaximumTorque(double maximumTorque)
Sets the maximum torque this constraint will apply in newton-meters.void
shift(Vector2 shift)
Translates the object to match the given coordinate shift.boolean
solvePositionConstraints(TimeStep step, Settings settings)
Solves the position constraints.void
solveVelocityConstraints(TimeStep step, Settings settings)
Solves the velocity constraints.String
toString()
-
Methods inherited from class AbstractPairedBodyJoint
getBody, getBody1, getBody2, getBodyCount, getOtherBody, getReducedInertia, getReducedMass, isEnabled, isMember, setCollisionAllowed
-
Methods inherited from class AbstractJoint
getBodies, getBodyIterator, getConstraintImpulseMixing, getErrorReductionParameter, getFrequency, getNaturalFrequency, getNaturalFrequency, getOwner, getSpringDampingCoefficient, getSpringStiffness, getUserData, isCollisionAllowed, setOwner, setUserData
-
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface DataContainer
getUserData, setUserData
-
Methods inherited from interface Joint
getBodies, getBody, getBodyCount, getBodyIterator, isCollisionAllowed, isEnabled, isMember, setCollisionAllowed
-
Methods inherited from interface PairedBodyJoint
getBody1, getBody2, getOtherBody
-
-
-
-
Field Detail
-
localAnchor1
protected final Vector2 localAnchor1
The local anchor point on the firstPhysicsBody
-
localAnchor2
protected final Vector2 localAnchor2
The local anchor point on the secondPhysicsBody
-
maximumForce
protected double maximumForce
The maximum force the constraint can apply
-
maximumTorque
protected double maximumTorque
The maximum torque the constraint can apply
-
-
Constructor Detail
-
FrictionJoint
public FrictionJoint(T body1, T body2, Vector2 anchor)
Minimal constructor.- Parameters:
body1
- the firstPhysicsBody
body2
- the secondPhysicsBody
anchor
- the anchor point in world coordinates- Throws:
NullPointerException
- if body1, body2, or anchor is nullIllegalArgumentException
- if body1 == body2
-
-
Method Detail
-
toString
public String toString()
- Overrides:
toString
in classAbstractJoint<T extends PhysicsBody>
-
initializeConstraints
public void initializeConstraints(TimeStep step, Settings settings)
Description copied from interface:Joint
Performs any initialization of the velocity and position constraints.- Specified by:
initializeConstraints
in interfaceJoint<T extends PhysicsBody>
- Parameters:
step
- the time step informationsettings
- the current world settings
-
solveVelocityConstraints
public void solveVelocityConstraints(TimeStep step, Settings settings)
Description copied from interface:Joint
Solves the velocity constraints.- Specified by:
solveVelocityConstraints
in interfaceJoint<T extends PhysicsBody>
- Parameters:
step
- the time step informationsettings
- the current world settings
-
solvePositionConstraints
public boolean solvePositionConstraints(TimeStep step, Settings settings)
Description copied from interface:Joint
Solves the position constraints.- Specified by:
solvePositionConstraints
in interfaceJoint<T extends PhysicsBody>
- Parameters:
step
- the time step informationsettings
- the current world settings- Returns:
- boolean true if the position constraints were solved
-
getAnchor1
public Vector2 getAnchor1()
Returns the anchor point in world space on the firstPhysicsBody
.- Returns:
Vector2
-
getAnchor2
public Vector2 getAnchor2()
Returns the anchor point in world space on the secondPhysicsBody
.- Returns:
Vector2
-
getReactionForce
public Vector2 getReactionForce(double invdt)
Description copied from interface:Joint
Returns the force applied to thePhysicsBody
s in order to satisfy the constraint in newtons.- Specified by:
getReactionForce
in interfaceJoint<T extends PhysicsBody>
- Parameters:
invdt
- the inverse delta time- Returns:
Vector2
-
getReactionTorque
public double getReactionTorque(double invdt)
Description copied from interface:Joint
Returns the torque applied to thePhysicsBody
s in order to satisfy the constraint in newton-meters.- Specified by:
getReactionTorque
in interfaceJoint<T extends PhysicsBody>
- Parameters:
invdt
- the inverse delta time- Returns:
- double
-
shift
public void shift(Vector2 shift)
Description copied from interface:Shiftable
Translates the object to match the given coordinate shift.
-
getMaximumTorque
public double getMaximumTorque()
Returns the maximum torque this constraint will apply in newton-meters.- Returns:
- double
-
setMaximumTorque
public void setMaximumTorque(double maximumTorque)
Sets the maximum torque this constraint will apply in newton-meters.- Parameters:
maximumTorque
- the maximum torque in newton-meters; in the range [0, ∞]- Throws:
IllegalArgumentException
- if maxTorque is less than zero
-
getMaximumForce
public double getMaximumForce()
Returns the maximum force this constraint will apply in newtons.- Returns:
- double
-
setMaximumForce
public void setMaximumForce(double maximumForce)
Sets the maximum force this constraint will apply in newtons.- Parameters:
maximumForce
- the maximum force in newtons; in the range [0, ∞]- Throws:
IllegalArgumentException
- if maxForce is less than zero
-
-