lerpQuaternion static method

List<double> lerpQuaternion(
  1. dynamic quaternionA,
  2. dynamic quaternionB,
  3. dynamic t
)

Implementation

static List<double> lerpQuaternion(quaternionA, quaternionB, t) {
  var product = _dot(quaternionA, quaternionB);

  // Clamp product to -1.0 <= product <= 1.0
  product = max<double>(min<double>(product, 1.0), -1.0);

  List<double> quaternionDst = List.filled(4, 0);
  if (product.abs() == 1.0) {
    return quaternionDst = quaternionA;
  }

  var theta = acos(product);
  var w = sin(t * theta) * 1 / sqrt(1 - product * product);

  for (int i = 0; i < 4; i++) {
    quaternionA[i] *= cos(t * theta) - product * w;
    quaternionB[i] *= w;
    quaternionDst[i] = quaternionA[i] + quaternionB[i];
  }

  return quaternionDst;
}