void SwitchSpline(Node.Connection from, Node.Connection to) { //See how much units we have travelled past that Node in the last frame float excessDistance = tracer.spline.CalculateLength(tracer.spline.GetPointPercent(from.pointIndex), tracer.UnclipPercent(tracer.result.percent)); //Set the spline to the tracer tracer.spline = to.spline; tracer.RebuildImmediate(); //Get the location of the junction point in percent along the new spline double startpercent = tracer.ClipPercent(to.spline.GetPointPercent(to.pointIndex)); if (Vector3.Dot(from.spline.Evaluate(from.pointIndex).direction, to.spline.Evaluate(to.pointIndex).direction) < 0f) { if (tracer.direction == Spline.Direction.Forward) { tracer.direction = Spline.Direction.Backward; } else { tracer.direction = Spline.Direction.Forward; } } //Position the tracer at the new location and travel excessDistance along the new spline tracer.SetPercent(tracer.Travel(startpercent, excessDistance, tracer.direction)); //Notify the wagon that we have entered a new spline segment wagon.EnterSplineSegment(from.pointIndex, tracer.spline, to.pointIndex, tracer.direction); wagon.UpdateOffset(); }
void ApplyTracer(SplineComputer spline, double percent, Spline.Direction direction) { bool rebuild = tracer.spline != spline; tracer.spline = spline; if (rebuild) { tracer.RebuildImmediate(); } tracer.direction = direction; tracer.SetPercent(tracer.ClipPercent(percent)); }