Point2D Quadratic(float t, KeyFrame first, KeyFrame second, KeyFrame third) { float dt0 = (first.t - second.t) * (first.t - third.t); float dt1 = (second.t - first.t) * (second.t - third.t); float dt2 = (third.t - first.t) * (third.t - second.t); Point2D p0 = first.point * ((t - second.t) * (t - third.t)) / dt0; Point2D p1 = second.point * ((t - first.t) * (t - third.t)) / dt1; Point2D p2 = third.point * ((t - first.t) * (t - second.t)) / dt2; return p0 + p1 + p2; }
public override KeyFrame Calculate(float timestamp, List<KeyFrame> source) { if (source.Count == 0 || source.Count < 2) return new KeyFrame(); KeyFrame result = source[0]; int neighbor = FindNearKeyFrame(timestamp, source); if (neighbor >= 0) { KeyFrame first = (neighbor == source.Count - 1) ? source[neighbor - 1] : source[neighbor]; KeyFrame second = (neighbor == source.Count - 1) ? source[neighbor] : source[neighbor + 1]; Point2D interp_point = Lerp(timestamp, first, second); result = new KeyFrame(timestamp, interp_point); } return result; }
public override KeyFrame Calculate(float timestamp, List<KeyFrame> source) { if (source.Count == 0 || source.Count < 3) return new KeyFrame(); KeyFrame result = source[0]; int neighbor = FindNearKeyFrame(timestamp, source); if (neighbor >= 0 && neighbor < (source.Count - 1)) { KeyFrame first = new KeyFrame(); KeyFrame second = new KeyFrame(); KeyFrame third = new KeyFrame(); if (neighbor == 0) { first = source[0]; second = source[1]; third = source[2]; } else if (neighbor == source.Count - 1) { first = source[source.Count - 3]; second = source[source.Count - 2]; third = source[source.Count - 1]; } else if (neighbor > 0) { first = source[neighbor - 1]; second = source[neighbor]; third = source[neighbor + 1]; } Point2D interp_point = Quadratic(timestamp, first, second, third); result = new KeyFrame(timestamp, interp_point); } return result; }
public override KeyFrame Calculate(float timestamp, List <KeyFrame> source) { if (source.Count == 0 || source.Count < 2) { return(new KeyFrame()); } KeyFrame result = source[0]; int neighbor = FindNearKeyFrame(timestamp, source); if (neighbor >= 0) { KeyFrame first = (neighbor == source.Count - 1) ? source[neighbor - 1] : source[neighbor]; KeyFrame second = (neighbor == source.Count - 1) ? source[neighbor] : source[neighbor + 1]; Point2D interp_point = Lerp(timestamp, first, second); result = new KeyFrame(timestamp, interp_point); } return(result); }
public override KeyFrame Calculate(float timestamp, List<KeyFrame> source) { if (source.Count == 0 || source.Count < 4) return new KeyFrame(); KeyFrame result = source[0]; int neighbor = FindNearKeyFrame(timestamp, source); if (neighbor >= 0 && neighbor < (source.Count - 1)) { Point2D P0 = (neighbor == 0) ? source[neighbor].point : source[neighbor - 1].point; Point2D P1 = source[neighbor].point; Point2D P2 = source[neighbor + 1].point; Point2D P3 = (neighbor + 2 > source.Count - 1) ? source[neighbor + 1].point : source[neighbor + 2].point; float dt = (timestamp - source[neighbor].t) / (source[neighbor + 1].t - source[neighbor].t); Point2D interp_point = HermiteInterpolate(dt, P0, P1, P2, P3); result = new KeyFrame(timestamp, interp_point); } return result; }
public virtual KeyFrame Calculate(float timestamp, List <KeyFrame> source) { KeyFrame result = new KeyFrame(); return(result); }
public virtual KeyFrame Calculate(float timestamp, List<KeyFrame> source) { KeyFrame result = new KeyFrame(); return result; }
Point2D Lerp(float t, KeyFrame first, KeyFrame second) { float alpha = (t - first.t) / (second.t - first.t); return first.point + (second.point - first.point) * alpha; }
Point2D Lerp(float t, KeyFrame first, KeyFrame second) { float alpha = (t - first.t) / (second.t - first.t); return(first.point + (second.point - first.point) * alpha); }