Pathfinding.SimpleSmoothModifier.GetPointOnCubic C# (CSharp) Method

GetPointOnCubic() public static method

public static GetPointOnCubic ( Vector3 a, Vector3 b, Vector3 tan1, Vector3 tan2, float t ) : Vector3
a UnityEngine.Vector3
b UnityEngine.Vector3
tan1 UnityEngine.Vector3
tan2 UnityEngine.Vector3
t float
return UnityEngine.Vector3
		public static Vector3 GetPointOnCubic (Vector3 a, Vector3 b, Vector3 tan1, Vector3 tan2, float t) {
			float t2 = t*t, t3 = t2*t;
			
			//float s = (float)t / (float)steps;  // scale s to go from 0 to 1
			float h1 =  2*t3 - 3*t2 + 1;       	  // calculate basis function 1
			float h2 = -2*t3 + 3*t2;              // calculate basis function 2
			float h3 =   t3 -  2*t2 + t;       	  // calculate basis function 3
			float h4 =   t3 -  t2;            	  // calculate basis function 4
			return		h1*a +                   	 // multiply and sum all funtions
						h2*b +                   	 // together to build the interpolated
						h3*tan1 +                	 // point along the curve.
						h4*tan2;
			
			//return //(b*(3*t*t-2*t*t*t)+c*(t-2*t*t+t*t*t)+d*(-t*t+t*t*t)+a*(1-3*t*t+2*t*t*t));
				
			//float mt = 1-t;
			//return start*mt*mt*mt + (start+startVel)*3*t*mt*mt + 3*mt*t*t*(end-endVel) + t*t*t*end;
			//return start*t*t*t + (start+startVel)*t*t + (end-endVel)*t + end;
			//return start*t*t*t + start*t*t + startVel*t*t + end*t + endVel*t + end;
		}
		

Usage Example

        public List <Vector3> CurvedNonuniform(List <Vector3> path)
        {
            if (this.maxSegmentLength <= 0f)
            {
                Debug.LogWarning("Max Segment Length is <= 0 which would cause DivByZero-exception or other nasty errors (avoid this)");
                return(path);
            }
            int num = 0;

            for (int i = 0; i < path.Count - 1; i++)
            {
                float magnitude = (path[i] - path[i + 1]).magnitude;
                for (float num2 = 0f; num2 <= magnitude; num2 += this.maxSegmentLength)
                {
                    num++;
                }
            }
            List <Vector3> list = ListPool <Vector3> .Claim(num);

            Vector3 vector = (path[1] - path[0]).normalized;

            for (int j = 0; j < path.Count - 1; j++)
            {
                float   magnitude2 = (path[j] - path[j + 1]).magnitude;
                Vector3 a          = vector;
                Vector3 vector2    = (j >= path.Count - 2) ? (path[j + 1] - path[j]).normalized : ((path[j + 2] - path[j + 1]).normalized - (path[j] - path[j + 1]).normalized).normalized;
                Vector3 tan        = a * magnitude2 * this.factor;
                Vector3 tan2       = vector2 * magnitude2 * this.factor;
                Vector3 a2         = path[j];
                Vector3 b          = path[j + 1];
                float   num3       = 1f / magnitude2;
                for (float num4 = 0f; num4 <= magnitude2; num4 += this.maxSegmentLength)
                {
                    float t = num4 * num3;
                    list.Add(SimpleSmoothModifier.GetPointOnCubic(a2, b, tan, tan2, t));
                }
                vector = vector2;
            }
            list[list.Count - 1] = path[path.Count - 1];
            return(list);
        }