-
- Type Parameters:
T
- thePhysicsBody
type
- All Implemented Interfaces:
DataContainer
,Shiftable
,Ownable
public class PrismaticJoint<T extends PhysicsBody> extends Joint<T> implements Shiftable, DataContainer
Implementation of a prismatic joint.A prismatic joint constrains the linear motion of two bodies along an axis and prevents relative rotation. The whole system can rotate and translate freely.
The initial relative rotation of the bodies will remain unchanged unless updated by calling
setReferenceAngle(double)
method. The bodies are not required to be aligned in any particular way.The world space anchor point can be any point but is typically a point on the axis of allowed motion, usually the world center of either of the joined bodies.
The limits are linear limits along the axis. The limits are checked against the separation of the local anchor points, rather than the separation of the bodies. This can have the effect of offsetting the limit values. The best way to describe the effect is to examine the "0 to 0" limit case. This case specifies that the bodies should not move along the axis, forcing them to stay at their initial location along the axis. So if the bodies were initially separated when they were joined, they will stay separated at that initial distance.
This joint also supports a motor. The motor is a linear motor along the axis. The motor speed can be positive or negative to indicate motion along or opposite the axis direction. The maximum motor force must be greater than zero for the motor to apply any motion.
- Since:
- 1.0.0
- Version:
- 4.0.1
- Author:
- William Bittle
- See Also:
- Documentation, Prismatic Constraint
-
-
Constructor Summary
Constructors Constructor Description PrismaticJoint(T body1, T body2, Vector2 anchor, Vector2 axis)
Minimal constructor.
-
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.Vector2
getAxis()
Returns the axis in which the joint is allowed move along in world coordinates.double
getJointSpeed()
Returns the current joint speed.double
getJointTranslation()
Returns the current joint translation.LimitState
getLimitState()
Deprecated.Deprecated in 4.0.0.double
getLowerLimit()
Returns the lower limit in meters.double
getMaximumMotorForce()
Returns the maximum force the motor can apply to the joint to achieve the target speed.double
getMotorForce(double invdt)
Returns the applied motor force.double
getMotorSpeed()
Returns the target motor speed in meters / second.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
getReferenceAngle()
Returns the reference angle.double
getUpperLimit()
Returns the upper limit in meters.void
initializeConstraints(TimeStep step, Settings settings)
Performs any initialization of the velocity and position constraints.boolean
isLimitEnabled()
Returns true if the limit is enabled.boolean
isMotorEnabled()
Returns true if the motor is enabled.void
setLimitEnabled(boolean limitEnabled)
Enables or disables the limits.void
setLimits(double lowerLimit, double upperLimit)
Sets the upper and lower limits.void
setLimitsEnabled(double lowerLimit, double upperLimit)
Sets the upper and lower limits and enables the limits.void
setLowerLimit(double lowerLimit)
Sets the lower limit.void
setMaximumMotorForce(double maximumMotorForce)
Sets the maximum force the motor can apply to the joint to achieve the target speed.void
setMotorEnabled(boolean motorEnabled)
Enables or disables the motor.void
setMotorSpeed(double motorSpeed)
Sets the target motor speed.void
setReferenceAngle(double angle)
Sets the reference angle.void
setUpperLimit(double upperLimit)
Sets the upper 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()
-
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
-
PrismaticJoint
public PrismaticJoint(T body1, T body2, Vector2 anchor, Vector2 axis)
Minimal constructor.- Parameters:
body1
- the firstPhysicsBody
body2
- the secondPhysicsBody
anchor
- the anchor point in world coordinatesaxis
- the axis of allowed motion- Throws:
NullPointerException
- if body1, body2, anchor or axis 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)
Description copied from class:Joint
Returns the torque applied to thePhysicsBody
s in order to satisfy the constraint in newton-meters.- 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.
-
getJointSpeed
public double getJointSpeed()
Returns the current joint speed.- Returns:
- double
-
getJointTranslation
public double getJointTranslation()
Returns the current joint translation.- Returns:
- double
-
isMotorEnabled
public boolean isMotorEnabled()
Returns true if the motor is enabled.- Returns:
- boolean
-
setMotorEnabled
public void setMotorEnabled(boolean motorEnabled)
Enables or disables the motor.- Parameters:
motorEnabled
- true if the motor should be enabled
-
getMotorSpeed
public double getMotorSpeed()
Returns the target motor speed in meters / second.- Returns:
- double
-
setMotorSpeed
public void setMotorSpeed(double motorSpeed)
Sets the target motor speed.- Parameters:
motorSpeed
- the target motor speed in meters / second- See Also:
setMaximumMotorForce(double)
-
getMaximumMotorForce
public double getMaximumMotorForce()
Returns the maximum force the motor can apply to the joint to achieve the target speed.- Returns:
- double
-
setMaximumMotorForce
public void setMaximumMotorForce(double maximumMotorForce)
Sets the maximum force the motor can apply to the joint to achieve the target speed.- Parameters:
maximumMotorForce
- the maximum force in newtons; must be greater than zero- Throws:
IllegalArgumentException
- if maxMotorForce is less than zero- See Also:
setMotorSpeed(double)
-
getMotorForce
public double getMotorForce(double invdt)
Returns the applied motor force.- Parameters:
invdt
- the inverse delta time- Returns:
- double
-
isLimitEnabled
public boolean isLimitEnabled()
Returns true if the limit is enabled.- Returns:
- boolean
-
setLimitEnabled
public void setLimitEnabled(boolean limitEnabled)
Enables or disables the limits.- Parameters:
limitEnabled
- true if the limit should be enabled.
-
getLowerLimit
public double getLowerLimit()
Returns the lower limit in meters.- Returns:
- double
-
setLowerLimit
public void setLowerLimit(double lowerLimit)
Sets the lower limit.- Parameters:
lowerLimit
- the lower limit in meters- Throws:
IllegalArgumentException
- if lowerLimit is greater than the current upper limit
-
getUpperLimit
public double getUpperLimit()
Returns the upper limit in meters.- Returns:
- double
-
setUpperLimit
public void setUpperLimit(double upperLimit)
Sets the upper limit.- Parameters:
upperLimit
- the upper limit in meters- Throws:
IllegalArgumentException
- if upperLimit is less than the current lower limit
-
setLimits
public void setLimits(double lowerLimit, double upperLimit)
Sets the upper and lower limits.The lower limit must be less than or equal to the upper limit.
- Parameters:
lowerLimit
- the lower limit in metersupperLimit
- the upper limit in meters- Throws:
IllegalArgumentException
- if lowerLimit is greater than upperLimit
-
setLimitsEnabled
public void setLimitsEnabled(double lowerLimit, double upperLimit)
Sets the upper and lower limits and enables the limits.The lower limit must be less than or equal to the upper limit.
- Parameters:
lowerLimit
- the lower limit in metersupperLimit
- the upper limit in meters- Throws:
IllegalArgumentException
- if lowerLimit is greater than upperLimit- Since:
- 2.2.2
-
getAxis
public Vector2 getAxis()
Returns the axis in which the joint is allowed move along in world coordinates.- Returns:
Vector2
- Since:
- 3.0.0
-
getReferenceAngle
public double getReferenceAngle()
Returns the 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.
- Returns:
- double
- Since:
- 3.0.1
-
setReferenceAngle
public void setReferenceAngle(double angle)
Sets the 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.
This can also be used to override the initial angle between the bodies.
- Parameters:
angle
- the reference angle- Since:
- 3.0.1
- See Also:
getReferenceAngle()
-
getLimitState
@Deprecated public LimitState getLimitState()
Deprecated.Deprecated in 4.0.0.Returns the current state of the limit.- Returns:
LimitState
- Since:
- 3.2.0
-
-