sLerp method
Implementation
Q sLerp(Q o, double amount) {
double cosHalfTheta = x*o.x + y*o.y + z*o.z + w*o.w;
if (cosHalfTheta < 0)
{
o = _q(-o.x, -o.y, -o.z, -o.w);
cosHalfTheta = -cosHalfTheta;
}
if (cosHalfTheta.abs() >= 1.0) return _this;
else if (cosHalfTheta > 0.95) return nLerp(o, amount);
else
{
final halfTheta = math.acos(cosHalfTheta);
final sinHalfTheta = math.sqrt(1.0 - cosHalfTheta*cosHalfTheta);
if (sinHalfTheta.abs() < RaylibConstants.EPSILON)
{
return _q(
x*0.5 + o.x*0.5,
y*0.5 + o.y*0.5,
z*0.5 + o.z*0.5,
w*0.5 + o.w*0.5,
);
}
else
{
final ratioA = math.sin((1 - amount)*halfTheta)/sinHalfTheta;
final ratioB = math.sin(amount*halfTheta)/sinHalfTheta;
return _q(
x*ratioA + o.x*ratioB,
y*ratioA + o.y*ratioB,
z*ratioA + o.z*ratioB,
w*ratioA + o.w*ratioB,
);
}
}
}