Пример #1
0
    /// <summary>
    /// 球面插值
    /// </summary>
    /// <param name="q1">单位四元数</param>
    /// <param name="q2">单位四元数</param>
    /// <param name="t">0--1</param>
    /// <returns>单位四元数</returns>
    public static Quaternion Slerp(Quaternion q1, Quaternion q2, float t)
    {
        Quaternion uq = q1;

        t = MathS.Clamp(t, 0, 1);
        float dot = Quaternion.Dot(q1, q2);

        if ((1 - dot) > Threshold)
        {
            float radian = MathS.Acos(dot);
            if (radian < 0)
            {
                radian = MathS.PI - radian;
            }
            float sin = MathS.Sin(radian);
            float t1  = MathS.Sin((1 - t) * radian) / sin;
            float t2  = MathS.Sin(t * radian) / sin;
            uq = q1 * t1 + q2 * t2;
        }
        return(uq);
    }
Пример #2
0
 public static float Angle(Vector2 lhs, Vector2 rhs)
 {
     lhs.Normalize();
     rhs.Normalize();
     return(MathS.Acos(lhs.Dot(rhs)) * MathS.RadToDeg);
 }