Пример #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);
        }