Class VehicleController

java.lang.Object
com.jme3.bullet.NativePhysicsObject
com.jme3.bullet.objects.infos.VehicleController
All Implemented Interfaces:
Comparable<NativePhysicsObject>

public class VehicleController extends NativePhysicsObject
The "action" (controller) portion of a PhysicsVehicle, based on Bullet's btRaycastVehicle.
  • Field Details

    • logger

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

    • VehicleController

      public VehicleController(PhysicsVehicle vehicle, PhysicsSpace space)
      Instantiate a controller for the specified collision object.
      Parameters:
      vehicle - the collision object to control (not null)
      space - the PhysicsSpace where the collision object is or will be added (not null)
  • Method Details

    • addWheel

      public int addWheel(VehicleWheel wheel, VehicleTuning tuning)
      Add a wheel to this controller. Used internally.
      Parameters:
      wheel - (not null, unaffected)
      tuning - (not null, unaffected)
      Returns:
      the wheel index to be assigned (≥0)
    • applyEngineForce

      public void applyEngineForce(VehicleWheel wheel, float force)
      Apply the specified engine force to the specified wheel. Works continuously. The vehicle must be added to a PhysicsSpace.
      Parameters:
      wheel - which wheel (not null)
      force - the desired amount of force (may be negative)
    • brake

      public void brake(VehicleWheel wheel, float impulse)
      Apply the specified brake impulse to the specified wheel. Works continuously. The vehicle must be added to a PhysicsSpace.
      Parameters:
      wheel - which wheel (not null)
      impulse - the desired impulse
    • castRay

      public float castRay(VehicleWheel wheel)
      Determine the depth for the specified wheel by raycasting. The vehicle must be added to a PhysicsSpace.
      Parameters:
      wheel - which wheel (not null, unaffected)
      Returns:
      the depth value, or -1 if the raycast finds no result
    • countWheels

      public int countWheels()
      Determine the number of wheels in this controller.
      Returns:
      the count (≥0)
    • forwardAxisIndex

      public int forwardAxisIndex()
      Determine the index of the vehicle's forward axis. The vehicle must be added to a PhysicsSpace.
      Returns:
      the index of the local axis: 0→X, 1→Y, 2→Z, -1→custom axes
    • getCurrentVehicleSpeedKmHour

      public float getCurrentVehicleSpeedKmHour()
      Determine the vehicle's speed in km/h. The vehicle must be added to a PhysicsSpace.
      Returns:
      the speed (in kilometers per hour, positive in the forward direction)
    • getForwardVector

      public Vector3f getForwardVector(Vector3f storeResult)
      Determine the vehicle's forward direction. The vehicle must be added to a PhysicsSpace.
      Parameters:
      storeResult - storage for the result (modified if not null)
      Returns:
      a direction vector (in physics-space coordinates, either storeResult or a new vector, not null)
    • resetSuspension

      public void resetSuspension()
      Reset the vehicle's suspension. The vehicle must be added to a PhysicsSpace.
    • rightAxisIndex

      public int rightAxisIndex()
      Determine the index of the vehicle's right-side axis. The vehicle must be added to a PhysicsSpace.
      Returns:
      the index of the local axis: 0→X, 1→Y, 2→Z, -1→custom axes
    • setCoordinateSystem

      public void setCoordinateSystem(int rightAxisIndex, int upAxisIndex, int forwardAxisIndex)
      Alter the coordinate system of the vehicle. Note that the Libbulletjme's default coordinate system is left-handed. That's not required, nor is it even a good idea.
      Parameters:
      rightAxisIndex - the desired local axis index (0→X, 1→Y, 2→Z, default=0)
      upAxisIndex - the desired local axis index (0→X, 1→Y, 2→Z, default=1)
      forwardAxisIndex - the desired local axis index (0→X, 1→Y, 2→Z, default=2)
    • setCoordinateSystem

      public void setCoordinateSystem(Vector3f right, Vector3f up, Vector3f forward)
      Customize the coordinate system of the vehicle. The arguments must form an orthonormal basis. Note that the Libbulletjme's default coordinate system is left-handed. That's not required, nor is it even a good idea.
      Parameters:
      right - the desired direction (in chassis coordinates, not null, length=1, default=(1,0,0))
      up - the desired direction (in chassis coordinates, not null, length=1, default=(0,1,0))
      forward - the desired direction (in chassis coordinates, not null, length=1, default=(0,0,1))
    • steer

      public void steer(VehicleWheel wheel, float angle)
      Alter the steering angle of the specified wheel. The vehicle must be added to a PhysicsSpace.
      Parameters:
      wheel - which wheel to steer (not null)
      angle - the desired angle (in radians, 0=straight, positive=left)
    • upAxisIndex

      public int upAxisIndex()
      Determine the index of the vehicle's up axis. The vehicle must be added to a PhysicsSpace.
      Returns:
      the index of the local axis: 0→X, 1→Y, 2→Z, -1→custom axes
    • updateWheelTransform

      public void updateWheelTransform(VehicleWheel wheel)
      Used internally.
      Parameters:
      wheel - (not null)