-
- Type Parameters:
T
- thePhysicsBody
type
- All Implemented Interfaces:
DataContainer
,Shiftable
,Ownable
public class PinJoint<T extends PhysicsBody> extends Joint<T> implements Shiftable, DataContainer
Implementation of a pin joint.A pin joint is a joint that pins a body to a specified world space point using a spring-damper system. This joint will attempt to place the given anchor point at the target position.
NOTE: The anchor point does not have to be within the bounds of the body.
By default the target position will be the given world space anchor. Use the
setTarget(Vector2)
method to set a different target.The pin joint requires the spring-damper system to function properly and as such the frequency value must be greater than zero. Use a
RevoluteJoint
instead if a spring-damper system is not desired. A good starting point is a frequency of 8.0 and damping ratio of 0.3 then adjust as necessary.The
getAnchor1()
method returns the target and thegetAnchor2()
method returns the world space anchor point.Both the
Joint.getBody1()
andJoint.getBody2()
methods return the same body.Renamed from MouseJoint in 3.2.0.
- Since:
- 1.0.0
- Version:
- 4.0.0
- Author:
- William Bittle
- See Also:
- Documentation
-
-
Method Summary
All Methods Instance Methods Concrete 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.double
getDampingRatio()
Returns the damping ratio.double
getFrequency()
Returns the spring frequency.double
getMaximumForce()
Returns the maximum force this constraint will apply in newtons.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.Vector2
getTarget()
Returns the target point in world coordinatesvoid
initializeConstraints(TimeStep step, Settings settings)
Performs any initialization of the velocity and position constraints.boolean
isCollisionAllowed()
Returns true if collision between the joinedPhysicsBody
s is allowed.void
setDampingRatio(double dampingRatio)
Sets the damping ratio.void
setFrequency(double frequency)
Sets the spring frequency.void
setMaximumForce(double maximumForce)
Sets the maximum force this constraint will apply in newtons.void
setTarget(Vector2 target)
Returns the target point in world coordinates.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, isEnabled, isOnIsland, setCollisionAllowed, setOnIsland, setOwner, setUserData
-
Methods inherited from interface DataContainer
getUserData, setUserData
-
-
-
-
Constructor Detail
-
PinJoint
public PinJoint(T body, Vector2 anchor, double frequency, double dampingRatio, double maximumForce)
Full constructor.- Parameters:
body
- the body to attach the joint toanchor
- the anchor point on the bodyfrequency
- the oscillation frequency in hzdampingRatio
- the damping ratiomaximumForce
- the maximum force this constraint can apply in newtons- Throws:
NullPointerException
- if body or anchor is nullIllegalArgumentException
- if frequency is less than or equal to zero, or if dampingRatio is less than zero or greater than one, or if maxForce is less than zero
-
-
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()
Returns the anchor point on the firstPhysicsBody
in world coordinates.Returns the target point in world space.
- Specified by:
getAnchor1
in classJoint<T extends PhysicsBody>
- Returns:
Vector2
-
getAnchor2
public Vector2 getAnchor2()
Returns the anchor point on the secondPhysicsBody
in world coordinates.Returns the anchor point on the body in world space.
- 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
-
isCollisionAllowed
public boolean isCollisionAllowed()
Description copied from class:Joint
Returns true if collision between the joinedPhysicsBody
s is allowed.- Overrides:
isCollisionAllowed
in classJoint<T extends PhysicsBody>
- Returns:
- boolean
-
shift
public void shift(Vector2 shift)
Description copied from interface:Shiftable
Translates the object to match the given coordinate shift.
-
setTarget
public void setTarget(Vector2 target)
Returns the target point in world coordinates.- Parameters:
target
- the target point- Throws:
NullPointerException
- if target is null
-
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 less than zero
-
getDampingRatio
public double getDampingRatio()
Returns the damping ratio.- Returns:
- double
-
setDampingRatio
public void setDampingRatio(double dampingRatio)
Sets the damping ratio.- Parameters:
dampingRatio
- the damping ratio; in the range [0, 1]- Throws:
IllegalArgumentException
- if dampingRation is less than zero or greater than one
-
getFrequency
public double getFrequency()
Returns the spring frequency.- Returns:
- double
-
setFrequency
public void setFrequency(double frequency)
Sets the spring frequency.- Parameters:
frequency
- the spring frequency in hz; must be greater than zero- Throws:
IllegalArgumentException
- if frequency is less than or equal to zero
-
-