Example #1
0
        /// <summary>Get a worldspace position of a point along the path</summary>
        /// <param name="pos">Postion along the path.  Need not be normalized.</param>
        /// <returns>World-space position of the point along at path at pos</returns>
        public override Vector3 EvaluatePosition(float pos)
        {
            Vector3 result = new Vector3();

            if (Waypoints.Length == 0)
            {
                result = transform.position;
            }
            else
            {
                int indexA, indexB;
                pos = GetBoundingIndices(pos, out indexA, out indexB);
                if (indexA == indexB)
                {
                    result = Waypoints[indexA].Position;
                }
                else
                {
                    // interpolate
                    Waypoint wpA = Waypoints[indexA];
                    Waypoint wpB = Waypoints[indexB];
                    result = ExtSpline.Bezier3(pos - indexA,
                                               Waypoints[indexA].Position, wpA.Position + wpA.Tangent,
                                               wpB.Position - wpB.Tangent, wpB.Position);
                }
            }
            return(transform.TransformPoint(result));
        }
Example #2
0
        /// <summary>Get a worldspace position of a point along the path</summary>
        /// <param name="pos">Position along the path.  Need not be normalized.</param>
        /// <returns>World-space position of the point along at path at pos</returns>
        public override Vector3 EvaluatePosition(float pos)
        {
            Vector3 result = Vector3.zero;

            if (Waypoints.Length > 0)
            {
                UpdateControlPoints();
                int indexA, indexB;
                pos = GetBoundingIndices(pos, out indexA, out indexB);
                if (indexA == indexB)
                {
                    result = Waypoints[indexA].Position;
                }
                else
                {
                    result = ExtSpline.Bezier3(pos - indexA,
                                               Waypoints[indexA].Position, m_ControlPoints1[indexA].Position,
                                               m_ControlPoints2[indexA].Position, Waypoints[indexB].Position);
                }
            }
            return(transform.TransformPoint(result));
        }