-
- Type Parameters:
T
- thePhysicsBody
type
- All Implemented Interfaces:
DataContainer
,Shiftable
,Ownable
public class WheelJoint<T extends PhysicsBody> extends Joint<T> implements Shiftable, DataContainer
Implementation of a wheel joint.A wheel joint is used to simulate a vehicle's wheel and suspension. The wheel is allowed to rotate freely about the given anchor point. The suspension is allowed to translate freely along the given axis. The whole system can translate and rotate freely.
By default the frequency and damping ratio are set to 8.0 and 0.0 respectively. By definition this joint requires a frequency greater than zero to perform properly. If a wheel without suspension is required, use a
RevoluteJoint
instead.This joint also supports a motor. The motor is an angular motor about the anchor point. The motor speed can be positive or negative to indicate a clockwise or counter-clockwise rotation. The maximum motor torque must be greater than zero for the motor to apply any motion.
The joint also supports upper and lower limits. The limits represent the maximum displacement from the anchor point along the given axis.
- Since:
- 3.0.0
- Version:
- 4.0.1
- Author:
- William Bittle
- See Also:
- Documentation
-
-
Constructor Summary
Constructors Constructor Description WheelJoint(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.double
getAngularSpeed()
Returns the current angular speed between the two joined bodies.double
getAngularTranslation()
Returns the current angular translation between the joined bodies.Vector2
getAxis()
Returns the axis in which the joint is allowed move along in world coordinates.double
getDampingRatio()
Returns the damping ratio.double
getFrequency()
Returns the spring frequency.double
getJointSpeed()
Deprecated.Replaced bygetAngularSpeed()
in 3.2.1double
getJointTranslation()
Deprecated.Replaced bygetLinearTranslation()
in 3.2.1double
getLinearSpeed()
Returns the linear speed along the axis between the two joined bodiesdouble
getLinearTranslation()
Returns the current linear translation along the joint axis.double
getLowerLimit()
Returns the lower limit in meters.double
getMaximumMotorTorque()
Returns the maximum torque the motor can apply to the joint to achieve the target speed.double
getMotorSpeed()
Returns the target motor speed in radians / second.double
getMotorTorque(double invdt)
Returns the applied motor torque.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
isLimitEnabled()
Returns true if the limit is enabled.boolean
isMotorEnabled()
Returns true if the motor is enabled.boolean
isSpring()
Deprecated.Deprecated in 4.0.0.boolean
isSpringDamper()
Deprecated.Deprecated in 4.0.0.boolean
isSpringDamperEnabled()
Returns true if this distance joint is a spring distance joint with damping.boolean
isSpringEnabled()
Returns true if this distance joint is a spring distance joint.void
setDampingRatio(double dampingRatio)
Sets the damping ratio.void
setFrequency(double frequency)
Sets the spring frequency.void
setLimitEnabled(boolean flag)
Enables or disables the limit.void
setLimits(double lowerLimit, double upperLimit)
Sets the upper and lower limits.void
setLowerLimit(double lowerLimit)
Sets the lower limit.void
setMaximumMotorTorque(double maximumMotorTorque)
Sets the maximum torque 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
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
-
WheelJoint
public WheelJoint(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
@Deprecated public double getJointSpeed()
Deprecated.Replaced bygetAngularSpeed()
in 3.2.1Returns the current joint speed.- Returns:
- double
-
getLinearSpeed
public double getLinearSpeed()
Returns the linear speed along the axis between the two joined bodies- Returns:
- double
- Since:
- 3.2.1
-
getAngularSpeed
public double getAngularSpeed()
Returns the current angular speed between the two joined bodies.- Returns:
- double
- Since:
- 3.2.1
-
getJointTranslation
@Deprecated public double getJointTranslation()
Deprecated.Replaced bygetLinearTranslation()
in 3.2.1Returns the current joint translation.- Returns:
- double
-
getLinearTranslation
public double getLinearTranslation()
Returns the current linear translation along the joint axis.- Returns:
- double
- Since:
- 3.2.1
-
getAngularTranslation
public double getAngularTranslation()
Returns the current angular translation between the joined bodies.- Returns:
- double
- Since:
- 3.2.1
-
isSpring
@Deprecated public boolean isSpring()
Deprecated.Deprecated in 4.0.0. Use theisSpringEnabled()
method instead.Returns true if this wheel joint is a spring wheel joint.Since the frequency cannot be less than or equal to zero, this should always returne true.
- Returns:
- boolean
-
isSpringDamper
@Deprecated public boolean isSpringDamper()
Deprecated.Deprecated in 4.0.0. Use theisSpringDamperEnabled()
method instead.Returns true if this wheel joint is a spring wheel joint with damping.- Returns:
- boolean
-
isSpringEnabled
public boolean isSpringEnabled()
Returns true if this distance joint is a spring distance joint.- Returns:
- boolean
- Since:
- 4.0.0
-
isSpringDamperEnabled
public boolean isSpringDamperEnabled()
Returns true if this distance joint is a spring distance joint with damping.- Returns:
- boolean
- Since:
- 4.0.0
-
getDampingRatio
public double getDampingRatio()
Returns the damping ratio.- Returns:
- double
-
setDampingRatio
public void setDampingRatio(double dampingRatio)
Sets the damping ratio.Larger values reduce the oscillation of the spring.
- Parameters:
dampingRatio
- the damping ratio; in the range [0, 1]- Throws:
IllegalArgumentException
- if damping ration is less than zero or greater than 1
-
getFrequency
public double getFrequency()
Returns the spring frequency.- Returns:
- double
-
setFrequency
public void setFrequency(double frequency)
Sets the spring frequency.Larger values increase the stiffness of the spring.
- Parameters:
frequency
- the spring frequency in hz; must be greater than zero- Throws:
IllegalArgumentException
- if frequency is less than or equal to zero
-
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 radians / second.- Returns:
- double
-
setMotorSpeed
public void setMotorSpeed(double motorSpeed)
Sets the target motor speed.- Parameters:
motorSpeed
- the target motor speed in radians / second- See Also:
setMaximumMotorTorque(double)
-
getMaximumMotorTorque
public double getMaximumMotorTorque()
Returns the maximum torque the motor can apply to the joint to achieve the target speed.- Returns:
- double
-
setMaximumMotorTorque
public void setMaximumMotorTorque(double maximumMotorTorque)
Sets the maximum torque the motor can apply to the joint to achieve the target speed.- Parameters:
maximumMotorTorque
- the maximum torque in newtons-meters; in the range [0, ∞]- Throws:
IllegalArgumentException
- if maxMotorTorque is less than zero- See Also:
setMotorSpeed(double)
-
getMotorTorque
public double getMotorTorque(double invdt)
Returns the applied motor torque.- Parameters:
invdt
- the inverse delta time from the time step- Returns:
- double
-
isLimitEnabled
public boolean isLimitEnabled()
Returns true if the limit is enabled.- Returns:
- boolean
-
setLimitEnabled
public void setLimitEnabled(boolean flag)
Enables or disables the limit.- Parameters:
flag
- true if the limit should be enabled
-
getUpperLimit
public double getUpperLimit()
Returns the upper limit in meters.- Returns:
- double
-
setUpperLimit
public void setUpperLimit(double upperLimit)
Sets the upper limit.Must be greater than or equal to the current lower limit.
- Parameters:
upperLimit
- the upper limit in meters- Throws:
IllegalArgumentException
- if upperLimit is less than the current lower limit
-
getLowerLimit
public double getLowerLimit()
Returns the lower limit in meters.- Returns:
- double
-
setLowerLimit
public void setLowerLimit(double lowerLimit)
Sets the lower limit.Must be less than or equal to the current upper limit.
- Parameters:
lowerLimit
- the lower limit in meters- Throws:
IllegalArgumentException
- if lowerLimit is greater than the current upper 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 the lowerLimit is greater than upperLimit
-
-