Class VehicleWheel

java.lang.Object
com.jme3.bullet.objects.VehicleWheel

public class VehicleWheel extends Object
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
    Constructor
    Description
    VehicleWheel(Vector3f location, Vector3f direction, Vector3f axle, float restLength, float radius, boolean frontWheel)
    Instantiate a wheel.
  • Method Summary

    Modifier and Type
    Method
    Description
    getAxle(Vector3f storeResult)
    Determine this wheel's axis direction.
    float
    Determine this wheel's braking impulse (native field: m_brake).
    Determine the location where the wheel touches the ground.
    Determine the normal direction where the wheel touches the ground.
    float
    Determine how much this wheel has turned since the last simulation step.
    getDirection(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.
    getLocation(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).
    Determine this wheel's location.
    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).
    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
    Update this wheel's location and orientation.

    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

      public VehicleWheel(Vector3f location, Vector3f direction, Vector3f axle, float restLength, float radius, boolean frontWheel)
      Instantiate a wheel.
      Parameters:
      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

    • getAxle

      public Vector3f getAxle(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 Vector3f getCollisionLocation(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 Vector3f getCollisionNormal(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 Vector3f getDirection(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 Vector3f getLocation(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
    • getWheelWorldLocation

      public Vector3f getWheelWorldLocation(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 Quaternion getWheelWorldRotation(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)
    • updatePhysicsState

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