lerpQuaternion static method
List<double>
lerpQuaternion(
- dynamic quaternionA,
- dynamic quaternionB,
- 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;
}