// Slerp interpolates between two unit quaternions, maintaining ''uniticity''. Quaternion Slerp(Quaternion Q0, Quaternion Q1, float T) { float CosTheta = Q0.DotProd(Q1); float Theta = acosf(CosTheta); float SinTheta = sqrtf(1.0f-CosTheta*CosTheta); float Sin_T_Theta = sinf(T*Theta)/SinTheta; float Sin_OneMinusT_Theta = sinf((1.0f-T)*Theta)/SinTheta; Quaternion Result = Q0*Sin_OneMinusT_Theta; Result += (Q1*Sin_T_Theta); return Result; } |