public List <Point> KeyFramesToCurve(List <Point> keyframes) { int modifier = 1; for (int i = 0; i < _smoothness.Count; i++) { List <Point> insertPoints = new List <Point>(); switch (_smoothness[i]) { case 0: break; case 1: insertPoints.Add(LerpMath.Lerp(keyframes[i + modifier - 1], keyframes[i + modifier], 0.5)); keyframes.InsertRange(i + modifier, insertPoints); modifier += 1; break; case 2: insertPoints.Add(LerpMath.Lerp(keyframes[i + modifier - 1], keyframes[i + modifier], 0.30)); insertPoints.Add(LerpMath.Lerp(keyframes[i + modifier - 1], keyframes[i + modifier], 0.70)); keyframes.InsertRange(i + modifier, insertPoints); modifier += 2; break; default: break; } } return(keyframes); }
//TODO: Figure out why insert Point is at a different Y value than curve is on public void InsertPoint(Point pos) { int position = 0; double delta = 0; Point insertPos = new Point(0, 0); for (int i = 0; i < Points.Count; i++) { if (Points[i].X > pos.X) { delta = pos.X / Points[i].X; insertPos = LerpMath.GetY(Points[i - 1], Points[i], pos.X); if ((pos.Y + 20) > insertPos.Y) { for (int j = 0; j < Original.Count; j++) { if (pos.X < Original[j].X) { position = j; break; } } break; } } } if (position == 0 || delta == 0 || insertPos.X == 0) { return; } List <Point> list = new List <Point>(Original); list.Insert(position, new Point(pos.X, insertPos.Y)); Original.Insert(position, new Point(pos.X, insertPos.Y)); _smoothness.Insert(position, 0); _points = KeyFramesToCurve(list); //TODO: return the keyframes to the parent object }