-
- Type Parameters:
T
- thePhysicsBody
type
- All Implemented Interfaces:
DataContainer
,Shiftable
,Ownable
public class RopeJoint<T extends PhysicsBody> extends Joint<T> implements Shiftable, DataContainer
Implementation a maximum and/or minimum length distance joint.A rope joint contains the distance between two bodies. The bodies can rotate freely about the anchor points. The system as a whole can rotate and translate freely as well.
This joint is like the
DistanceJoint
, but includes an upper and lower limit and does not include a spring-damper system.By default the lower and upper limits are set to the current distance between the given anchor points and will function identically like a
DistanceJoint
. The upper and lower limits can be enabled separately.The lower limit constraint requires that the bodies are initially separated for it to be enforced. The lower limit will be enforced as soon as the bodies separate, but it's recommended that they start separated instead. If the lower limit is not being used, then the initial state doesn't matter.
- Since:
- 2.2.1
- Version:
- 4.0.1
- Author:
- William Bittle
- See Also:
- Documentation, Distance Constraint, Max Distance Constraint
-
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description Vector2
getAnchor1()
Returns the anchor point on the firstPhysicsBody
in world coordinates.Vector2
getAnchor2()
Returns the anchor point on the secondPhysicsBody
in world coordinates.LimitState
getLimitState()
Deprecated.Deprecated in 4.0.0.double
getLowerLimit()
Returns the lower limit in 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.double
getUpperLimit()
Returns the upper limit in meters.void
initializeConstraints(TimeStep step, Settings settings)
Performs any initialization of the velocity and position constraints.boolean
isLowerLimitEnabled()
Returns true if the lower limit is enabled.boolean
isUpperLimitEnabled()
Returns true if the upper limit is enabled.void
setLimits(double limit)
Sets both the lower and upper limits to the given limit.void
setLimits(double lowerLimit, double upperLimit)
Sets both the lower and upper limits.void
setLimitsEnabled(boolean flag)
Enables or disables both the lower and upper limits.void
setLimitsEnabled(double limit)
Sets both the lower and upper limits to the given limit and enables both.void
setLimitsEnabled(double lowerLimit, double upperLimit)
Sets both the lower and upper limits and enables both.void
setLowerLimit(double lowerLimit)
Sets the lower limit in meters.void
setLowerLimitEnabled(boolean flag)
Sets whether the lower limit is enabled.void
setUpperLimit(double upperLimit)
Sets the upper limit in meters.void
setUpperLimitEnabled(boolean flag)
Sets whether the upper limit is enabled.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 Joint
getBody1, getBody2, getOtherBody, getOwner, getUserData, isActive, isCollisionAllowed, isEnabled, isOnIsland, setCollisionAllowed, setOnIsland, setOwner, setUserData
-
Methods inherited from interface DataContainer
getUserData, setUserData
-
-
-
-
Constructor Detail
-
RopeJoint
public RopeJoint(T body1, T body2, Vector2 anchor1, Vector2 anchor2)
Minimal constructor.Creates a rope joint between the two bodies that acts like a distance joint.
- Parameters:
body1
- the firstPhysicsBody
body2
- the secondPhysicsBody
anchor1
- in world coordinatesanchor2
- in world coordinates- Throws:
NullPointerException
- if body1, body2, anchor1, or anchor2 is nullIllegalArgumentException
- if body1 == body2
-
-
Method Detail
-
toString
public String toString()
- Overrides:
toString
in classJoint<T extends PhysicsBody>
-
initializeConstraints
public void initializeConstraints(TimeStep step, Settings settings)
Description copied from class:Joint
Performs any initialization of the velocity and position constraints.- Specified by:
initializeConstraints
in classJoint<T extends PhysicsBody>
- Parameters:
step
- the time step informationsettings
- the current world settings
-
solveVelocityConstraints
public void solveVelocityConstraints(TimeStep step, Settings settings)
Description copied from class:Joint
Solves the velocity constraints.- Specified by:
solveVelocityConstraints
in classJoint<T extends PhysicsBody>
- Parameters:
step
- the time step informationsettings
- the current world settings
-
solvePositionConstraints
public boolean solvePositionConstraints(TimeStep step, Settings settings)
Description copied from class:Joint
Solves the position constraints.- Specified by:
solvePositionConstraints
in classJoint<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()
Description copied from class:Joint
Returns the anchor point on the firstPhysicsBody
in world coordinates.- Specified by:
getAnchor1
in classJoint<T extends PhysicsBody>
- Returns:
Vector2
-
getAnchor2
public Vector2 getAnchor2()
Description copied from class:Joint
Returns the anchor point on the secondPhysicsBody
in world coordinates.- Specified by:
getAnchor2
in classJoint<T extends PhysicsBody>
- Returns:
Vector2
-
getReactionForce
public Vector2 getReactionForce(double invdt)
Description copied from class:Joint
Returns the force applied to thePhysicsBody
s in order to satisfy the constraint in newtons.- Specified by:
getReactionForce
in classJoint<T extends PhysicsBody>
- Parameters:
invdt
- the inverse delta time- Returns:
Vector2
-
getReactionTorque
public double getReactionTorque(double invdt)
Returns the torque applied to thePhysicsBody
s in order to satisfy the constraint in newton-meters.Not applicable to this joint. Always returns zero.
- Specified by:
getReactionTorque
in classJoint<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.
-
getUpperLimit
public double getUpperLimit()
Returns the upper limit in meters.- Returns:
- double
-
setUpperLimit
public void setUpperLimit(double upperLimit)
Sets the upper limit in meters.- Parameters:
upperLimit
- the upper limit in meters; must be greater than or equal to zero- Throws:
IllegalArgumentException
- if upperLimit is less than zero or less than the current lower limit
-
setUpperLimitEnabled
public void setUpperLimitEnabled(boolean flag)
Sets whether the upper limit is enabled.- Parameters:
flag
- true if the upper limit should be enabled
-
isUpperLimitEnabled
public boolean isUpperLimitEnabled()
Returns true if the upper limit is enabled.- Returns:
- boolean true if the upper limit is enabled
-
getLowerLimit
public double getLowerLimit()
Returns the lower limit in meters.- Returns:
- double
-
setLowerLimit
public void setLowerLimit(double lowerLimit)
Sets the lower limit in meters.- Parameters:
lowerLimit
- the lower limit in meters; must be greater than or equal to zero- Throws:
IllegalArgumentException
- if lowerLimit is less than zero or greater than the current upper limit
-
setLowerLimitEnabled
public void setLowerLimitEnabled(boolean flag)
Sets whether the lower limit is enabled.- Parameters:
flag
- true if the lower limit should be enabled
-
isLowerLimitEnabled
public boolean isLowerLimitEnabled()
Returns true if the lower limit is enabled.- Returns:
- boolean true if the lower limit is enabled
-
setLimits
public void setLimits(double lowerLimit, double upperLimit)
Sets both the lower and upper limits.- Parameters:
lowerLimit
- the lower limit in meters; must be greater than or equal to zeroupperLimit
- the upper limit in meters; must be greater than or equal to zero- Throws:
IllegalArgumentException
- if lowerLimit is less than zero, upperLimit is less than zero, or lowerLimit is greater than upperLimit
-
setLimitsEnabled
public void setLimitsEnabled(double lowerLimit, double upperLimit)
Sets both the lower and upper limits and enables both.- Parameters:
lowerLimit
- the lower limit in meters; must be greater than or equal to zeroupperLimit
- the upper limit in meters; must be greater than or equal to zero- Throws:
IllegalArgumentException
- if lowerLimit is less than zero, upperLimit is less than zero, or lowerLimit is greater than upperLimit
-
setLimitsEnabled
public void setLimitsEnabled(boolean flag)
Enables or disables both the lower and upper limits.- Parameters:
flag
- true if both limits should be enabled- Since:
- 2.2.2
-
setLimits
public void setLimits(double limit)
Sets both the lower and upper limits to the given limit.This makes the joint a fixed length joint.
- Parameters:
limit
- the desired limit- Throws:
IllegalArgumentException
- if limit is less than zero- Since:
- 2.2.2
-
setLimitsEnabled
public void setLimitsEnabled(double limit)
Sets both the lower and upper limits to the given limit and enables both.This makes the joint a fixed length joint.
- Parameters:
limit
- the desired limit- Throws:
IllegalArgumentException
- if limit is less than zero- Since:
- 2.2.2
-
getLimitState
@Deprecated public LimitState getLimitState()
Deprecated.Deprecated in 4.0.0.Returns the current state of the limit.- Returns:
LimitState
- Since:
- 3.2.0
-
-