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.scale2(-1, up);
  right.setFrom(wheel.axleLocal);
  up.cross2(right, fwd);
  fwd.normalize();
  right.normalize();

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

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

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

  q.normalize();

  // world position of the wheel
  final p = wheel.worldTransform.position;
  p.setFrom(wheel.directionWorld);
  p.scale2(wheel.suspensionLength, p);
  p.add2(wheel.chassisConnectionPointWorld, p);
}