Пример #1
0
        public void UpdateGraphLine()
        {
            SetGraphVisible(true);

            PVector2 dGraph01Size = DGraph01Size;
            PRect    dGraphRect   = DGraphRect;

            //Update Inside lines
            for (int graphLineI = 0; graphLineI < graphLines.Length; ++graphLineI)
            {
                float motionValue     = GetLineMotionValue(graphLineI);
                float nextMotionValue = GetLineMotionValue(graphLineI + 1);

                Line line = graphLines[graphLineI];
                line.X1 = dGraphRect.xMin + graphLineI * dGraph01Size.x / GraphResolution;
                line.X2 = dGraphRect.xMin + (graphLineI + 1) * dGraph01Size.x / GraphResolution;
                line.Y1 = dGraphRect.yMax - motionValue * dGraph01Size.y;
                line.Y2 = dGraphRect.yMax - nextMotionValue * dGraph01Size.y;

                float GetLineMotionValue(int index)
                {
                    float linearValue = (float)index / graphLines.Length;

                    return(EditingMotionData.GetMotionValue(linearValue));
                }
            }

            //Update Outside lines
            float outsideLeftY  = NormalToDisplayY(EditingMotionData.GetMotionValue(0f));
            float outsideRightY = NormalToDisplayY(EditingMotionData.GetMotionValue(1f));

            outsideLines[0].SetLinePosition(new Vector2(Mathf.Min(dGraphRect.xMin, 0f), outsideLeftY), new Vector2(dGraphRect.xMin, outsideLeftY));
            outsideLines[1].SetLinePosition(new Vector2(dGraphRect.xMax, outsideRightY), new Vector2(Mathf.Max(dGraphRect.xMax, (float)GraphContext.ActualWidth), outsideRightY));
        }
Пример #2
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);
        }
Пример #3
0
 private float GetMotionTime(float linearTime)
 {
     return(OnEditing ? EditingMotionData.Cast <MotionItem>().GetMotionValue(linearTime) : 0f);
 }
Пример #4
0
        private void UpdateCursorInteraction()
        {
            //코드 꼴이 말이 아니다. 으아아악
            //언젠가 리팩토링 할 것.

            const float InteractionThreshold = 0.02f;

            if (Mouse.LeftButton != MouseButtonState.Pressed)
            {
                clickEventExecuted = false;
            }

            if (!OnEditing)
            {
                return;
            }

            bool            cursorChanged = false;
            MotionPointView cursorOveredPoint;
            int             cursorOverPointIndex = -1;

            FindCursorOverPoint(out cursorOveredPoint, out cursorOverPointIndex);

            if (Keyboard.IsKeyDown(Key.LeftAlt))
            {
                //Remove mode
                if (cursorOveredPoint != null && cursorOverPointIndex > 0 && cursorOverPointIndex < pointViewList.Count - 1)
                {
                    SetCursor(CursorStorage.cursor_remove);
                    cursorChanged = true;

                    if (!clickEventExecuted && Mouse.LeftButton == MouseButtonState.Pressed)
                    {
                        clickEventExecuted = true;

                        EditingMotionData.RemovePoint(cursorOveredPoint.Data);
                    }
                }
            }
            else if (Keyboard.IsKeyDown(Key.LeftCtrl) && cursorOveredPoint == null)
            {
                Vector2 cursorPos = DisplayToNormal((Vector2)Mouse.GetPosition(PointCanvas));
                if (!Keyboard.IsKeyDown(Key.Space) && cursorPos.x > 0f && cursorPos.x < 1f)
                {
                    //Add mode

                    int index = EditingMotionData.GetRightPointIndex(cursorPos.x);
                    if (index > 0)
                    {
                        SetCursor(CursorStorage.cursor_add);
                        SetSmartLineForX(cursorPos.x);
                        cursorChanged = true;

                        if (!clickEventExecuted && Mouse.LeftButton == MouseButtonState.Pressed)
                        {
                            clickEventExecuted = true;

                            CreatePointWithInterpolation(index, cursorPos);
                        }
                    }
                }
                else
                {
                    HideSmartLineForX();
                }
            }
            if ((cursorOveredPoint != null || !Keyboard.IsKeyDown(Key.LeftCtrl)) && !IsElementDragging)
            {
                HideSmartLineForX();
            }
            if (!cursorChanged)
            {
                SetCursor(CursorStorage.cursor_default);
            }
        }