Example #1
0
        /// <summary>
        /// Helper used by the four Freezable clone methods to copy the resolved key times and
        /// key frames. The Get*AsFrozenCore methods are implemented the same as the Clone*Core
        /// methods; Get*AsFrozen at the top level will recursively Freeze so it's not done here.
        /// </summary>
        /// <param name="sourceAnimation"></param>
        /// <param name="isCurrentValueClone"></param>
        private void CopyCommon(Point3DAnimationUsingKeyFrames sourceAnimation, bool isCurrentValueClone)
        {
            _areKeyTimesValid = sourceAnimation._areKeyTimesValid;

            if (_areKeyTimesValid &&
                sourceAnimation._sortedResolvedKeyFrames != null)
            {
                // _sortedResolvedKeyFrames is an array of ResolvedKeyFrameEntry so the notion of CurrentValueClone doesn't apply
                _sortedResolvedKeyFrames = (ResolvedKeyFrameEntry[])sourceAnimation._sortedResolvedKeyFrames.Clone();
            }

            if (sourceAnimation._keyFrames != null)
            {
                if (isCurrentValueClone)
                {
                    _keyFrames = (Point3DKeyFrameCollection)sourceAnimation._keyFrames.CloneCurrentValue();
                }
                else
                {
                    _keyFrames = (Point3DKeyFrameCollection)sourceAnimation._keyFrames.Clone();
                }

                OnFreezablePropertyChanged(null, _keyFrames);
            }
        }
Example #2
0
        /// <summary>
        /// Implementation of <see cref="System.Windows.Freezable.GetCurrentValueAsFrozenCore(Freezable)">Freezable.GetCurrentValueAsFrozenCore</see>.
        /// </summary>
        protected override void GetCurrentValueAsFrozenCore(Freezable source)
        {
            Point3DAnimationUsingKeyFrames sourceAnimation = (Point3DAnimationUsingKeyFrames)source;

            base.GetCurrentValueAsFrozenCore(source);

            CopyCommon(sourceAnimation, /* isCurrentValueClone = */ true);
        }
Example #3
0
        /// <summary>
        /// Implementation of <see cref="System.Windows.Freezable.CloneCore(System.Windows.Freezable)">Freezable.CloneCore</see>.
        /// </summary>
        protected override void CloneCore(Freezable sourceFreezable)
        {
            Point3DAnimationUsingKeyFrames sourceAnimation = (Point3DAnimationUsingKeyFrames)sourceFreezable;

            base.CloneCore(sourceFreezable);

            CopyCommon(sourceAnimation, /* isCurrentValueClone = */ false);
        }
Example #4
0
        public static Point3DAnimationUsingKeyFrames GetSmoothAnimation(Point3D start, Point3D end, double duration)
        {
            Point3DAnimationUsingKeyFrames anim = new Point3DAnimationUsingKeyFrames();
            anim.Duration = new Duration(TimeSpan.FromSeconds(duration));
            SplinePoint3DKeyFrame p1 = new SplinePoint3DKeyFrame(start,
                                                                 KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.0)),
                                                                 splineStart);
            anim.KeyFrames.Add(p1);
            SplinePoint3DKeyFrame p2 = new SplinePoint3DKeyFrame(end,
                                                                 KeyTime.FromTimeSpan(TimeSpan.FromSeconds(duration)),
                                                                 splineEnd);
            anim.KeyFrames.Add(p2);

            return anim;
        }
Example #5
0
        private void Animate_OnClick(object sender, RoutedEventArgs e)
        {
            var lookDirectionAnimation = new Vector3DAnimationUsingKeyFrames
            {
                Duration = new Duration(TimeSpan.FromMilliseconds(7000))
            };
            lookDirectionAnimation.KeyFrames.Add(new LinearVector3DKeyFrame(new Vector3D(5, 2, -2), TimeSpan.FromMilliseconds(2000)));
            lookDirectionAnimation.KeyFrames.Add(new LinearVector3DKeyFrame(new Vector3D(2, 1, -2), TimeSpan.FromMilliseconds(4000)));
            lookDirectionAnimation.KeyFrames.Add(new LinearVector3DKeyFrame(new Vector3D(1.2, -1, -2), TimeSpan.FromMilliseconds(7000)));
            Camera.BeginAnimation(ProjectionCamera.LookDirectionProperty, lookDirectionAnimation);

            var positionAnimation = new Point3DAnimationUsingKeyFrames
            {
                Duration = new Duration(TimeSpan.FromMilliseconds(7000))
            };
            positionAnimation.KeyFrames.Add(new LinearPoint3DKeyFrame(new Point3D(0.1, 0.05, 0.2), TimeSpan.FromMilliseconds(2000)));
            positionAnimation.KeyFrames.Add(new LinearPoint3DKeyFrame(new Point3D(0, 0.05, 0.2), TimeSpan.FromMilliseconds(4000)));
            positionAnimation.KeyFrames.Add(new LinearPoint3DKeyFrame(new Point3D(-0.15, 1.2, 1.7), TimeSpan.FromMilliseconds(7000)));
            Camera.BeginAnimation(ProjectionCamera.PositionProperty, positionAnimation);
        }
        /// <summary> 
        /// Helper used by the four Freezable clone methods to copy the resolved key times and
        /// key frames. The Get*AsFrozenCore methods are implemented the same as the Clone*Core 
        /// methods; Get*AsFrozen at the top level will recursively Freeze so it's not done here. 
        /// </summary>
        /// <param name="sourceAnimation"></param> 
        /// <param name="isCurrentValueClone"></param>
        private void CopyCommon(Point3DAnimationUsingKeyFrames sourceAnimation, bool isCurrentValueClone)
        {
            _areKeyTimesValid = sourceAnimation._areKeyTimesValid; 

            if (   _areKeyTimesValid 
                && sourceAnimation._sortedResolvedKeyFrames != null) 
            {
                // _sortedResolvedKeyFrames is an array of ResolvedKeyFrameEntry so the notion of CurrentValueClone doesn't apply 
                _sortedResolvedKeyFrames = (ResolvedKeyFrameEntry[])sourceAnimation._sortedResolvedKeyFrames.Clone();
            }

            if (sourceAnimation._keyFrames != null) 
            {
                if (isCurrentValueClone) 
                { 
                    _keyFrames = (Point3DKeyFrameCollection)sourceAnimation._keyFrames.CloneCurrentValue();
                } 
                else
                {
                    _keyFrames = (Point3DKeyFrameCollection)sourceAnimation._keyFrames.Clone();
                } 

                OnFreezablePropertyChanged(null, _keyFrames); 
            } 
        }