Class VehicleWheel

java.lang.Object
com.jme3.bullet.objects.VehicleWheel
All Implemented Interfaces:
com.jme3.export.Savable, com.jme3.util.clone.JmeCloneable, Cloneable

public class VehicleWheel extends Object implements com.jme3.util.clone.JmeCloneable, com.jme3.export.Savable
Information about one wheel of a vehicle, based on Bullet's btWheelInfo.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Logger
    message logger for this class
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    No-argument constructor needed by SavableClassUtil.
     
    VehicleWheel(com.jme3.scene.Spatial subtree, com.jme3.math.Vector3f location, com.jme3.math.Vector3f direction, com.jme3.math.Vector3f axle, float restLength, float radius, boolean frontWheel)
    Instantiate a wheel.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Apply this wheel's physics location and orientation to its visualization, if any.
    void
    cloneFields(com.jme3.util.clone.Cloner cloner, Object original)
    Callback from Cloner to convert this shallow-cloned wheel into a deep-cloned one, using the specified Cloner and original to resolve copied fields.
    com.jme3.math.Vector3f
    getAxle(com.jme3.math.Vector3f storeResult)
    Determine this wheel's axis direction.
    float
    Determine this wheel's braking impulse (native field: m_brake).
    com.jme3.math.Vector3f
    For compatibility with the jme3-jbullet library.
    com.jme3.math.Vector3f
    getCollisionLocation(com.jme3.math.Vector3f storeResult)
    Determine the location where the wheel touches the ground.
    com.jme3.math.Vector3f
    For compatibility with the jme3-jbullet library.
    com.jme3.math.Vector3f
    getCollisionNormal(com.jme3.math.Vector3f storeResult)
    Determine the normal direction where the wheel touches the ground.
    float
    Determine how much this wheel has turned since the last simulation step.
    com.jme3.math.Vector3f
    getDirection(com.jme3.math.Vector3f storeResult)
    Determine this wheel's suspension direction.
    float
    Determine this wheel's engine force (native field: m_engineForce).
    float
    Determine the friction between this wheel's tire and the ground (native field: m_frictionSlip).
    int
    Determine the index of this wheel, based on creation order.
    com.jme3.math.Vector3f
    For compatibility with the jme3-jbullet library.
    com.jme3.math.Vector3f
    getLocation(com.jme3.math.Vector3f storeResult)
    Determine the location where the suspension connects to the chassis.
    float
    Determine the maximum force exerted by this wheel's suspension (native field: m_maxSuspensionForce).
    float
    Determine the maximum travel distance for this wheel's suspension (native field: m_maxSuspensionTravelCm).
    float
    Determine the radius of this wheel (native field: m_wheelsRadius).
    float
    Determine the rest length of this wheel (native field: m_suspensionRestLength1).
    float
    Determine this wheel's roll influence (native field: m_rollInfluence).
    float
    Determine the total rotation of this wheel (native field: m_rotation).
    float
    Determine to what extent the wheel is skidding (for skid sounds/smoke etcetera).
    float
    Determine this wheel's steering angle (native field: m_steering).
    float
    Determine the length of this wheel's suspension (native field: m_suspensionLength).
    float
    Determine the stiffness of this wheel's suspension (native field: m_suspensionStiffness).
    float
    Determine this wheel's damping when the suspension is compressed (native field: m_wheelsDampingCompression).
    float
    Determine this wheel's damping when the suspension is expanded (native field: m_wheelsDampingRelaxation).
    com.jme3.scene.Spatial
    Access the scene-graph subtree used to visualize this wheel.
    com.jme3.math.Vector3f
    getWheelWorldLocation(com.jme3.math.Vector3f storeResult)
    Determine this wheel's location.
    com.jme3.math.Quaternion
    getWheelWorldRotation(com.jme3.math.Quaternion storeResult)
    Determine this wheel's orientation.
    boolean
    Test whether physics coordinates should match the local transform of the Spatial.
    boolean
    Test whether this wheel is a front (steering) wheel (native field: m_bIsFrontWheel).
    Create a shallow clone for the JME cloner.
    void
    read(com.jme3.export.JmeImporter importer)
    De-serialize this wheel from the specified importer, for example when loading from a J3O file.
    void
    setApplyLocal(boolean applyLocal)
    Alter whether physics coordinates should match the local transform of the Spatial.
    void
    setFrictionSlip(float coeff)
    Alter the friction between this wheel's tire and the ground (native field: m_frictionSlip).
    void
    setFrontWheel(boolean frontWheel)
    Alter whether this wheel is a front (steering) wheel (native field: m_bIsFrontWheel).
    void
    setMaxSuspensionForce(float maxForce)
    Alter the maximum force exerted by this wheel's suspension (native field: m_maxSuspensionForce).
    void
    setMaxSuspensionTravelCm(float travelCm)
    Alter the maximum travel distance for this wheel's suspension (native field: m_maxSuspensionTravelCm).
    void
    setRadius(float radius)
    Alter the radius of this wheel (native field: m_wheelsRadius).
    void
    setRestLength(float restLength)
    Alter the rest length of the suspension of this wheel (native field: m_suspensionRestLength1).
    void
    setRollInfluence(float rollInfluence)
    Alter this wheel's roll influence (native field: m_rollInfluence).
    void
    setRotationAngle(float angle)
    Alter the total rotation of this wheel (native field: m_rotation).
    void
    setSuspensionLength(float length)
    Alter the length of this wheel's suspension (native field: m_suspensionLength).
    void
    setSuspensionStiffness(float stiffness)
    Alter the stiffness of this wheel's suspension (native field: m_suspensionStiffness).
    void
    setVehicleId(long vehicleId, int wheelIndex)
    Assign this wheel to a vehicle.
    void
    Alter this wheel's damping when the suspension is compressed (native field: m_wheelsDampingCompression).
    void
    setWheelsDampingRelaxation(float wheelsDampingRelaxation)
    Alter this wheel's damping when the suspension is expanded (native field: m_wheelsDampingRelaxation).
    void
    setWheelSpatial(com.jme3.scene.Spatial subtree)
    Alter which scene-graph subtree is used to visualize this wheel.
    void
    Update this wheel's location and orientation.
    void
    write(com.jme3.export.JmeExporter exporter)
    Serialize this wheel to the specified exporter, for example when saving to a J3O file.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • logger

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

    • VehicleWheel

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

      public VehicleWheel(com.jme3.scene.Spatial subtree, com.jme3.math.Vector3f location, com.jme3.math.Vector3f direction, com.jme3.math.Vector3f axle, float restLength, float radius, boolean frontWheel)
      Instantiate a wheel.
      Parameters:
      subtree - the scene-graph subtree to visualize this wheel (alias created) or null for none
      location - the location where the suspension connects to the chassis (in chassis coordinates, not null, unaffected)
      direction - the suspension direction (in chassis coordinates, not null, unaffected, typically down/0,-1,0)
      axle - the axis direction (in chassis coordinates, not null, unaffected, typically right/-1,0,0)
      restLength - the rest length of the suspension (in physics-space units)
      radius - the wheel's radius (in physics-space units, ≥0)
      frontWheel - true→front (steering) wheel, false→non-front wheel
  • Method Details

    • applyWheelTransform

      public void applyWheelTransform()
      Apply this wheel's physics location and orientation to its visualization, if any.
    • getAxle

      public com.jme3.math.Vector3f getAxle(com.jme3.math.Vector3f storeResult)
      Determine this wheel's axis direction.
      Parameters:
      storeResult - storage for the result (modified if not null)
      Returns:
      a new unit vector (in chassis coordinates, either storeResult or a new instance)
    • getBrake

      public float getBrake()
      Determine this wheel's braking impulse (native field: m_brake).
      Returns:
      the amount of impulse
    • getCollisionLocation

      public com.jme3.math.Vector3f getCollisionLocation()
      For compatibility with the jme3-jbullet library.
      Returns:
      a new location vector (in physics-space coordinates, not null)
    • getCollisionLocation

      public com.jme3.math.Vector3f getCollisionLocation(com.jme3.math.Vector3f storeResult)
      Determine the location where the wheel touches the ground.
      Parameters:
      storeResult - storage for the result (modified if not null)
      Returns:
      a location vector (in physics-space coordinates, either storeResult or a new instance)
    • getCollisionNormal

      public com.jme3.math.Vector3f getCollisionNormal()
      For compatibility with the jme3-jbullet library.
      Returns:
      a new unit vector (in physics-space coordinates, not null)
    • getCollisionNormal

      public com.jme3.math.Vector3f getCollisionNormal(com.jme3.math.Vector3f storeResult)
      Determine the normal direction where the wheel touches the ground.
      Parameters:
      storeResult - storage for the result (modified if not null)
      Returns:
      a unit vector (in physics-space coordinates, either storeResult or a new instance)
    • getDeltaRotation

      public float getDeltaRotation()
      Determine how much this wheel has turned since the last simulation step.
      Returns:
      the rotation angle (in radians)
    • getDirection

      public com.jme3.math.Vector3f getDirection(com.jme3.math.Vector3f storeResult)
      Determine this wheel's suspension direction.
      Parameters:
      storeResult - storage for the result (modified if not null)
      Returns:
      a unit vector (in chassis coordinates, either storeResult or a new instance)
    • getEngineForce

      public float getEngineForce()
      Determine this wheel's engine force (native field: m_engineForce).
      Returns:
      the amount of force applied (TODO positive direction?)
    • getFrictionSlip

      public float getFrictionSlip()
      Determine the friction between this wheel's tire and the ground (native field: m_frictionSlip).
      Returns:
      the coefficient of friction
    • getIndex

      public int getIndex()
      Determine the index of this wheel, based on creation order.
      Returns:
      the zero-origin index (≥0)
    • getLocation

      public com.jme3.math.Vector3f getLocation()
      For compatibility with the jme3-jbullet library. The jme3-jbullet version returns a pre-existing vector instead of a new one.
      Returns:
      a new location vector (in physics-space coordinates, not null)
    • getLocation

      public com.jme3.math.Vector3f getLocation(com.jme3.math.Vector3f storeResult)
      Determine the location where the suspension connects to the chassis.
      Parameters:
      storeResult - storage for the result (modified if not null)
      Returns:
      a new location vector (in chassis coordinates, either storeResult or a new instance)
    • getMaxSuspensionForce

      public float getMaxSuspensionForce()
      Determine the maximum force exerted by this wheel's suspension (native field: m_maxSuspensionForce).
      Returns:
      the maximum force
    • getMaxSuspensionTravelCm

      public float getMaxSuspensionTravelCm()
      Determine the maximum travel distance for this wheel's suspension (native field: m_maxSuspensionTravelCm). Note that the units are centimeters ONLY if the physics-space unit is exactly one meter.
      Returns:
      the maximum amount the suspension can be compressed or expanded, relative to its rest length (in hundredths of a physics-space unit)
    • getRadius

      public float getRadius()
      Determine the radius of this wheel (native field: m_wheelsRadius).
      Returns:
      the radius (in physics-space units, ≥0)
    • getRestLength

      public float getRestLength()
      Determine the rest length of this wheel (native field: m_suspensionRestLength1).
      Returns:
      the length
    • getRollInfluence

      public float getRollInfluence()
      Determine this wheel's roll influence (native field: m_rollInfluence).
      Returns:
      the roll-influence factor
    • getRotationAngle

      public float getRotationAngle()
      Determine the total rotation of this wheel (native field: m_rotation).
      Returns:
      the angle (in radians)
    • getSkidInfo

      public float getSkidInfo()
      Determine to what extent the wheel is skidding (for skid sounds/smoke etcetera). Don't bother invoking this if the wheel is unsupported---in other words, if PhysicsVehicle.castRay(int) is negative!
      Returns:
      the relative amount of traction (0→wheel is sliding, 1→wheel has full traction)
    • getSteerAngle

      public float getSteerAngle()
      Determine this wheel's steering angle (native field: m_steering).
      Returns:
      angle (in radians, 0=straight, left is positive)
    • getSuspensionLength

      public float getSuspensionLength()
      Determine the length of this wheel's suspension (native field: m_suspensionLength).
      Returns:
      the length (in physics-space units)
    • getSuspensionStiffness

      public float getSuspensionStiffness()
      Determine the stiffness of this wheel's suspension (native field: m_suspensionStiffness).
      Returns:
      the stiffness constant
    • getWheelsDampingCompression

      public float getWheelsDampingCompression()
      Determine this wheel's damping when the suspension is compressed (native field: m_wheelsDampingCompression).
      Returns:
      the damping
    • getWheelsDampingRelaxation

      public float getWheelsDampingRelaxation()
      Determine this wheel's damping when the suspension is expanded (native field: m_wheelsDampingRelaxation).
      Returns:
      the damping
    • getWheelSpatial

      public com.jme3.scene.Spatial getWheelSpatial()
      Access the scene-graph subtree used to visualize this wheel.
      Returns:
      the pre-existing instance, or null
    • getWheelWorldLocation

      public com.jme3.math.Vector3f getWheelWorldLocation(com.jme3.math.Vector3f storeResult)
      Determine this wheel's location.
      Parameters:
      storeResult - storage for the result (modified if not null)
      Returns:
      a location vector (in physics-space coordinates, either storeResult or a new instance)
    • getWheelWorldRotation

      public com.jme3.math.Quaternion getWheelWorldRotation(com.jme3.math.Quaternion storeResult)
      Determine this wheel's orientation.
      Parameters:
      storeResult - storage for the result (modified if not null)
      Returns:
      a Quaternion (in physics-space coordinates, either storeResult or a new instance)
    • isApplyLocal

      public boolean isApplyLocal()
      Test whether physics coordinates should match the local transform of the Spatial.
      Returns:
      true if matching local transform, false if matching world transform
    • isFrontWheel

      public boolean isFrontWheel()
      Test whether this wheel is a front (steering) wheel (native field: m_bIsFrontWheel).
      Returns:
      true if front wheel, otherwise false
    • setApplyLocal

      public void setApplyLocal(boolean applyLocal)
      Alter whether physics coordinates should match the local transform of the Spatial.
      Parameters:
      applyLocal - true→match local transform, false→match world transform (default=false)
    • setFrictionSlip

      public void setFrictionSlip(float coeff)
      Alter the friction between this wheel's tire and the ground (native field: m_frictionSlip).

      Should be about 0.8 for realistic cars, but can be increased for better handling. Set large (10000) for kart racers.

      Parameters:
      coeff - the desired coefficient of friction (default=10.5)
    • setFrontWheel

      public void setFrontWheel(boolean frontWheel)
      Alter whether this wheel is a front (steering) wheel (native field: m_bIsFrontWheel).
      Parameters:
      frontWheel - true→front wheel, false→non-front wheel
    • setMaxSuspensionForce

      public void setMaxSuspensionForce(float maxForce)
      Alter the maximum force exerted by this wheel's suspension (native field: m_maxSuspensionForce).

      Increase this if your suspension cannot handle the weight of your vehicle.

      Parameters:
      maxForce - the desired maximum force (default=6000)
    • setMaxSuspensionTravelCm

      public void setMaxSuspensionTravelCm(float travelCm)
      Alter the maximum travel distance for this wheel's suspension (native field: m_maxSuspensionTravelCm). Note that the units are centimeters ONLY if the physics-space unit is exactly one meter.
      Parameters:
      travelCm - the desired maximum amount the suspension can be compressed or expanded, relative to its rest length (in hundredths of a physics-space unit, default=500)
    • setRadius

      public void setRadius(float radius)
      Alter the radius of this wheel (native field: m_wheelsRadius).
      Parameters:
      radius - the desired radius (in physics-space units, ≥0, default=0.5)
    • setRestLength

      public void setRestLength(float restLength)
      Alter the rest length of the suspension of this wheel (native field: m_suspensionRestLength1).
      Parameters:
      restLength - the desired length (default=1)
    • setRollInfluence

      public void setRollInfluence(float rollInfluence)
      Alter this wheel's roll influence (native field: m_rollInfluence).

      The roll-influence factor reduces (or magnifies) the torque contributed by this wheel that tends to cause the vehicle to roll over. This is a bit of a hack, but it's quite effective.

      If the friction between the tires and the ground is too high, you may reduce this factor to prevent the vehicle from rolling over. You should also try lowering the vehicle's center of mass.

      Parameters:
      rollInfluence - the desired roll-influence factor (0→no roll torque, 1→realistic behavior, default=1)
    • setRotationAngle

      public void setRotationAngle(float angle)
      Alter the total rotation of this wheel (native field: m_rotation).
      Parameters:
      angle - the desired angle (in radians)
    • setSuspensionLength

      public void setSuspensionLength(float length)
      Alter the length of this wheel's suspension (native field: m_suspensionLength). Bullet updates the length during every simulation step.
      Parameters:
      length - the desired length (in physics-space units)
    • setSuspensionStiffness

      public void setSuspensionStiffness(float stiffness)
      Alter the stiffness of this wheel's suspension (native field: m_suspensionStiffness).
      Parameters:
      stiffness - the desired stiffness constant (10→off-road buggy, 50→sports car, 200→Formula-1 race car, default=5.88)
    • setVehicleId

      public void setVehicleId(long vehicleId, int wheelIndex)
      Assign this wheel to a vehicle.
      Parameters:
      vehicleId - the ID of the btRaycastVehicle (not zero)
      wheelIndex - index among the vehicle's wheels (≥0)
    • setWheelsDampingCompression

      public void setWheelsDampingCompression(float damping)
      Alter this wheel's damping when the suspension is compressed (native field: m_wheelsDampingCompression).

      Set to k * 2 * FastMath.sqrt(m_suspensionStiffness) where k is the damping ratio:

      k = 0.0 undamped and bouncy, k = 1.0 critical damping, k between 0.1 and 0.3 are good values

      Parameters:
      damping - the desired damping (0→no damping, default=0.83)
    • setWheelsDampingRelaxation

      public void setWheelsDampingRelaxation(float wheelsDampingRelaxation)
      Alter this wheel's damping when the suspension is expanded (native field: m_wheelsDampingRelaxation).

      Set to k * 2 * FastMath.sqrt(m_suspensionStiffness) where k is the damping ratio:

      k=0: undamped and bouncy, k=1: critical damping, k between 0.1 and 0.3 are good values

      Parameters:
      wheelsDampingRelaxation - the desired damping (default=0.88)
    • setWheelSpatial

      public void setWheelSpatial(com.jme3.scene.Spatial subtree)
      Alter which scene-graph subtree is used to visualize this wheel.
      Parameters:
      subtree - the subtree to use (alias created) or null for none
    • updatePhysicsState

      public void updatePhysicsState()
      Update this wheel's location and orientation.
    • cloneFields

      public void cloneFields(com.jme3.util.clone.Cloner cloner, Object original)
      Callback from Cloner to convert this shallow-cloned wheel 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
      Parameters:
      cloner - the Cloner that's cloning this wheel (not null)
      original - the instance from which this wheel was shallow-cloned (unused)
    • jmeClone

      public VehicleWheel jmeClone()
      Create a shallow clone for the JME cloner.
      Specified by:
      jmeClone in interface com.jme3.util.clone.JmeCloneable
      Returns:
      a new instance
    • read

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

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