Пример #1
0
        public float?FindMagnetForY(float y, bool findMainPoints, MotionPointView exclusivePoint = null)
        {
            List <float> magnetList = new List <float>()
            {
                0f,
                1f,
            };

            if (findMainPoints)
            {
                foreach (MotionPointView point in pointViewList)
                {
                    if (point != exclusivePoint)
                    {
                        magnetList.Add(point.Data.MainPoint.y);
                    }
                }
            }
            foreach (float magnet in magnetList)
            {
                if (Mathf.Abs(magnet - y) < NearDistance)
                {
                    //Found magnet
                    SetSmartLineForY(magnet);
                    return(magnet);
                }
            }
            HideSmartLineForY();
            return(null);
        }
Пример #2
0
        private void MotionItem_PointInserted(int index, MotionPoint point)
        {
            MotionPointView view = CreatePointViewFromData(point);

            //Add to collection
            pointViewList.Insert(index, view);
            dataToViewDict.Add(point, view);

            //Update UI
            UpdateGraphLine();

            EditorContext.MarkUnsaved();
        }
Пример #3
0
        private void FindCursorOverPoint(out MotionPointView cursorOverPoint, out int cursorOverIndex)
        {
            cursorOverPoint = null;
            cursorOverIndex = -1;
            for (int handleI = 0; handleI < pointViewList.Count; ++handleI)
            {
                MotionPointView pointView = pointViewList[handleI];

                if (pointView.MainHandleView.IsMouseOver)
                {
                    cursorOverIndex = handleI;
                    cursorOverPoint = pointView;
                    break;
                }
            }
        }
Пример #4
0
        //PointViews
        private MotionPointView CreatePointViewFromData(MotionPoint motionPoint)
        {
            MotionPointView view = new MotionPointView(EditorContext, motionPoint);

            PointCanvas.Children.Add(view);

            //MainPoint
            view.Data_MainPointChanged(motionPoint.MainPoint);

            //SubPoints
            for (int i = 0; i < motionPoint.SubPoints.Length; ++i)
            {
                view.Data_SubPointChanged(i, motionPoint.SubPoints[i]);
            }

            return(view);
        }
Пример #5
0
        private void MotionItem_PointRemoved(MotionPoint point)
        {
            MotionPointView view = dataToViewDict[point];

            RemovePointView(view);

            //Remove from collection
            pointViewList.Remove(view);
            dataToViewDict.Remove(point);

            view.Dispose();

            //Update UI
            UpdateGraphLine();

            EditorContext.MarkUnsaved();
        }
Пример #6
0
        //Points
        private void CreatePointWithInterpolation(int index, Vector2 position)
        {
            //Collect prev, next points
            MotionPointView prevPointView  = pointViewList[index - 1];
            MotionPointView nextPointView  = pointViewList[index];
            float           prevNextDeltaX = nextPointView.Data.MainPoint.x - prevPointView.Data.MainPoint.x;
            float           prevDeltaX     = position.x - prevPointView.Data.MainPoint.x;
            float           nextDeltaX     = nextPointView.Data.MainPoint.x - position.x;
            float           weight         = (position.x - prevPointView.Data.MainPoint.x) / prevNextDeltaX;

            MotionPoint point = new MotionPoint();

            //Calculate data
            float   mainPointX = position.x;
            float   subPoint0X = position.x - prevDeltaX * (1f - weight) * 0.5f;
            float   subPoint1X = position.x + nextDeltaX * weight * 0.5f;
            Vector2 subPoint0  = new Vector2(subPoint0X, EditingMotionData.GetMotionValue(subPoint0X)) - point.MainPoint.ToVector2();
            Vector2 subPoint1  = new Vector2(subPoint1X, EditingMotionData.GetMotionValue(subPoint1X)) - point.MainPoint.ToVector2();

            Vector2 subPoint0Delta = subPoint0 - position;
            Vector2 subPoint1Delta = subPoint1 - position;

            //subPoint의 각도로부터 90도씩 꺾인 각도를 구한다
            float subPoint0Angle = Mathf.Atan2(subPoint0Delta.y, subPoint0Delta.x) * Mathf.Rad2Deg + 90f;
            float subPoint1Angle = Mathf.Atan2(subPoint1Delta.y, subPoint1Delta.x) * Mathf.Rad2Deg - 90f;

            //그리고 둘이 섞었다가 다시 분리한다
            float averAngle = (subPoint0Angle + subPoint1Angle) * 0.5f;

            subPoint0Angle = (averAngle - 90f) * Mathf.Deg2Rad;
            subPoint1Angle = (averAngle + 90f) * Mathf.Deg2Rad;

            subPoint0 = new Vector2(Mathf.Cos(subPoint0Angle), Mathf.Sin(subPoint0Angle)) * subPoint0Delta.magnitude;
            subPoint1 = new Vector2(Mathf.Cos(subPoint1Angle), Mathf.Sin(subPoint1Angle)) * subPoint1Delta.magnitude;

            //Apply
            point.SetSubPoint(0, subPoint0.ToPVector2());
            point.SetSubPoint(1, subPoint1.ToPVector2());
            point.SetMainPoint(new PVector2(mainPointX, EditingMotionData.GetMotionValue(mainPointX)));
            prevPointView.Data.SetSubPoint(1, prevPointView.Data.SubPoints[1] * (prevDeltaX / prevNextDeltaX));
            nextPointView.Data.SetSubPoint(0, nextPointView.Data.SubPoints[0] * (nextDeltaX / prevNextDeltaX));

            EditingMotionData.InsertPoint(index, point);
        }
Пример #7
0
 private void RemovePointView(MotionPointView motionPointView)
 {
     PointCanvas.Children.Remove(motionPointView);
 }