Beispiel #1
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);
        }
Beispiel #2
0
        public void DuplicateSelectedMotion()
        {
            if (!IsSelectedItemCopyable)
            {
                return;
            }

            MotionItemBase   latestNewItem = null;
            MotionFolderItem parentFolder  = SelectedItemParent;

            foreach (MotionItemBaseView refItem in MotionTreeView.SelectedItemSet)
            {
                if (refItem.Type == MotionItemType.Motion)
                {
                    MotionItem refMotionItem = (MotionItem)refItem.Data;
                    //Create motion
                    MotionItem newItem = EditingFile.CreateMotionEmpty(parentFolder);
                    latestNewItem = newItem;

                    //Copy points
                    foreach (MotionPoint refPoint in refMotionItem.pointList)
                    {
                        MotionPoint point = new MotionPoint();
                        newItem.AddPoint(point);

                        point.SetMainPoint(refPoint.MainPoint);
                        for (int i = 0; i < refPoint.SubPoints.Length; ++i)
                        {
                            point.SetSubPoint(i, refPoint.SubPoints[i]);
                        }
                    }

                    ((MotionItemView)DataToViewDict[newItem]).UpdatePreviewGraph();

                    //Set name
                    const string CopyPostfix = "_Copy";
                    string       name        = refItem.Data.Name;
                    for (; ;)
                    {
                        if (EditingFile.itemDict.ContainsKey(name))
                        {
                            name += CopyPostfix;
                        }
                        else
                        {
                            break;
                        }
                    }
                    newItem.SetName(name);
                }
            }
            if (latestNewItem != null)
            {
                MotionTreeView.SelectedItemSet.SetSelectedItem(DataToViewDict[latestNewItem]);
            }
        }