public static Quaternionf slerp ( Quaternionf a , Quaternionf b , float percent ) { final float inverted ; float cosineTheta = a . dot ( b ) ; if ( cosineTheta < 0 ) { cosineTheta = - cosineTheta ; inverted = - 1 ; } else { inverted = 1 ; } if ( 1 - cosineTheta < GenericMath . FLT_EPSILON ) { return a . mul ( 1 - percent ) . add ( b . mul ( percent * inverted ) ) ; } final float theta = ( float ) TrigMath . acos ( cosineTheta ) ; final float sineTheta = TrigMath . sin ( theta ) ; final float coefficient1 = TrigMath . sin ( ( 1 - percent ) * theta ) / sineTheta ; final float coefficient2 = TrigMath . sin ( percent * theta ) / sineTheta * inverted ; return a . mul ( coefficient1 ) . add ( b . mul ( coefficient2 ) ) ; }
Interpolates a quaternion between two others using spherical linear interpolation .