Ejemplo n.º 1
0
        /// <summary>Get the tangent of the curve at a point along the path.</summary>
        /// <param name="pos">Postion along the path.  Need not be normalized.</param>
        /// <returns>World-space direction of the path tangent.
        /// Length of the vector represents the tangent strength</returns>
        public override Vector3 EvaluateTangent(float pos)
        {
            Vector3 result = new Vector3();

            if (Waypoints.Length == 0)
            {
                result = transform.rotation * Vector3.forward;
            }
            else
            {
                int indexA, indexB;
                pos = GetBoundingIndices(pos, out indexA, out indexB);
                if (indexA == indexB)
                {
                    result = Waypoints[indexA].Tangent;
                }
                else
                {
                    Waypoint wpA = Waypoints[indexA];
                    Waypoint wpB = Waypoints[indexB];
                    result = ExtSpline.BezierTangent3(pos - indexA,
                                                      Waypoints[indexA].Position, wpA.Position + wpA.Tangent,
                                                      wpB.Position - wpB.Tangent, wpB.Position);
                }
            }
            return(transform.TransformDirection(result));
        }
Ejemplo n.º 2
0
        /// <summary>Get the tangent of the curve at a point along the path.</summary>
        /// <param name="pos">Position along the path.  Need not be normalized.</param>
        /// <returns>World-space direction of the path tangent.
        /// Length of the vector represents the tangent strength</returns>
        public override Vector3 EvaluateTangent(float pos)
        {
            Vector3 result = transform.rotation * Vector3.forward;

            if (Waypoints.Length > 1)
            {
                UpdateControlPoints();
                int indexA, indexB;
                pos = GetBoundingIndices(pos, out indexA, out indexB);
                if (!Looped && indexA == Waypoints.Length - 1)
                {
                    --indexA;
                }
                result = ExtSpline.BezierTangent3(pos - indexA,
                                                  Waypoints[indexA].Position, m_ControlPoints1[indexA].Position,
                                                  m_ControlPoints2[indexA].Position, Waypoints[indexB].Position);
            }
            return(transform.TransformDirection(result));
        }