Exemple #1
0
        public static FVec3 SlerpUnclamped(FVec3 from, FVec3 to, Fix64 t)
        {
            Fix64 scale0, scale1;

            Fix64 len2 = to.Magnitude();
            Fix64 len1 = from.Magnitude();
            FVec3 v2   = to / len2;
            FVec3 v1   = from / len1;

            Fix64 len   = (len2 - len1) * t + len1;
            Fix64 cosom = Dot(v1, v2);

            if (cosom > ( Fix64 )(1 - 1e-6))
            {
                scale0 = Fix64.One - t;
                scale1 = t;
            }
            else if (cosom < ( Fix64 )(-1 + 1e-6))
            {
                FVec3 axis = OrthoNormalVector(from);
                FQuat q    = FQuat.AngleAxis(( Fix64 )180 * t, axis);
                FVec3 v    = q * from * len;
                return(v);
            }
            else
            {
                Fix64 omega = Fix64.Acos(cosom);
                Fix64 sinom = Fix64.Sin(omega);
                scale0 = Fix64.Sin((Fix64.One - t) * omega) / sinom;
                scale1 = Fix64.Sin(t * omega) / sinom;
            }

            v2 = (v2 * scale1 + v1 * scale0) * len;
            return(v2);
        }