/// <summary> /// Makes sure every control point follows the rules of the knot they belong to, or re-auto generates the control /// points. /// </summary> public void RecalculateControlPoints() { _path = null; if (AutoControlPoints) { IEnumerable <Vector3> points = _knots.Select(knot => knot.Position); var newKnots = CubicBezierKnotUtils.GeneratePathKnots(Looped, points, Tension, Bias, Continuity, true); // Copy up positions over to knew knots. for (int i = 0; i < _knots.Count; ++i) { newKnots[i].Up = _knots[i].Up; } _knots = newKnots; } else { for (int i = 0; i < _knots.Count; ++i) { _knots[i].RecalculateControlPoint(true, true); } } }
/// <summary> /// Creates an automatic bezier path between the given list of points. If tension, bias and continuity are all 0, /// This path will be a catmull-rom spline. /// </summary> /// <param name="tension"> /// A tension of 0 indicates smooth corners. A tension of 1 indicates sharp corners. Values larger than /// this range can cause the curves to overshoot. Values smaller than 0 will cause the curves to fold into /// themselves. /// </param> /// <summary> /// Bias affects how automatic control points should be generated. For a given knot, a positive bias means there /// will be a strong bend at the start of the outgoing segment, and a negative bias means there will be a strong /// bend at the end of the incomming segment. The default bias of 0 gives a neutral weighting. /// </summary> /// <summary> /// Continuity affects how automatic control points should be generated. If this value is 0, control points will /// be C1 continious, (no instant changes in velocity, unless tension is >= 1). This can be though to change how /// sharp the shape is. /// </summary> /// <param name="looped"> /// Whether the path should be looped or not. /// </param> /// <param name="overshootMode"> /// How path overshooting should be handled. /// </param> /// <param name="points">The points the bezier should map through.</param> public AutoBezierPath(float tension, float bias, float continuity, bool looped, PathOvershootMode overshootMode, IEnumerable <Vector3> points) { List <CubicBezierKnot> knots = CubicBezierKnotUtils.GeneratePathKnots(looped, points, tension, bias, continuity); var paths = new List <IPath>(); int numberOfPoints = points.Count(); int count = looped ? numberOfPoints : numberOfPoints - 1; for (int i = 0; i < count; ++i) { int index = i; int nextIndex = (i + 1) % numberOfPoints; CubicBezierKnot firstKnot = knots[index]; CubicBezierKnot nextKnot = knots[nextIndex]; var path = new NormalizedBezierPath(firstKnot.Position, firstKnot.OutControlPoint, nextKnot.InControlPoint, nextKnot.Position); paths.Add(path); } _path = new ChainedPath(overshootMode, paths); }