public ChainedPath(PathOvershootMode overshootMode, IEnumerable <IPath> paths) { _segments = new List <Segment>(); _overshootMode = overshootMode; float length = 0f; int pathCount = 0; foreach (var path in paths) { pathCount++; length += path.Length; } if (pathCount == 0) { return; } _length = length; double t = 0.0; if (length <= 0.0) { Segment segment = new Segment(); segment.StartTime = 0; segment.EndTime = 1.0; segment.Path = paths.First(); _segments.Add(segment); return; } foreach (var path in paths) { Segment segment = new Segment(); segment.Path = path; segment.StartTime = t; t += path.Length / _length; segment.EndTime = t; _segments.Add(segment); } }
/// <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, params Vector3[] points) : this(tension, bias, continuity, looped, overshootMode, points as IEnumerable <Vector3>) { }
/// <summary> /// Creates an automatic bezier path between the given list of points. This path will be a catmull-rom spline. /// </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(bool looped, PathOvershootMode overshootMode, IEnumerable <Vector3> points) : this(0f, 0f, 0f, looped, overshootMode, points) { }
/// <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); }
/// <summary> /// Construct a new path, using child paths. /// </summary> /// <param name="wrappedOvershoot"> Determines over/undershooting behaviour. </param> /// <param name="paths">The child paths to chain together.</param> public ChainedPath(PathOvershootMode overshootMode, params IPath[] paths) : this(overshootMode, paths as IEnumerable <IPath>) { }