Пример #1
0
        internal void AddSplinePoint()
        {
            Spline spline = EditorData.EditorLogic.CurrentSpline;

            if (spline == null)
            {
                MessageBox.Show("Select a spline to add points to");
            }
            else
            {
                SplinePoint newSplinePoint = new SplinePoint();
                if (spline.Count > 1)
                {
                    SplinePoint pointBefore = spline[spline.Count - 1];

                    newSplinePoint.Time = pointBefore.Time + 1;

                    if (spline.Count == 1)
                    {
                        newSplinePoint.Position    = pointBefore.Position;
                        newSplinePoint.Position.X += 30 / SpriteManager.Camera.PixelsPerUnitAt(newSplinePoint.Position.Z);
                    }
                    else
                    {
                        SplinePoint pointBeforePointBefore = spline[spline.Count - 2];

                        Vector3 difference = pointBefore.Position - pointBeforePointBefore.Position;

                        if (difference == Vector3.Zero)
                        {
                            newSplinePoint.Position    = pointBefore.Position;
                            newSplinePoint.Position.X += 30 / Camera.Main.PixelsPerUnitAt(0);
                        }
                        else
                        {
                            newSplinePoint.Position = pointBefore.Position + difference;
                        }
                    }
                }
                else
                {
                    newSplinePoint.Position.X = SpriteManager.Camera.X;
                    newSplinePoint.Position.Y = SpriteManager.Camera.Y;

                    if (spline.Count > 0)
                    {
                        newSplinePoint.Time = spline[0].Time + 1;

                        newSplinePoint.Position    = spline[0].Position;
                        newSplinePoint.Position.X += 30 / Camera.Main.PixelsPerUnitAt(0);
                    }
                }
                spline.Add(newSplinePoint);
                spline.CalculateVelocities();
                spline.CalculateAccelerations();
                spline.CalculateDistanceTimeRelationships(.1f);

                GuiData.PropertyGrid.Refresh();
                GuiData.SplineListDisplay.UpdateToList();
            }
            //if (AfterNewPointAdded != null)
            //{
            //    AfterNewPointAdded(this);
            //}
        }