/// <summary> /// Constructs an interpolated path based on the Key Frames. /// Options are Linear or Cubic interpolation /// </summary> private void BuildPath() { this.currentPathPoints.Clear(); // a point on a cubic spline is affected by every other point // so we need to build the cubic equations for each control point // by looking at the entire curve. This is what calculateCubicSpline does var looks = new Vector3[this.keyFrames.Count]; var positions = new Vector3[this.keyFrames.Count]; var ups = new Vector3[this.keyFrames.Count]; for (int i = 0; i < this.keyFrames.Count; i++) { looks[i] = this.keyFrames[i].LookAt; positions[i] = this.keyFrames[i].Position; ups[i] = this.keyFrames[i].Up; } int count = this.keyFrames.Count - 1; Spline[] posCubic; Spline.CalculateCubicSpline(ref count, ref positions, out posCubic); Spline[] lookCubic; Spline.CalculateCubicSpline(ref count, ref looks, out lookCubic); Spline[] upCubic; Spline.CalculateCubicSpline(ref count, ref ups, out upCubic); for (int i = 0; i < this.keyFrames.Count - 1; i++) { for (int j = 0; j < this.pathSteps; j++) { float k = j / (float)(this.pathSteps - 1); Vector3 center = posCubic[i].GetPointOnSpline(k); Vector3 up = upCubic[i].GetPointOnSpline(k); Vector3 look = lookCubic[i].GetPointOnSpline(k); var cam = new CameraPoint(ref center, ref look, ref up); this.currentPathPoints.Add(cam); } } }
public static Spline[] CalculateCubicSpline(int n, Vector3[] v) { Spline[] c = (Spline[])null; Spline.CalculateCubicSpline(ref n, ref v, out c); return(c); }