- Object
-
- AbstractJoint<T>
-
- AbstractPairedBodyJoint<T>
-
- WeldJoint<T>
-
- Type Parameters:
T
- thePhysicsBody
type
- All Implemented Interfaces:
DataContainer
,AngularLimitsJoint
,AngularSpringJoint
,Joint<T>
,PairedBodyJoint<T>
,Shiftable
,Ownable
public class WeldJoint<T extends PhysicsBody> extends AbstractPairedBodyJoint<T> implements AngularLimitsJoint, AngularSpringJoint, PairedBodyJoint<T>, Joint<T>, Shiftable, DataContainer, Ownable
Implementation of a weld joint.A weld joint joins two bodies together as if they were a single body. Both their relative linear and angular motion are constrained to keep them attached to each other. The system as a whole can rotate and translate freely.
The bodies are locked in place in their current positions. The anchor point is used to detect joint separation and to serve as the pivot point for the angular spring.
This joint supports an angular spring using the
setSpringEnabled(boolean)
method. You can control the behavior of the spring using the frequency, damping ratio, etc. settings. A good starting point is a frequency of 8.0 and damping ratio of 0.3 then adjust as necessary.This joint also supports angular limits, but only when the spring is enabled. Its recommended that you use limits when using the angular spring to prevent wrap-around (when the relative angle between the bodies changes from 180 to -180 for example).
By default the lower and upper limit angles are set to the current angle between the bodies. When the lower and upper limits are equal, the bodies rotate together and are not allowed rotate relative to one another. By default the limits are disabled. If you want the lower and upper limit to be the same, disable the spring/limits for a more stable simulation.
If the lower and upper limits are set explicitly, the values must follow these restrictions:
- lower limit ≤ upper limit
- lower limit > -180
- upper limit < 180
setLimitsReferenceAngle(double)
method. This method sets the baseline angle for the joint, which represents 0 radians in the context of the limits. For example:// we would like the joint limits to be [30, 260] // this is the same as the limits [-60, 170] if the reference angle is 90 joint.setLimits(Math.toRadians(-60), Math.toRadians(170)); joint.setReferenceAngle(Math.toRadians(90));
- Since:
- 1.0.0
- Version:
- 5.0.0
- Author:
- William Bittle
- See Also:
- Documentation, Weld Constraint
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
limitsEnabled
Whether theJoint
limits are enabled or notprotected Vector2
localAnchor1
The local anchor point on the firstPhysicsBody
protected Vector2
localAnchor2
The local anchor point on the secondPhysicsBody
protected double
lowerLimit
The lower limit of theJoint
protected double
referenceAngle
The initial angle between the twoPhysicsBody
sprotected boolean
springDamperEnabled
True if the spring-damper is enabledprotected double
springDampingRatio
The damping ratioprotected boolean
springEnabled
True if the spring is enabledprotected double
springFrequency
The oscillation frequency in hzprotected double
springMaximumTorque
The maximum force the spring will applyprotected boolean
springMaximumTorqueEnabled
True if the spring maximum force is enabledprotected int
springMode
The spring mode (frequency or stiffness)protected double
springStiffness
The stiffness of the springprotected double
upperLimit
The upper limit of theJoint
-
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
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Vector2
getAnchor1()
Returns the world space anchor point for the first body.Vector2
getAnchor2()
Returns the world space anchor point for the second body.double
getLimitsReferenceAngle()
Returns the limits reference angle.double
getLowerLimit()
Returns the lower angular limit in radians.double
getMaximumSpringTorque()
Returns the maximum spring torque 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.double
getSpringDampingRatio()
Returns the damping ratio for the spring's damper.double
getSpringFrequency()
Returns the spring frequency.int
getSpringMode()
Returns the current spring mode.double
getSpringStiffness()
Returns the spring stiffness.double
getSpringTorque(double invdt)
Returns the torque applied to by the spring in the last step.double
getUpperLimit()
Returns the upper angular limit in radians.void
initializeConstraints(TimeStep step, Settings settings)
Performs any initialization of the velocity and position constraints.boolean
isLimitsEnabled()
Returns true if the angular limits are enabled.boolean
isMaximumSpringTorqueEnabled()
Returns true if the maximum spring torque is enabled.boolean
isSpringDamperEnabled()
Returns true if the damper is enabled for the spring.boolean
isSpringEnabled()
Returns true if the spring is enabled.void
setLimits(double limit)
Sets both the lower and upper limits to the given limit.void
setLimits(double lowerLimit, double upperLimit)
Sets the upper and lower angular limits.void
setLimitsEnabled(boolean flag)
Enables or disables the angular limits.void
setLimitsEnabled(double limit)
Sets both the lower and upper limits to the given limit and enables them.void
setLimitsEnabled(double lowerLimit, double upperLimit)
Sets both the lower and upper limits and enables them.void
setLimitsReferenceAngle(double angle)
Sets the limits reference angle.void
setLowerLimit(double lowerLimit)
Sets the lower angular limit.void
setMaximumSpringTorque(double maximum)
Sets the maximum spring torque the spring is allowed to exert.void
setMaximumSpringTorqueEnabled(boolean enabled)
Sets whether the spring torque is limited to a maximum torque.void
setSpringDamperEnabled(boolean enabled)
Sets whether the spring's damper is enabled or not.void
setSpringDampingRatio(double dampingRatio)
Sets the damping ratio.void
setSpringEnabled(boolean enabled)
Sets whether the spring is enabled or not.void
setSpringFrequency(double frequency)
Sets the spring frequency.void
setSpringStiffness(double stiffness)
Sets the spring stiffness.void
setUpperLimit(double upperLimit)
Sets the upper angular limit.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()
protected void
updateSpringCoefficients()
Computes the spring coefficients from the current state of the joint.-
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
-
limitsEnabled
protected boolean limitsEnabled
Whether theJoint
limits are enabled or not
-
upperLimit
protected double upperLimit
The upper limit of theJoint
-
lowerLimit
protected double lowerLimit
The lower limit of theJoint
-
referenceAngle
protected double referenceAngle
The initial angle between the twoPhysicsBody
s
-
springEnabled
protected boolean springEnabled
True if the spring is enabled
-
springDamperEnabled
protected boolean springDamperEnabled
True if the spring-damper is enabled
-
springMode
protected int springMode
The spring mode (frequency or stiffness)
-
springFrequency
protected double springFrequency
The oscillation frequency in hz
-
springStiffness
protected double springStiffness
The stiffness of the spring
-
springDampingRatio
protected double springDampingRatio
The damping ratio
-
springMaximumTorqueEnabled
protected boolean springMaximumTorqueEnabled
True if the spring maximum force is enabled
-
springMaximumTorque
protected double springMaximumTorque
The maximum force the spring will apply
-
-
Constructor Detail
-
WeldJoint
public WeldJoint(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
-
updateSpringCoefficients
protected void updateSpringCoefficients()
Computes the spring coefficients from the current state of the joint.This method is intended to set the springStiffness OR springFrequency and damping for use during constraint solving.
-
getAnchor1
public Vector2 getAnchor1()
Returns the world space anchor point for the first body.- Returns:
Vector2
-
getAnchor2
public Vector2 getAnchor2()
Returns the world space anchor point for the second body.- 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.
-
getSpringDampingRatio
public double getSpringDampingRatio()
Description copied from interface:AngularSpringJoint
Returns the damping ratio for the spring's damper.- Specified by:
getSpringDampingRatio
in interfaceAngularSpringJoint
- Returns:
- double
-
setSpringDampingRatio
public void setSpringDampingRatio(double dampingRatio)
Description copied from interface:AngularSpringJoint
Sets the damping ratio.Larger values reduce the oscillation of the spring.
- Specified by:
setSpringDampingRatio
in interfaceAngularSpringJoint
- Parameters:
dampingRatio
- the damping ratio; in the range (0, 1]
-
getSpringFrequency
public double getSpringFrequency()
Description copied from interface:AngularSpringJoint
Returns the spring frequency.- Specified by:
getSpringFrequency
in interfaceAngularSpringJoint
- Returns:
- double
-
getSpringStiffness
public double getSpringStiffness()
Description copied from interface:AngularSpringJoint
Returns the spring stiffness.- Specified by:
getSpringStiffness
in interfaceAngularSpringJoint
- Returns:
- double
-
setSpringFrequency
public void setSpringFrequency(double frequency)
Description copied from interface:AngularSpringJoint
Sets the spring frequency.Larger values increase the stiffness of the spring.
Calling this method puts the spring into fixed frequency mode. In this mode, the spring stiffness is computed based on the frequency.
- Specified by:
setSpringFrequency
in interfaceAngularSpringJoint
- Parameters:
frequency
- the spring frequency in hz; must be greater than zero
-
setSpringStiffness
public void setSpringStiffness(double stiffness)
Description copied from interface:AngularSpringJoint
Sets the spring stiffness.Larger values increase the stiffness of the spring.
Calling this method puts the spring into fixed stiffness mode. In this mode, the spring frequency is computed based on the stiffness.
- Specified by:
setSpringStiffness
in interfaceAngularSpringJoint
- Parameters:
stiffness
- the spring stiffness (k); must be greater than zero
-
getMaximumSpringTorque
public double getMaximumSpringTorque()
Description copied from interface:AngularSpringJoint
Returns the maximum spring torque in Newton-meters.- Specified by:
getMaximumSpringTorque
in interfaceAngularSpringJoint
- Returns:
- double
-
setMaximumSpringTorque
public void setMaximumSpringTorque(double maximum)
Description copied from interface:AngularSpringJoint
Sets the maximum spring torque the spring is allowed to exert.- Specified by:
setMaximumSpringTorque
in interfaceAngularSpringJoint
- Parameters:
maximum
- the maximum spring torque
-
isMaximumSpringTorqueEnabled
public boolean isMaximumSpringTorqueEnabled()
Description copied from interface:AngularSpringJoint
Returns true if the maximum spring torque is enabled.- Specified by:
isMaximumSpringTorqueEnabled
in interfaceAngularSpringJoint
- Returns:
- boolean
-
setMaximumSpringTorqueEnabled
public void setMaximumSpringTorqueEnabled(boolean enabled)
Description copied from interface:AngularSpringJoint
Sets whether the spring torque is limited to a maximum torque.- Specified by:
setMaximumSpringTorqueEnabled
in interfaceAngularSpringJoint
- Parameters:
enabled
- true if the spring torque should be limited
-
isSpringEnabled
public boolean isSpringEnabled()
Description copied from interface:AngularSpringJoint
Returns true if the spring is enabled.- Specified by:
isSpringEnabled
in interfaceAngularSpringJoint
- Returns:
- boolean
-
setSpringEnabled
public void setSpringEnabled(boolean enabled)
Description copied from interface:AngularSpringJoint
Sets whether the spring is enabled or not.- Specified by:
setSpringEnabled
in interfaceAngularSpringJoint
- Parameters:
enabled
- true if the spring should be enabled
-
isSpringDamperEnabled
public boolean isSpringDamperEnabled()
Description copied from interface:AngularSpringJoint
Returns true if the damper is enabled for the spring.NOTE: for the damper to have any effect, the spring must be enabled.
- Specified by:
isSpringDamperEnabled
in interfaceAngularSpringJoint
- Returns:
- boolean
- See Also:
AngularSpringJoint.isSpringEnabled()
-
setSpringDamperEnabled
public void setSpringDamperEnabled(boolean enabled)
Description copied from interface:AngularSpringJoint
Sets whether the spring's damper is enabled or not.NOTE: for the damper to have any effect, the spring must be enabled.
- Specified by:
setSpringDamperEnabled
in interfaceAngularSpringJoint
- Parameters:
enabled
- true if the damper should be enabled- See Also:
AngularSpringJoint.setSpringEnabled(boolean)
-
getSpringTorque
public double getSpringTorque(double invdt)
Description copied from interface:AngularSpringJoint
Returns the torque applied to by the spring in the last step.- Specified by:
getSpringTorque
in interfaceAngularSpringJoint
- Parameters:
invdt
- the inverse delta time- Returns:
- double
-
getSpringMode
public int getSpringMode()
Description copied from interface:AngularSpringJoint
Returns the current spring mode.NOTE: The spring mode is set automatically when you call either
AngularSpringJoint.setSpringFrequency(double)
orAngularSpringJoint.setSpringStiffness(double)
. Use this method to store the spring mode when saving the simulation state and use the value to call eitherAngularSpringJoint.setSpringFrequency(double)
orAngularSpringJoint.setSpringStiffness(double)
.- Specified by:
getSpringMode
in interfaceAngularSpringJoint
- Returns:
- int
- See Also:
Joint.SPRING_MODE_FREQUENCY
,Joint.SPRING_MODE_STIFFNESS
-
isLimitsEnabled
public boolean isLimitsEnabled()
Description copied from interface:AngularLimitsJoint
Returns true if the angular limits are enabled.- Specified by:
isLimitsEnabled
in interfaceAngularLimitsJoint
- Returns:
- boolean
-
setLimitsEnabled
public void setLimitsEnabled(boolean flag)
Description copied from interface:AngularLimitsJoint
Enables or disables the angular limits.- Specified by:
setLimitsEnabled
in interfaceAngularLimitsJoint
- Parameters:
flag
- true if the limit should be enabled
-
getUpperLimit
public double getUpperLimit()
Description copied from interface:AngularLimitsJoint
Returns the upper angular limit in radians.- Specified by:
getUpperLimit
in interfaceAngularLimitsJoint
- Returns:
- double
-
setUpperLimit
public void setUpperLimit(double upperLimit)
Description copied from interface:AngularLimitsJoint
Sets the upper angular limit.Must be greater than or equal to the lower angular limit.
See the class documentation for more details on the limit ranges.
- Specified by:
setUpperLimit
in interfaceAngularLimitsJoint
- Parameters:
upperLimit
- the upper angular limit in radians
-
getLowerLimit
public double getLowerLimit()
Description copied from interface:AngularLimitsJoint
Returns the lower angular limit in radians.- Specified by:
getLowerLimit
in interfaceAngularLimitsJoint
- Returns:
- double
-
setLowerLimit
public void setLowerLimit(double lowerLimit)
Description copied from interface:AngularLimitsJoint
Sets the lower angular limit.Must be less than or equal to the upper angular limit.
See the class documentation for more details on the limit ranges.
- Specified by:
setLowerLimit
in interfaceAngularLimitsJoint
- Parameters:
lowerLimit
- the lower angular limit in radians
-
setLimits
public void setLimits(double lowerLimit, double upperLimit)
Description copied from interface:AngularLimitsJoint
Sets the upper and lower angular limits.The lower limit must be less than or equal to the upper limit.
See the class documentation for more details on the limit ranges.
- Specified by:
setLimits
in interfaceAngularLimitsJoint
- Parameters:
lowerLimit
- the lower limit in radiansupperLimit
- the upper limit in radians
-
setLimitsEnabled
public void setLimitsEnabled(double lowerLimit, double upperLimit)
Description copied from interface:AngularLimitsJoint
Sets both the lower and upper limits and enables them.See the class documentation for more details on the limit ranges.
- Specified by:
setLimitsEnabled
in interfaceAngularLimitsJoint
- Parameters:
lowerLimit
- the lower limit in radiansupperLimit
- the upper limit in radians
-
setLimitsEnabled
public void setLimitsEnabled(double limit)
Description copied from interface:AngularLimitsJoint
Sets both the lower and upper limits to the given limit and enables them.See the class documentation for more details on the limit ranges.
- Specified by:
setLimitsEnabled
in interfaceAngularLimitsJoint
- Parameters:
limit
- the desired limit
-
setLimits
public void setLimits(double limit)
Description copied from interface:AngularLimitsJoint
Sets both the lower and upper limits to the given limit.See the class documentation for more details on the limit ranges.
- Specified by:
setLimits
in interfaceAngularLimitsJoint
- Parameters:
limit
- the desired limit
-
getLimitsReferenceAngle
public double getLimitsReferenceAngle()
Description copied from interface:AngularLimitsJoint
Returns the limits reference angle.The reference angle is the angle calculated when the joint was created from the two joined bodies. The reference angle is the angular difference between the bodies.
- Specified by:
getLimitsReferenceAngle
in interfaceAngularLimitsJoint
- Returns:
- double
-
setLimitsReferenceAngle
public void setLimitsReferenceAngle(double angle)
Description copied from interface:AngularLimitsJoint
Sets the limits reference angle.This method can be used to set the reference angle to override the computed reference angle from the constructor. This is useful in recreating the joint from a current state or when adjusting the limits.
See the class documentation for more details.
- Specified by:
setLimitsReferenceAngle
in interfaceAngularLimitsJoint
- Parameters:
angle
- the reference angle in radians- See Also:
AngularLimitsJoint.getLimitsReferenceAngle()
-
-