示例#1
0
        /// <summary>
        /// Slerp the quaternion by t.
        /// </summary>
        public static Quaternion3d Slerp(Quaternion3d from, Quaternion3d to, double t)
        {
            if (t <= 0.0)
            {
                return(from);
            }
            else if (t >= 1.0)
            {
                return(to);
            }
            else
            {
                double cosom    = from.x * to.x + from.y * to.y + from.z * to.z + from.w * to.w;
                double absCosom = Math.Abs(cosom);

                double scale0;
                double scale1;

                if (1.0 - absCosom > DMath.EPS)
                {
                    double omega = DMath.SafeAcos(absCosom);
                    double sinom = 1.0 / Math.Sin(omega);
                    scale0 = Math.Sin((1.0 - t) * omega) * sinom;
                    scale1 = Math.Sin(t * omega) * sinom;
                }
                else
                {
                    scale0 = 1.0 - t;
                    scale1 = t;
                }

                Quaternion3d res = new Quaternion3d(scale0 * from.x + scale1 * to.x,
                                                    scale0 * from.y + scale1 * to.y,
                                                    scale0 * from.z + scale1 * to.z,
                                                    scale0 * from.w + scale1 * to.w);

                return(res.Normalized);
            }
        }
示例#2
0
 /// <summary>
 /// Create a rotation out of a vector.
 /// </summary>
 static public Matrix3x3d Rotate(Vector3d euler)
 {
     return(Quaternion3d.FromEuler(euler).ToMatrix3x3d());
 }