예제 #1
0
 public CameraRotateAnimation(CameraLookDirection fromValue, IEnumerable <CameraLookDirection> tosValue, Duration duration, FillBehavior fillBehavior)
 {
     From         = fromValue;
     Tos          = tosValue;
     Duration     = duration;
     FillBehavior = FillBehavior;
 }
예제 #2
0
 /// <summary>
 /// Creates a new DoubleAnimation that will animate a
 /// Double property from the "fromValue" parameter of this constructor
 /// to the "toValue" parameter.
 /// </summary>
 public CameraRotateAnimation(CameraLookDirection fromValue, CameraLookDirection toValue, Duration duration)
     : this()
 {
     From     = fromValue;
     To       = toValue;
     Duration = duration;
 }
예제 #3
0
 /// <summary>
 /// Creates a new DoubleAnimation that will animate a
 /// Double property from its base value to the value specified
 /// by the "toValue" parameter of this constructor.
 /// </summary>
 public CameraRotateAnimation(CameraLookDirection toValue, Duration duration, FillBehavior fillBehavior)
     : this()
 {
     To           = toValue;
     Duration     = duration;
     FillBehavior = fillBehavior;
 }
예제 #4
0
        /// <summary>
        /// 初始化动画关键点值
        /// </summary>
        /// <param name="defaultOriginValue"></param>
        /// <param name="defaultDestinationValue"></param>
        private void InitAnimationKeyValues(CameraLookDirection defaultOriginValue, CameraLookDirection defaultDestinationValue)
        {
            if (From.HasValue)
            {
                if (To.HasValue)
                {
                    _keyValues    = new CameraLookDirection[2];
                    _keyValues[0] = From.Value;
                    _keyValues[1] = To.Value;
                }
                else if (Tos != null && Tos.Count() != 0)
                {
                    _keyValues    = new CameraLookDirection[Tos.Count() + 1];
                    _keyValues[0] = From.Value;

                    int index = 1;
                    foreach (CameraLookDirection lookDirection in Tos)
                    {
                        _keyValues[index] = lookDirection;
                        index++;
                    }
                }
                else
                {
                    _keyValues    = new CameraLookDirection[2];
                    _keyValues[0] = From.Value;
                    _keyValues[1] = defaultDestinationValue;
                }
            }
            else if (To.HasValue)
            {
                _keyValues    = new CameraLookDirection[2];
                _keyValues[0] = defaultOriginValue;
                _keyValues[1] = To.Value;
            }
            else if (Tos != null && Tos.Count() != 0)
            {
                _keyValues    = new CameraLookDirection[Tos.Count() + 1];
                _keyValues[0] = defaultOriginValue;

                int index = 1;
                foreach (CameraLookDirection lookDirection in Tos)
                {
                    _keyValues[index] = lookDirection;
                    index++;
                }
            }
            else
            {
                _keyValues    = new CameraLookDirection[2];
                _keyValues[0] = defaultOriginValue;
                _keyValues[1] = defaultDestinationValue;
            }
        }
예제 #5
0
        public override bool Equals(object obj)
        {
            if (obj == null || !(obj is CameraLookDirection))
            {
                return(false);
            }

            CameraLookDirection lookDirection = (CameraLookDirection)obj;

            return(this == lookDirection);
        }
예제 #6
0
        public CameraLookDirection GetCurrentValue(CameraLookDirection defaultOriginValue, CameraLookDirection defaultDestinationValue, AnimationClock animationClock)
        {
            ReadPreamble();

            if (animationClock == null)
            {
                throw new ArgumentNullException("animationClock");
            }

            if (animationClock.CurrentState == ClockState.Stopped)
            {
                return(new CameraLookDirection());
            }

            return(GetCurrentValueCore(defaultOriginValue, defaultDestinationValue, animationClock));
        }
예제 #7
0
        private static void OnLookDirectionChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            Panorama            panorama      = d as Panorama;
            CameraLookDirection lookDirection = (CameraLookDirection)e.NewValue;

            if (lookDirection == new CameraLookDirection())
            {
                return;
            }

            if (panorama.Camera != null)
            {
                panorama.Camera.LookDirection = lookDirection.LookDirection;
                panorama.Camera.UpDirection   = lookDirection.UpDirection;
            }
        }
예제 #8
0
        private CameraLookDirection GetCameraLookDirectionAfterRotate(CameraLookDirection originalLookDirection, Vector3D rotateAxis, double rotateAngle)
        {
            RotateTransform3D rotateTransform3D = new RotateTransform3D();

            rotateTransform3D.Rotation = new AxisAngleRotation3D(rotateAxis, rotateAngle);
            Matrix3D matrix = rotateTransform3D.Value;

            Point3D  newCameraLookPoint     = matrix.Transform(new Point3D(originalLookDirection.LookDirection.X, originalLookDirection.LookDirection.Y, originalLookDirection.LookDirection.Z));
            Vector3D newCameraLookDirection = new Vector3D(newCameraLookPoint.X, newCameraLookPoint.Y, newCameraLookPoint.Z);

            Vector3D horizontalVector3D = Vector3D.CrossProduct(new Vector3D(0, -1, 0), newCameraLookDirection);
            Vector3D upDirection        = Vector3D.CrossProduct(horizontalVector3D, newCameraLookDirection);

            CameraLookDirection cameraLookDirection = new CameraLookDirection(newCameraLookDirection, upDirection);

            return(cameraLookDirection);
        }
예제 #9
0
        private void TryValidateAnimationFunction(CameraLookDirection defaultOriginValue, CameraLookDirection defaultDestinationValue)
        {
            if (_isAnimationFunctionValid)
            {
                return;
            }

            InitAnimationKeyValues(defaultOriginValue, defaultDestinationValue);

            if (_keyValues != null && _keyValues.Length > 0)
            {
                int keyValueCount = _keyValues.Length;
                int sectionCount  = keyValueCount - 1;
                _rotateAxesOfSection = new Vector3D[sectionCount];
                for (int i = 0; i < sectionCount; i++)
                {
                    _rotateAxesOfSection[i] = Vector3D.CrossProduct(_keyValues[i].LookDirection, _keyValues[i + 1].LookDirection);
                }

                _anglesOfSection = new double[sectionCount];

                //计算每一个旋转片段的旋转角
                for (int i = 0; i < sectionCount; i++)
                {
                    _anglesOfSection[i] = Vector3D.AngleBetween(_keyValues[i].LookDirection, _keyValues[i + 1].LookDirection);
                }

                //计算总的旋转角度
                double totalAngle = _anglesOfSection.Sum();

                //计算每一个关键点的指向与初值关键点间的旋转角的总和
                double[] rotateAnglesToOriginDirection = new double[keyValueCount];
                for (int i = 0; i < sectionCount; i++)
                {
                    rotateAnglesToOriginDirection[i + 1] = rotateAnglesToOriginDirection[i] + _anglesOfSection[i];
                }

                _progressBegins = new double[keyValueCount];
                for (int i = 1; i < keyValueCount; i++)
                {
                    _progressBegins[i] = rotateAnglesToOriginDirection[i] / totalAngle;
                }
            }

            _isAnimationFunctionValid = true;
        }
예제 #10
0
        protected override CameraLookDirection GetCurrentValueCore(CameraLookDirection defaultOriginValue, CameraLookDirection defaultDestinationValue, AnimationClock animationClock)
        {
            TryValidateAnimationFunction(defaultOriginValue, defaultDestinationValue);

            double progress     = GetCurrentProgress(animationClock);
            int    sectionIndex = GetRotateSectionIndex(ref progress);

            double progressInSection = GetProgressInSection(progress, sectionIndex);

            CameraLookDirection rotateFromDirectionInSection = _keyValues[sectionIndex];

            Vector3D rotateAxis      = _rotateAxesOfSection[sectionIndex];
            double   fullRotateAngle = _anglesOfSection[sectionIndex];
            double   rotateAngle     = fullRotateAngle * progressInSection;

            CameraLookDirection cameraLookDirection = GetCameraLookDirectionAfterRotate(rotateFromDirectionInSection, rotateAxis, rotateAngle);

            return(cameraLookDirection);
        }
예제 #11
0
 protected abstract CameraLookDirection GetCurrentValueCore(CameraLookDirection defaultOriginValue, CameraLookDirection defaultDestinationValue, AnimationClock animationClock);
예제 #12
0
 public CameraRotateAnimation(CameraLookDirection fromValue, IEnumerable <CameraLookDirection> tosValue, Duration duration)
 {
     From     = fromValue;
     Tos      = tosValue;
     Duration = duration;
 }