示例#1
0
        protected void GenerateCurve()
        {
            //Make sure we have all the info we need
            if (Whisker == null || Whisker.WhiskerPoints == null)
            {
                return;
            }

            if (Whisker.WhiskerPoints.Length == 0)
            {
                return;
            }

            if (Whisker.Parent.OriginalWidth == 0 || Whisker.Parent.OriginalHeight == 0)
            {
                return;
            }

            //Calculate Control Points
            IWhiskerPoint firstPoint = Whisker.WhiskerPoints[0].Clone();

            ControlPoints    = new IWhiskerPoint[Whisker.WhiskerPoints.Length];
            ControlPoints[0] = firstPoint;

            double videoWidth  = Whisker.Parent.OriginalWidth;
            double videoHeight = Whisker.Parent.OriginalHeight;

            if (ControlPoints.Length == 2)
            {
                IWhiskerPoint lWhiskerPoint1 = Whisker.WhiskerPoints[1].Clone();
                ControlPoints[1] = lWhiskerPoint1;
                TargetPoint      = GetTValuePointForLinear();
            }

            if (ControlPoints.Length == 3)
            {
                IWhiskerPoint qWhiskerPoint1 = Whisker.WhiskerPoints[1].Clone();
                IWhiskerPoint qWhiskerPoint2 = Whisker.WhiskerPoints[2].Clone();

                Point[] points = new Point[3];
                points[0] = new Point(firstPoint.XRatio * videoWidth, firstPoint.YRatio * videoHeight);
                points[1] = new Point(qWhiskerPoint1.XRatio * videoWidth, qWhiskerPoint1.YRatio * videoHeight);
                points[2] = new Point(qWhiskerPoint2.XRatio * videoWidth, qWhiskerPoint2.YRatio * videoHeight);

                Point point1;
                DrawingUtility.GetControlPointsForQuadraticBezier(points, out point1);

                qWhiskerPoint1.XRatio = point1.X / videoWidth;
                qWhiskerPoint1.YRatio = point1.Y / videoHeight;

                ControlPoints[1] = qWhiskerPoint1;
                ControlPoints[2] = qWhiskerPoint2;
                TargetPoint      = GetTValuePointForQuadratic();
            }

            if (ControlPoints.Length == 4)
            {
                IWhiskerPoint cWhiskerPoint1 = Whisker.WhiskerPoints[1].Clone();
                IWhiskerPoint cWhiskerPoint2 = Whisker.WhiskerPoints[2].Clone();
                IWhiskerPoint cWhiskerPoint3 = Whisker.WhiskerPoints[3].Clone();

                Point[] points = new Point[4];
                points[0] = new Point(firstPoint.XRatio * videoWidth, firstPoint.YRatio * videoHeight);
                points[1] = new Point(cWhiskerPoint1.XRatio * videoWidth, cWhiskerPoint1.YRatio * videoHeight);
                points[2] = new Point(cWhiskerPoint2.XRatio * videoWidth, cWhiskerPoint2.YRatio * videoHeight);
                points[3] = new Point(cWhiskerPoint3.XRatio * videoWidth, cWhiskerPoint3.YRatio * videoHeight);

                Point point1, point2;
                DrawingUtility.GetControlPointsForCubicBezier(points, out point1, out point2);

                cWhiskerPoint1.XRatio = point1.X / videoWidth;
                cWhiskerPoint1.YRatio = point1.Y / videoHeight;
                cWhiskerPoint2.XRatio = point2.X / videoWidth;
                cWhiskerPoint2.YRatio = point2.Y / videoHeight;

                ControlPoints[1] = cWhiskerPoint1;
                ControlPoints[2] = cWhiskerPoint2;
                ControlPoints[3] = cWhiskerPoint3;
                TargetPoint      = GetTValuePointForCubic();
            }
        }