Class HingeJoint

All Implemented Interfaces:
com.jme3.export.Savable, com.jme3.util.clone.JmeCloneable, Cloneable, Comparable<NativePhysicsObject>

public class HingeJoint extends Constraint
A single degree-of-freedom joint based on Bullet's btHingeConstraint.

From the Bullet manual:
Hinge constraint, or revolute joint restricts two additional angular degrees of freedom, so the body can only rotate around one axis, the hinge axis. This can be useful to represent doors or wheels rotating around one axis. The user can specify limits and motor for the hinge.

  • Field Details

    • logger2

      public static final Logger logger2
      message logger for this class
  • Constructor Details

    • HingeJoint

      protected HingeJoint()
      No-argument constructor needed by SavableClassUtil.
    • HingeJoint

      public HingeJoint(PhysicsRigidBody rigidBodyA, com.jme3.math.Vector3f pivotInA, com.jme3.math.Vector3f pivotInWorld, com.jme3.math.Vector3f axisInA, com.jme3.math.Vector3f axisInWorld, JointEnd referenceFrame)
      Instantiate a single-ended HingeJoint.

      To be effective, the joint must be added to the body's PhysicsSpace and the body must be dynamic.

      Parameters:
      rigidBodyA - the body to constrain (not null, alias created)
      pivotInA - the pivot location in A's scaled local coordinates (not null, unaffected)
      pivotInWorld - the pivot location in physics-space coordinates (not null, unaffected)
      axisInA - the joint axis in A's local coordinates (unit vector, unaffected)
      axisInWorld - the joint axis in physics-space coordinates (unit vector, unaffected)
      referenceFrame - which end to use as the reference frame (not null)
    • HingeJoint

      public HingeJoint(PhysicsRigidBody rigidBodyA, PhysicsRigidBody rigidBodyB, com.jme3.math.Vector3f pivotInA, com.jme3.math.Vector3f pivotInB, com.jme3.math.Vector3f axisInA, com.jme3.math.Vector3f axisInB)
      Instantiate a double-ended HingeJoint.

      To be effective, the joint must be added to the PhysicsSpace of both bodies. Also, the bodies must be distinct and at least one of them must be dynamic.

      Parameters:
      rigidBodyA - the body for the A end (not null, alias created)
      rigidBodyB - the body for the B end (not null, alias created)
      pivotInA - the pivot location in A's scaled local coordinates (not null, unaffected)
      pivotInB - the pivot location in B's scaled local coordinates (not null, unaffected)
      axisInA - the joint axis in A's local coordinates (unit vector, unaffected)
      axisInB - the joint axis in B's local coordinates (unit vector, unaffected)
  • Method Details

    • enableMotor

      public void enableMotor(boolean enable, float targetVelocity, float maxMotorImpulse)
      Enable or disable this joint's motor.
      Parameters:
      enable - true to enable, false to disable (default=false)
      targetVelocity - the desired target velocity
      maxMotorImpulse - the desired maximum rotational force
    • getBiasFactor

      public float getBiasFactor()
      Read this joint's bias factor.
      Returns:
      the magnitude of the position correction: how strictly position errors (drift) are corrected
    • getEnableMotor

      public boolean getEnableMotor()
      Test whether this joint's motor is enabled.
      Returns:
      true if enabled, otherwise false
    • getFrameTransform

      public com.jme3.math.Transform getFrameTransform(JointEnd end, com.jme3.math.Transform storeResult)
      Copy the joint's frame transform relative to the specified end.
      Parameters:
      end - which end (not null)
      storeResult - storage for the result (modified if not null)
      Returns:
      the transform of the constraint space relative to the end
    • getHingeAngle

      public float getHingeAngle()
      Read the hinge angle.
      Returns:
      the angle (in radians)
    • getLimitSoftness

      public float getLimitSoftness()
      Read this joint's limit softness.
      Returns:
      the range fraction at which velocity-error correction starts operating
    • getLowerLimit

      public final float getLowerLimit()
      Read the lower limit of the hinge angle.
      Returns:
      the angle (in radians)
    • getMotorTargetVelocity

      public float getMotorTargetVelocity()
      Read the motor's target velocity.
      Returns:
      velocity
    • getMaxMotorImpulse

      public float getMaxMotorImpulse()
      Read the motor's maximum impulse.
      Returns:
      impulse
    • getRelaxationFactor

      public float getRelaxationFactor()
      Read this joint's relaxation factor.
      Returns:
      the rate at which velocity errors are corrected
    • getUpperLimit

      public final float getUpperLimit()
      Read the upper limit of the hinge angle.
      Returns:
      angle (in radians)
    • isAngularOnly

      public boolean isAngularOnly()
      Test whether this joint is angular-only, meaning no constraints on translation.
      Returns:
      true if angular-only, otherwise false
    • setAngularOnly

      public void setAngularOnly(boolean angularOnly)
      Alter whether this joint is angular-only, meaning no constraints on translation.
      Parameters:
      angularOnly - true→translation is free, false→translation is constrained (default=false)
    • setLimit

      public void setLimit(float low, float high)
      Alter the angular limits for this joint.
      Parameters:
      low - the desired lower limit of the hinge angle (in radians, default=1)
      high - the desired upper limit of the hinge angle (in radians, default=-1)
    • setLimit

      public void setLimit(float low, float high, float softness, float bias, float relaxation)
      Alter the angular limits for this joint.

      If you're above the softness, velocities that would shoot through the actual limit are slowed down. The bias should be in the range of 0.2 - 0.5.

      Parameters:
      low - the desired lower limit of the hinge angle (in radians, default=1)
      high - the desired upper limit of the hinge angle (in radians, default=-1)
      softness - the desired range fraction at which velocity-error correction starts operating. A softness of 0.9 means that the correction starts at 90% of the limit range. (default=0.9)
      bias - the desired magnitude of the position correction: how strictly position errors (drift) are corrected (default=0.3)
      relaxation - the desired rate at which velocity errors are corrected. This can be seen as the strength of the limits. A low value will make the limits more spongy. (default=1)
    • cloneFields

      public void cloneFields(com.jme3.util.clone.Cloner cloner, Object original)
      Callback from Cloner to convert this shallow-cloned object into a deep-cloned one, using the specified Cloner and original to resolve copied fields.
      Specified by:
      cloneFields in interface com.jme3.util.clone.JmeCloneable
      Overrides:
      cloneFields in class Constraint
      Parameters:
      cloner - the Cloner that's cloning this joint (not null)
      original - the instance from which this joint was shallow-cloned (not null, unaffected)
    • read

      public void read(com.jme3.export.JmeImporter importer) throws IOException
      De-serialize this joint from the specified importer, for example when loading from a J3O file.
      Specified by:
      read in interface com.jme3.export.Savable
      Overrides:
      read in class Constraint
      Parameters:
      importer - (not null)
      Throws:
      IOException - from the importer
    • write

      public void write(com.jme3.export.JmeExporter exporter) throws IOException
      Serialize this joint to the specified exporter, for example when saving to a J3O file.
      Specified by:
      write in interface com.jme3.export.Savable
      Overrides:
      write in class Constraint
      Parameters:
      exporter - (not null)
      Throws:
      IOException - from the exporter