Пример #1
0
        /// <summary>
        ///		Interpolates a single segment of the spline given a parametric value.
        /// </summary>
        /// <param name="index">The point index to treat as t=0. index + 1 is deemed to be t=1</param>
        /// <param name="t">Parametric value</param>
        /// <returns>An interpolated point along the spline.</returns>
        public Quaternion Interpolate(int index, float t, bool useShortestPath)
        {
            Debug.Assert(index >= 0 && index < pointList.Count, "Spline point index overrun.");

            if ((index + 1) == pointList.Count)
            {
                // can't interpolate past the end of the list, just return the last point
                return(pointList[index]);
            }

            // quick special cases
            if (t == 0.0f)
            {
                return(pointList[index]);
            }
            else if (t == 1.0f)
            {
                return(pointList[index + 1]);
            }

            // Time for real interpolation

            // Algorithm uses spherical quadratic interpolation
            Quaternion p = pointList[index];
            Quaternion q = pointList[index + 1];
            Quaternion a = tangentList[index];
            Quaternion b = tangentList[index + 1];

            // return the final result
            return(Quaternion.Squad(t, p, a, b, q, useShortestPath));
        }