private static void AnimationFunction_Changed(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            QuaternionAnimation a = (QuaternionAnimation)d;

            a._isAnimationFunctionValid = false;
            a.PropertyChanged(e.Property);
        }
        internal static void AddRotationAnimation(Storyboard storyboard, TimeSpan animationTime, TimeSpan beginTime, double angleOfRotation, Vector3D axisOfRotation, Quaternion currentRotationQuaternion)
        {
            Quaternion delta = new Quaternion(axisOfRotation, angleOfRotation);
            Quaternion newRotation = currentRotationQuaternion * delta;

            QuaternionAnimation rotationAnimation = new QuaternionAnimation(newRotation, new Duration(animationTime));
            rotationAnimation.AccelerationRatio = 0.5;
            rotationAnimation.DecelerationRatio = 0.5;
            rotationAnimation.BeginTime = beginTime;

            Storyboard.SetTargetName(rotationAnimation, "viewportCamera");

            //Property path for the animation target is going to be the Transform property's Children collection. Specifically the item at index 1 (the first item is the zoom transform),
            //which is our rotation transform, and on it we want to animate the Rotation property's Quarternion property...whew, that was confusing :)
            PropertyPath path = new PropertyPath("(0).(1)[1].(2).(3)", PerspectiveCamera.TransformProperty, Transform3DGroup.ChildrenProperty, RotateTransform3D.RotationProperty, QuaternionRotation3D.QuaternionProperty);
            Storyboard.SetTargetProperty(rotationAnimation, path);

            storyboard.Children.Add(rotationAnimation);
        }
Exemple #3
0
        void ps_GeoLocationSelected(double longitude, double latitude, FlickrPhoto photo)
        {
            MakeEarthVisible();

            // convert relative to our object
            longitude = 180 + longitude;

            if (earthLocationVisual != null)
            {
                earthLocationVisual.SetPinFill(Brushes.White);
                ((Transform3DGroup)earthLocationVisual.Transform).Children.RemoveAt(0);
            }

            earthLocationVisual = _photoToPushpin[photo];
            earthLocationVisual.SetPinFill(Brushes.Red);

            // if it had any children, clear the now
            Transform3DGroup transformGroup = new Transform3DGroup();
            transformGroup.Children.Add(new ScaleTransform3D(1, 1, 1.1));
            transformGroup.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(1, 0, 0), -latitude)));
            transformGroup.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), longitude)));
            earthLocationVisual.Transform = transformGroup;

            if (!earth.Children.Contains(earthLocationVisual))
            {
                earth.Children.Add(earthLocationVisual);
            }

            QuaternionAnimation quatAnimLong = new QuaternionAnimation(new Quaternion(new Vector3D(0, 1, 0), -longitude),
                                                                       new Duration(TimeSpan.FromMilliseconds(500)));
            QuaternionAnimation quatAnimLat = new QuaternionAnimation(new Quaternion(new Vector3D(1, 0, 0), latitude),
                                                                      new Duration(TimeSpan.FromMilliseconds(500)));

            quatAnimLat.Completed += new EventHandler(quatAnimLat_Completed);

            _myQuaternionRotLong.BeginAnimation(QuaternionRotation3D.QuaternionProperty, quatAnimLong);
            _myQuaternionRotLat.BeginAnimation(QuaternionRotation3D.QuaternionProperty, quatAnimLat);
        }