コード例 #1
0
        public static bool Animate(
            Point currentValue, Vector currentVelocity, Vector force,
            double dampening, double terminalVelocity, double minValueDelta, double minVelocityDelta,
            out Point newValue, out Vector newVelocity)
        {
            Debug.Assert(currentValue.IsRational());
            Debug.Assert(currentVelocity.IsRational());

            Debug.Assert(dampening.IsRational());
            Debug.Assert(dampening > 0 && dampening < 1);

            Debug.Assert(terminalVelocity > 0);

            Debug.Assert(minValueDelta > 0);
            Debug.Assert(minVelocityDelta > 0);

            if (force.Length > minValueDelta || currentVelocity.Length > minVelocityDelta)
            {
                newVelocity = currentVelocity * (1 - dampening);
                newVelocity += force;
                newVelocity *= (currentVelocity.Length > terminalVelocity) ? terminalVelocity / currentVelocity.Length : 1;

                newValue = currentValue + newVelocity;

                return true;
            }
            else
            {
                newValue = currentValue;
                newVelocity = new Vector();
                return false;
            }

        }
コード例 #2
0
        public Line(Point p1, Point p2)
        {
            Util.RequireArgument(p1.IsRational(), "p1");
            Util.RequireArgument(p2.IsRational(), "p2");

            m_p1 = p1;
            m_p2 = p2;
        }
コード例 #3
0
        /// <param name="angleRadians">The angle, in radians, from 3-o'clock going counter-clockwise.</param>
        public static void DrawLine(this DrawingContext drawingContext, Pen pen, Point startPoint, double angleRadians, double length)
        {
            Util.RequireNotNull(drawingContext, "drawingContext");
            Util.RequireArgument(startPoint.IsRational(), "startPoint");
            Util.RequireNotNull(pen, "Pen");

            drawingContext.DrawLine(pen, startPoint, startPoint + GetVectorFromAngle(angleRadians, length));
        }
コード例 #4
0
ファイル: WpfUtil.cs プロジェクト: liuxr/wpfumprototype
        public Line(Point p1, Point p2)
        {
            Util.RequireArgument(p1.IsRational(), "p1");
            Util.RequireArgument(p2.IsRational(), "p2");

            m_p1 = p1;
            m_p2 = p2;
        }
コード例 #5
0
        public static double AngleRad(Point point1, Point point2, Point point3)
        {
            Debug.Assert(point1.IsRational());
            Debug.Assert(point2.IsRational());
            Debug.Assert(point3.IsRational());

            double rad = AngleRad(point2 - point1, point2 - point3);

            double rad2 = AngleRad(point2 - point1, (point2 - point3).RightAngle());

            if (rad2 < (Math.PI / 2))
            {
                return rad;
            }
            else
            {
                return (Math.PI * 2) - rad;
            }
        }
コード例 #6
0
        public static bool Animate(
            Point currentValue, Vector currentVelocity, Point targetValue,
            double attractionFator, double dampening,
            double terminalVelocity, double minValueDelta, double minVelocityDelta,
            out Point newValue, out Vector newVelocity)
        {
            Debug.Assert(currentValue.IsRational());
            Debug.Assert(currentVelocity.IsRational());
            Debug.Assert(targetValue.IsRational());

            Debug.Assert(dampening.IsRational());
            Debug.Assert(dampening > 0 && dampening < 1);

            Debug.Assert(attractionFator.IsRational());
            Debug.Assert(attractionFator > 0);

            Debug.Assert(terminalVelocity > 0);

            Debug.Assert(minValueDelta > 0);
            Debug.Assert(minVelocityDelta > 0);

            Vector diff = targetValue - currentValue;

            if (diff.Length > minValueDelta || currentVelocity.Length > minVelocityDelta)
            {
                newVelocity = currentVelocity * (1 - dampening);
                newVelocity += diff * attractionFator;
                newVelocity *= (currentVelocity.Length > terminalVelocity) ? terminalVelocity / currentVelocity.Length : 1;

                newValue = currentValue + newVelocity;

                return true;
            }
            else
            {
                newValue = targetValue;
                newVelocity = new Vector();
                return false;
            }
        }
コード例 #7
0
ファイル: WpfUtil.cs プロジェクト: liuxr/wpfumprototype
        /// <param name="angleRadians">The angle, in radians, from 3-o'clock going counter-clockwise.</param>
        public static void DrawLine(this DrawingContext drawingContext, Pen pen, Point startPoint, double angleRadians, double length)
        {
            Util.RequireNotNull(drawingContext, "drawingContext");
            Util.RequireArgument(startPoint.IsRational(), "startPoint");
            Util.RequireNotNull(pen, "Pen");

            drawingContext.DrawLine(pen, startPoint, startPoint + GetVectorFromAngle(angleRadians, length));
        }
コード例 #8
0
ファイル: WpfUtil.cs プロジェクト: liuxr/wpfumprototype
        public static bool Animate(
            Point currentValue, Vector currentVelocity, Vector force,
            double dampening, double terminalVelocity, double minValueDelta, double minVelocityDelta,
            out Point newValue, out Vector newVelocity)
        {
            Debug.Assert(currentValue.IsRational());
            Debug.Assert(currentVelocity.IsRational());

            Debug.Assert(dampening.IsRational());
            Debug.Assert(dampening > 0 && dampening < 1);

            Debug.Assert(terminalVelocity > 0);

            Debug.Assert(minValueDelta > 0);
            Debug.Assert(minVelocityDelta > 0);

            if (force.Length > minValueDelta || currentVelocity.Length > minVelocityDelta)
            {
                newVelocity = currentVelocity * (1 - dampening);
                newVelocity += force;
                newVelocity *= (currentVelocity.Length > terminalVelocity) ? terminalVelocity / currentVelocity.Length : 1;

                newValue = currentValue + newVelocity;

                return true;
            }
            else
            {
                newValue = currentValue;
                newVelocity = new Vector();
                return false;
            }
        }
コード例 #9
0
ファイル: WpfUtil.cs プロジェクト: liuxr/wpfumprototype
        public static bool Animate(
            Point currentValue, Vector currentVelocity, Point targetValue,
            double attractionFator, double dampening,
            double terminalVelocity, double minValueDelta, double minVelocityDelta,
            out Point newValue, out Vector newVelocity)
        {
            Debug.Assert(currentValue.IsRational());
            Debug.Assert(currentVelocity.IsRational());
            Debug.Assert(targetValue.IsRational());

            Debug.Assert(dampening.IsRational());
            Debug.Assert(dampening > 0 && dampening < 1);

            Debug.Assert(attractionFator.IsRational());
            Debug.Assert(attractionFator > 0);

            Debug.Assert(terminalVelocity > 0);

            Debug.Assert(minValueDelta > 0);
            Debug.Assert(minVelocityDelta > 0);

            Vector diff = targetValue - currentValue;

            if (diff.Length > minValueDelta || currentVelocity.Length > minVelocityDelta)
            {
                newVelocity = currentVelocity * (1 - dampening);
                newVelocity += diff * attractionFator;
                newVelocity *= (currentVelocity.Length > terminalVelocity) ? terminalVelocity / currentVelocity.Length : 1;

                newValue = currentValue + newVelocity;

                return true;
            }
            else
            {
                newValue = targetValue;
                newVelocity = new Vector();
                return false;
            }
        }
コード例 #10
0
ファイル: WpfUtil.cs プロジェクト: liuxr/wpfumprototype
        public static double AngleRad(Point point1, Point point2, Point point3)
        {
            Debug.Assert(point1.IsRational());
            Debug.Assert(point2.IsRational());
            Debug.Assert(point3.IsRational());

            double rad = AngleRad(point2 - point1, point2 - point3);

            double rad2 = AngleRad(point2 - point1, (point2 - point3).RightAngle());

            if (rad2 < (Math.PI / 2))
            {
                return rad;
            }
            else
            {
                return (Math.PI * 2) - rad;
            }
        }