public static GetPoint ( Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3, float t ) : Vector3 | ||
p0 | Vector3 | |
p1 | Vector3 | |
p2 | Vector3 | |
p3 | Vector3 | |
t | float | |
Résultat | Vector3 |
public Vector3 GetPoint(float t) { int i; if (t >= 1f) { t = 1f; i = points.Length - 4; } else { t = Mathf.Clamp01(t) * CurveCount; i = (int)t; t -= i; // [0, 1] i *= 3; } return(transform.TransformPoint(CatmullRom.GetPoint(points[i], points[i + 1], points[i + 2], points[i + 3], t))); }
/// <summary> /// Get position on spline /// </summary> /// <param name="i"> /// A <see cref="System.Int32"/>. index point on spline /// </param> /// <param name="t"> /// A <see cref="System.Single"/>. position on spline segment /// </param> /// <returns> /// A <see cref="Vector3"/> /// </returns> public Vector3 GetValue(int i, float t) { if (i == 0 && t == 0) { return(values[0]); } if (i >= values.Count - 1) { return(values[values.Count - 1]); } Vector3 prevPos; Vector3 currPos = values[i]; Vector3 nextPos = values[i + 1]; Vector3 nextNextPos; if (i > 0) { prevPos = values[i - 1]; } else { //extrapolated prevPos = currPos - (nextPos - currPos); } if (i < values.Count - 2) { nextNextPos = values[i + 2]; } else { //extrapolated nextNextPos = nextPos + (nextPos - currPos); } return(CatmullRom.GetPoint(prevPos, currPos, nextPos, nextNextPos, t)); }