Ejemplo n.º 1
0
        private void Validate()
        {
            Debug.Assert(!_isValid);

            if (IsOffsetCumulative ||
                IsAngleCumulative)
            {
                Point        startPoint;
                Point        startTangent;
                Point        endPoint;
                Point        endTangent;
                PathGeometry pathGeometry = PathGeometry;

                // Get values at the beginning of the path.
                pathGeometry.GetPointAtFractionLength(0.0, out startPoint, out startTangent);

                // Get values at the end of the path.
                pathGeometry.GetPointAtFractionLength(1.0, out endPoint, out endTangent);

                // Calculate difference.
                _accumulatingAngle = DoubleAnimationUsingPath.CalculateAngleFromTangentVector(endTangent.X, endTangent.Y)
                                     - DoubleAnimationUsingPath.CalculateAngleFromTangentVector(startTangent.X, startTangent.Y);

                _accumulatingOffset.X = endPoint.X - startPoint.X;
                _accumulatingOffset.Y = endPoint.Y - startPoint.Y;
            }

            _isValid = true;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Calculates the value this animation believes should be the current value for the property.
        /// </summary>
        /// <param name="defaultOriginValue">
        /// This value is the suggested origin value provided to the animation
        /// to be used if the animation does not have its own concept of a
        /// start value. If this animation is the first in a composition chain
        /// this value will be the snapshot value if one is available or the
        /// base property value if it is not; otherise this value will be the
        /// value returned by the previous animation in the chain with an
        /// animationClock that is not Stopped.
        /// </param>
        /// <param name="defaultDestinationValue">
        /// This value is the suggested destination value provided to the animation
        /// to be used if the animation does not have its own concept of an
        /// end value. This value will be the base value if the animation is
        /// in the first composition layer of animations on a property;
        /// otherwise this value will be the output value from the previous
        /// composition layer of animations for the property.
        /// </param>
        /// <param name="animationClock">
        /// This is the animationClock which can generate the CurrentTime or
        /// CurrentProgress value to be used by the animation to generate its
        /// output value.
        /// </param>
        /// <returns>
        /// The value this animation believes should be the current value for the property.
        /// </returns>
        protected override Matrix GetCurrentValueCore(Matrix defaultOriginValue, Matrix defaultDestinationValue, AnimationClock animationClock)
        {
            Debug.Assert(animationClock.CurrentState != ClockState.Stopped);

            PathGeometry pathGeometry = PathGeometry;

            if (pathGeometry == null)
            {
                return(defaultDestinationValue);
            }

            if (!_isValid)
            {
                Validate();
            }

            Point pathPoint;
            Point pathTangent;

            pathGeometry.GetPointAtFractionLength(animationClock.CurrentProgress.Value, out pathPoint, out pathTangent);

            double angle = 0.0;

            if (DoesRotateWithTangent)
            {
                angle = DoubleAnimationUsingPath.CalculateAngleFromTangentVector(pathTangent.X, pathTangent.Y);
            }

            Matrix matrix = new Matrix();

            double currentRepeat = (double)(animationClock.CurrentIteration - 1);

            if (currentRepeat > 0)
            {
                if (IsOffsetCumulative)
                {
                    pathPoint = pathPoint + (_accumulatingOffset * currentRepeat);
                }

                if (DoesRotateWithTangent &&
                    IsAngleCumulative)
                {
                    angle = angle + (_accumulatingAngle * currentRepeat);
                }
            }

            matrix.Rotate(angle);
            matrix.Translate(pathPoint.X, pathPoint.Y);

            if (IsAdditive)
            {
                return(Matrix.Multiply(matrix, defaultOriginValue));
            }
            else
            {
                return(matrix);
            }
        }