updateWheelTransform method

void updateWheelTransform(
  1. int wheelIndex
)

Update one of the wheel transform. Note when rendering wheels: during each step, wheel transforms are updated BEFORE the chassis; ie. their position becomes invalid after the step. Thus when you render wheels, you must update wheel transforms before rendering them. See raycastVehicle demo for an example. @param wheelIndex The wheel index to update.;

Implementation

void updateWheelTransform(int wheelIndex){
  final up = _tmpVec4;
  final right = _tmpVec5;
  final fwd = _tmpVec6;

  final wheel = wheelInfos[wheelIndex];
  updateWheelTransformWorld(wheel);

  wheel.directionLocal.scale(-1, up);
  right.copy(wheel.axleLocal);
  up.cross(right, fwd);
  fwd.normalize();
  right.normalize();

  // Rotate around steering over the wheelAxle
  final steering = wheel.steering;
  final steeringOrn = Quaternion();
  steeringOrn.setFromAxisAngle(up, steering);

  final rotatingOrn = Quaternion();
  rotatingOrn.setFromAxisAngle(right, wheel.rotation);

  // World rotation of the wheel
  final q = wheel.worldTransform.quaternion;
  chassisBody.quaternion.mult(steeringOrn, q);
  q.mult(rotatingOrn, q);

  q.normalize();

  // world position of the wheel
  final p = wheel.worldTransform.position;
  p.copy(wheel.directionWorld);
  p.scale(wheel.suspensionLength, p);
  p.vadd(wheel.chassisConnectionPointWorld, p);
}