示例#1
0
        /// <summary>
        /// Animates the camera position and direction
        /// </summary>
        /// <param name="camera">Camera</param>
        /// <param name="newPosition">The position to animate to</param>
        /// <param name="newDirection">The direction to animate to</param>
        /// <param name="newUpDirection">The up direction to animate to</param>
        /// <param name="animationTime">Animation time in milliseconds</param>
        public static void AnimateTo(ProjectionCamera camera, Point3D newPosition, Vector3D newDirection, Vector3D newUpDirection, double animationTime)
        {
            var fromPosition    = camera.Position;
            var fromDirection   = camera.LookDirection;
            var fromUpDirection = camera.UpDirection;

            camera.Position      = newPosition;
            camera.LookDirection = newDirection;
            camera.UpDirection   = newUpDirection;

            if (animationTime > 0)
            {
                var a1 = new Point3DAnimation(fromPosition, newPosition,
                                              new Duration(TimeSpan.FromMilliseconds(animationTime)))
                {
                    AccelerationRatio = 0.3, DecelerationRatio = 0.5, FillBehavior = FillBehavior.Stop
                };
                camera.BeginAnimation(ProjectionCamera.PositionProperty, a1);

                var a2 = new Vector3DAnimation(fromDirection, newDirection,
                                               new Duration(TimeSpan.FromMilliseconds(animationTime)))
                {
                    AccelerationRatio = 0.3, DecelerationRatio = 0.5, FillBehavior = FillBehavior.Stop
                };
                camera.BeginAnimation(ProjectionCamera.LookDirectionProperty, a2);

                var a3 = new Vector3DAnimation(fromUpDirection, newUpDirection,
                                               new Duration(TimeSpan.FromMilliseconds(animationTime)))
                {
                    AccelerationRatio = 0.3, DecelerationRatio = 0.5, FillBehavior = FillBehavior.Stop
                };
                camera.BeginAnimation(ProjectionCamera.UpDirectionProperty, a3);
            }
        }
示例#2
0
        private Storyboard CreateEnteringViewStoryboard(Rectangle2D3D viewport3D)
        {
            // Camera position animation.
            Point3DAnimation cameraPositionAnimation = new Point3DAnimation
            {
                Duration       = Duration,
                From           = new Point3D(0, 0, 200),
                EasingFunction = new CircleEase {
                    EasingMode = EasingMode.EaseIn
                }
            };

            Storyboard.SetTarget(cameraPositionAnimation, viewport3D);
            Storyboard.SetTargetProperty(cameraPositionAnimation, new PropertyPath("(0).(1)", Rectangle2D3D.CameraProperty, PerspectiveCamera.PositionProperty));

            // Opacity amination.
            DoubleAnimation opacityAnimation = new DoubleAnimation {
                Duration = Duration, From = 0, To = 1
            };

            Storyboard.SetTargetProperty(opacityAnimation, new PropertyPath("Opacity"));

            // Create storyboard.
            var storyboard = new Storyboard();

            storyboard.Children.Add(cameraPositionAnimation);
            storyboard.Children.Add(opacityAnimation);

            return(storyboard);
        }
示例#3
0
        private void Viewport3D_MouseWheel(object sender, MouseWheelEventArgs e)
        {
            double scaleFactor = 3;

            //120 near ,   -120 far
            System.Diagnostics.Debug.WriteLine(e.Delta.ToString());
            Point3D  currentPosition = camera.Position;
            Vector3D lookDirection   = camera.LookDirection;//new Vector3D(camera.LookDirection.X, camera.LookDirection.Y, camera.LookDirection.Z);

            lookDirection.Normalize();

            lookDirection *= scaleFactor;

            if (e.Delta == 120)//getting near
            {
                if ((currentPosition.X + lookDirection.X) * currentPosition.X > 0)
                {
                    currentPosition += lookDirection;
                }
            }
            if (e.Delta == -120)//getting far
            {
                currentPosition -= lookDirection;
            }

            Point3DAnimation positionAnimation = new Point3DAnimation();

            positionAnimation.BeginTime  = new TimeSpan(0, 0, 0);
            positionAnimation.Duration   = TimeSpan.FromMilliseconds(100);
            positionAnimation.To         = currentPosition;
            positionAnimation.From       = camera.Position;
            positionAnimation.Completed += new EventHandler(positionAnimation_Completed);
            camera.BeginAnimation(PerspectiveCamera.PositionProperty, positionAnimation, HandoffBehavior.Compose);
        }
        public static void ZoomIn(PerspectiveCamera camera, double scaleFactor)
        {
            Point3D  oldPosition          = camera.Position;
            Vector3D currentLookDirection = camera.LookDirection;

            currentLookDirection.Normalize();

            Vector3D positionChangeVector = currentLookDirection * scaleFactor;
            Point3D  newPosition          = oldPosition + positionChangeVector;

            Point3DAnimation positionAnimation = new Point3DAnimation();

            positionAnimation.BeginTime  = new TimeSpan(0, 0, 0);
            positionAnimation.Duration   = TimeSpan.FromMilliseconds(100);
            positionAnimation.From       = oldPosition;
            positionAnimation.To         = newPosition;
            positionAnimation.Completed += (s, e) =>
            {
                Point3D position = camera.Position;
                camera.BeginAnimation(ProjectionCamera.PositionProperty, null);
                camera.Position = position;
            };

            camera.BeginAnimation(ProjectionCamera.PositionProperty, positionAnimation, HandoffBehavior.Compose);
        }
示例#5
0
        public void Move(LookDirection dir)
        {
            Point3DAnimation anim = new Point3DAnimation(Position + GetMoveVector(dir), new System.Windows.Duration(TimeSpan.FromMilliseconds(GlobalSettingsManager.Global.TurnSpeed)));

            anim.Completed += Anim_Completed;
            IsAnimated      = true;
            BeginAnimation(PerspectiveCamera.PositionProperty, anim);
        }
示例#6
0
        // animacija preko frameova
        public void KamAnimiraj(KamFrame f, double trajanje)
        {
            if (f != null)
            {
                Duration dur = new Duration(TimeSpan.FromMilliseconds(trajanje));

                Point3D kamRotKut_trenutno = KameraRotacijaKuteviXYZ_dp;
                Point3D kamRotKut_frame    = f.KameraRotacijaKuteviXYZ;
                Point3D kamRotKut_najkraci = f.KameraRotacijaKuteviXYZ;

                // ako treba napraviti rotaciju za vise od pola kruga vrti u suprotnom smjeru
                double z = kamRotKut_frame.Z - kamRotKut_trenutno.Z;
                if (z > 180)
                {
                    kamRotKut_najkraci.Z = kamRotKut_frame.Z - 360;
                }
                else if (z < -180)
                {
                    kamRotKut_najkraci.Z = kamRotKut_frame.Z + 360;
                }

                double x = kamRotKut_frame.X - kamRotKut_trenutno.X;
                if (x > 180)
                {
                    kamRotKut_najkraci.X = kamRotKut_frame.X - 360;
                }
                else if (x < -180)
                {
                    kamRotKut_najkraci.X = kamRotKut_frame.X + 360;
                }

                double y = kamRotKut_frame.Y - kamRotKut_trenutno.Y;
                if (y > 180)
                {
                    kamRotKut_najkraci.Y = kamRotKut_frame.Y - 360;
                }
                else if (y < -180)
                {
                    kamRotKut_najkraci.Y = kamRotKut_frame.Y + 360;
                }


                Point3DAnimation  anim_rot   = new Point3DAnimation(kamRotKut_najkraci, dur, FillBehavior.HoldEnd);
                Vector3DAnimation anim_trans = new Vector3DAnimation(f.KameraTranslacija, dur, FillBehavior.HoldEnd);
                DoubleAnimation   anim_zoom  = new DoubleAnimation(f.KameraZoom, dur, FillBehavior.HoldEnd);

                // buduci da imaju isti duration dovoljno je da jedna animacija digne event
                anim_zoom.Completed += new EventHandler(anim_Completed);

                //FLAG_bKameraAnimating = true;

                this.BeginAnimation(KameraTranslacijaProperty, anim_trans);
                this.BeginAnimation(KameraRotacijaKuteviXYZProperty, anim_rot);
                this.BeginAnimation(KameraZoom_dpProperty, anim_zoom);
            }
        }
示例#7
0
        /// <summary>
        /// Animates the camera position and directions.
        /// </summary>
        /// <param name="camera">
        /// The camera to animate.
        /// </param>
        /// <param name="newPosition">
        /// The position to animate to.
        /// </param>
        /// <param name="newDirection">
        /// The direction to animate to.
        /// </param>
        /// <param name="newUpDirection">
        /// The up direction to animate to.
        /// </param>
        /// <param name="animationTime">
        /// Animation time in milliseconds.
        /// </param>
        public static void AnimateTo(
            this Camera camera,
            Point3D newPosition,
            Vector3D newDirection,
            Vector3D newUpDirection,
            double animationTime)
        {
            var projectionCamera = camera as ProjectionCamera;

            if (projectionCamera == null)
            {
                return;
            }

            var fromPosition    = projectionCamera.Position;
            var fromDirection   = projectionCamera.LookDirection;
            var fromUpDirection = projectionCamera.UpDirection;

            projectionCamera.Position      = newPosition;
            projectionCamera.LookDirection = newDirection;
            projectionCamera.UpDirection   = newUpDirection;

            if (animationTime > 0)
            {
                var a1 = new Point3DAnimation(
                    fromPosition, newPosition, new Duration(TimeSpan.FromMilliseconds(animationTime)))
                {
                    AccelerationRatio = 0.3,
                    DecelerationRatio = 0.5,
                    FillBehavior      = FillBehavior.Stop
                };

                a1.Completed += (s, a) => { camera.BeginAnimation(ProjectionCamera.PositionProperty, null); };
                camera.BeginAnimation(ProjectionCamera.PositionProperty, a1);

                var a2 = new Vector3DAnimation(
                    fromDirection, newDirection, new Duration(TimeSpan.FromMilliseconds(animationTime)))
                {
                    AccelerationRatio = 0.3,
                    DecelerationRatio = 0.5,
                    FillBehavior      = FillBehavior.Stop
                };
                a2.Completed += (s, a) => { camera.BeginAnimation(ProjectionCamera.LookDirectionProperty, null); };
                camera.BeginAnimation(ProjectionCamera.LookDirectionProperty, a2);

                var a3 = new Vector3DAnimation(
                    fromUpDirection, newUpDirection, new Duration(TimeSpan.FromMilliseconds(animationTime)))
                {
                    AccelerationRatio = 0.3,
                    DecelerationRatio = 0.5,
                    FillBehavior      = FillBehavior.Stop
                };
                a3.Completed += (s, a) => { camera.BeginAnimation(ProjectionCamera.UpDirectionProperty, null); };
                camera.BeginAnimation(ProjectionCamera.UpDirectionProperty, a3);
            }
        }
示例#8
0
        ///<summary>计算当前状态下合适观察的相机位置</summary>
        public void moveCamera()  
        {
            Point3D camPos, pcenter, orgPos;
            Vector3D camLookDir, camUpDir;
            Duration duration = TimeSpan.FromSeconds(1);
            savePos = camera.Position;
            saveLookDir = camera.LookDirection;
            saveUpDir = camera.UpDirection;
            //取得占用空间,计算中心点
            double x, y, z;
            x = curSettle.RectVec.X;
            y = curSettle.RectVec.Y;
            z = curSettle.RectVec.Z;
            pcenter = new Point3D(x / 2, 0, z / 4);
            //if (x <= para.Limit.X) pcenter = new Point3D(0, pcenter.Y, pcenter.Z);
            //if (z <= para.Limit.Z) pcenter = new Point3D(pcenter.X, pcenter.Y, 0);

            if (z < y * 2) z = y * 2;
            if (z < x / 2) z = x / 2;
            matrix = Matrix3D.Identity;
            orgPos = new Point3D(pcenter.X, 0, z + y * 6.5);
            matrix.Translate(orgPos - savePos);
            matrix.RotateAt(new Quaternion(new Vector3D(1, 0, 0), -30), pcenter);
            matrix.RotateAt(new Quaternion(new Vector3D(0, 1, 0), 30), pcenter);


            camPos = matrix.Transform(orgPos);
            camLookDir = matrix.Transform(new Vector3D(0, 0, -1));
            camUpDir = matrix.Transform(new Vector3D(0, 1, 0));
            camPos = matrix.Transform(savePos);
            camLookDir = matrix.Transform(saveLookDir);
            camUpDir = matrix.Transform(saveUpDir);



            camera.Position = (camera.Transform as MatrixTransform3D).Transform(camera.Position);
            camera.LookDirection = (camera.Transform as MatrixTransform3D).Transform(camera.LookDirection);
            camera.UpDirection = (camera.Transform as MatrixTransform3D).Transform(camera.UpDirection);
            (camera.Transform as MatrixTransform3D).Matrix = Matrix3D.Identity;

            Point3DAnimation anipos = new Point3DAnimation(camera.Position, camPos, duration, FillBehavior.Stop);
            anipos.Completed += new EventHandler(anipos_Completed);
            Vector3DAnimation anilookdir = new Vector3DAnimation(camera.LookDirection, camLookDir, duration, FillBehavior.Stop);
            Vector3DAnimation aniupdir = new Vector3DAnimation(camera.UpDirection, camUpDir, duration, FillBehavior.Stop);
            camera.Position = camPos;
            camera.LookDirection = camLookDir;
            camera.UpDirection = camUpDir;

            camera.BeginAnimation(PerspectiveCamera.PositionProperty, anipos);
            camera.BeginAnimation(PerspectiveCamera.LookDirectionProperty, anilookdir);
            camera.BeginAnimation(PerspectiveCamera.UpDirectionProperty, aniupdir);
        }
示例#9
0
        private Point3DAnimation GetCameraMoveAnimation(double x1, double y1, double z1, double x2, double y2, double z2, int beginTime, int duration)
        {
            Point3DAnimation result = new Point3DAnimation(new Point3D(x1, y1, z1), new Point3D(x2, y2, z2), new Duration(TimeSpan.FromMilliseconds(duration)))
            {
                AutoReverse       = true,
                BeginTime         = TimeSpan.FromMilliseconds(beginTime),
                DecelerationRatio = 0.3
            };

            Storyboard.SetTarget(result, this);
            Storyboard.SetTargetProperty(result, new PropertyPath("CameraPosition"));
            return(result);
        }
        Point3DAnimation CreateCameraAnimation()
        {
            Point3DAnimation cameraZoomAnim = new Point3DAnimation
            {
                To           = this.CameraZoomDestination,
                Duration     = new Duration(TimeSpan.FromMilliseconds(this.AnimationLength / 2)),
                AutoReverse  = true,
                FillBehavior = FillBehavior.Stop
            };

            cameraZoomAnim.Completed += this.OnRotationCompleted;
            return(cameraZoomAnim);
        }
        /// <summary>
        /// Rotates the control in 3D space in the direction specified by the RotationDirection property
        /// over the amount of time specified by the AnimationLength property.  Set the EasingMode property
        /// before calling this method to specify how the animated rotation should behave.
        /// </summary>
        public void Rotate()
        {
            if (!this.CanRotate)
            {
                throw new InvalidOperationException("You cannot call the Rotate method of ContentControl3D when CanRotate is set to false.");
            }

            if (_viewport == null)
            {
                throw new InvalidOperationException("The ContentControl3D's control template does not contain a Viewport3D whose name is PART_Viewport.");
            }

            if (_frontRotation == null)
            {
                throw new InvalidOperationException("The ContentControl3D's control template does not contain a Visual2DViewport3D with an AxisAngleRotation3D for the front side.");
            }

            if (_backRotation == null)
            {
                throw new InvalidOperationException("The ContentControl3D's control template does not contain a Visual2DViewport3D with an AxisAngleRotation3D for the back side.");
            }

            if (this.IsRotating)
            {
                return;
            }

            // Avoid trying to animate a frozen instance.
            if (_viewport.Camera.IsFrozen)
            {
                _viewport.Camera = this.CreateCamera();
            }

            PerspectiveCamera camera = _viewport.Camera as PerspectiveCamera;

            // Create the animations.
            DoubleAnimation frontAnimation, backAnimation;

            this.PrepareForRotation(out frontAnimation, out backAnimation);
            Point3DAnimation cameraZoomAnim = this.CreateCameraAnimation();

            // Start the animations.
            _frontRotation.BeginAnimation(AxisAngleRotation3D.AngleProperty, frontAnimation);
            _backRotation.BeginAnimation(AxisAngleRotation3D.AngleProperty, backAnimation);
            camera.BeginAnimation(PerspectiveCamera.PositionProperty, cameraZoomAnim);

            this.IsRotating = true;
        }
示例#12
0
        public void Rotate()
        {
            if (_isRotating)
            {
                ++_rotationRequests;
                return;
            }
            else
            {
                _isRotating = true;
            }

            if (_viewport != null)
            {
                // Find front rotation
                Viewport2DVisual3D  backContentSurface = _viewport.Children[1] as Viewport2DVisual3D;
                RotateTransform3D   backTransform      = backContentSurface.Transform as RotateTransform3D;
                AxisAngleRotation3D backRotation       = backTransform.Rotation as AxisAngleRotation3D;

                // Find back rotation
                Viewport2DVisual3D  frontContentSurface = _viewport.Children[2] as Viewport2DVisual3D;
                RotateTransform3D   frontTransform      = frontContentSurface.Transform as RotateTransform3D;
                AxisAngleRotation3D frontRotation       = frontTransform.Rotation as AxisAngleRotation3D;

                // Create a new camera each time, to avoid trying to animate a frozen instance.
                PerspectiveCamera camera = this.CreateCamera();
                _viewport.Camera = camera;

                // Create animations.
                DoubleAnimation rotationAnim = new DoubleAnimation
                {
                    Duration = new Duration(TimeSpan.FromMilliseconds(this.AnimationLength)),
                    By       = 180
                };
                Point3DAnimation cameraZoomAnim = new Point3DAnimation
                {
                    To          = new Point3D(0, 0, 2.5),
                    Duration    = new Duration(TimeSpan.FromMilliseconds(this.AnimationLength / 2)),
                    AutoReverse = true
                };
                cameraZoomAnim.Completed += this.OnRotationCompleted;

                // Start the animations.
                frontRotation.BeginAnimation(AxisAngleRotation3D.AngleProperty, rotationAnim);
                backRotation.BeginAnimation(AxisAngleRotation3D.AngleProperty, rotationAnim);
                camera.BeginAnimation(PerspectiveCamera.PositionProperty, cameraZoomAnim);
            }
        }
示例#13
0
        public void Zoom()
        {
            Vector3D          d  = new Vector3D(0, 0, -1);
            Vector3DAnimation va = new Vector3DAnimation(d, TimeSpan.FromSeconds(3));
            Point3D           p  = GetRoundKeyPosition(0);

            p.Z += 30;
            p.X -= 7;
            p.Y -= 7;
            Point3DAnimation pa = new Point3DAnimation(p, TimeSpan.FromSeconds(3));
            DoubleAnimation  da = new DoubleAnimation(opacity_high, TimeSpan.FromSeconds(2));

            parent.KS_Cam.BeginAnimation(PerspectiveCamera.PositionProperty, pa);
            parent.KS_Cam.BeginAnimation(PerspectiveCamera.LookDirectionProperty, va);
            brush[0, 0].BeginAnimation(Brush.OpacityProperty, da);
            brush[1, 0].BeginAnimation(Brush.OpacityProperty, da);
            parent.lbl_KS_Text.Content = Properties.Resources.Finished_generating_32_roundkeys;
            parent.lbl_KS_Step.Content = Properties.Resources.Finished;
        }
示例#14
0
        private void OnClick(object sender, RoutedEventArgs e)
        {
            Button btn = e.OriginalSource as Button;

            if (btn != null)
            {
                string s = btn.Content.ToString();
                if (s == "关闭")
                {
                    this.Close();
                }

                if (_isRotating)
                {
                    return;
                }

                DoubleAnimation frontAnimation = null, backAnimation = null;

                Point3DAnimation cameraZoomAnim = new Point3DAnimation
                {
                    To           = new Point3D(0, 0, 500),
                    Duration     = new Duration(TimeSpan.FromMilliseconds(_animationLength / 2)),
                    AutoReverse  = true,
                    FillBehavior = FillBehavior.Stop
                };
                cameraZoomAnim.Completed += this.OnRotationCompleted;

                if (s == "向前")
                {
                    this.PrepareForRotation(out frontAnimation, out backAnimation, RotationDirection.LeftToRight);
                }
                else if (s == "向后")
                {
                    this.PrepareForRotation(out frontAnimation, out backAnimation, RotationDirection.RightToLeft);
                }

                frontaxis.BeginAnimation(AxisAngleRotation3D.AngleProperty, frontAnimation);
                backaxis.BeginAnimation(AxisAngleRotation3D.AngleProperty, backAnimation);
                camera.BeginAnimation(PerspectiveCamera.PositionProperty, cameraZoomAnim);
                _isRotating = true;
            }
        }
示例#15
0
        private void arrowdelclick(object sender, RoutedEventArgs e)
        {
            //拉远
            double   scaleFactor     = 3;
            Point3D  currentPosition = myPerspectiveCamera.Position;
            Vector3D lookDirection   = myPerspectiveCamera.LookDirection;//new Vector3D(camera.LookDirection.X, camera.LookDirection.Y, camera.LookDirection.Z);

            lookDirection.Normalize();
            lookDirection   *= scaleFactor;
            currentPosition -= lookDirection;
            Point3DAnimation positionAnimation = new Point3DAnimation();

            positionAnimation.BeginTime  = new TimeSpan(0, 0, 0);
            positionAnimation.Duration   = TimeSpan.FromMilliseconds(100);
            positionAnimation.To         = currentPosition;
            positionAnimation.From       = myPerspectiveCamera.Position;
            positionAnimation.Completed += new EventHandler(positionAnimation_Completed);
            myPerspectiveCamera.BeginAnimation(PerspectiveCamera.PositionProperty, positionAnimation, HandoffBehavior.Compose);
        }
        public void AnimateScene(int i)
        {
            OriginAnimation = new Point3DAnimation();
            OriginAnimation.From = this.OriginRect;
            OriginAnimation.To = new Point3D(DictionaryValuesRectangle.XFixedFromIndex[this.IndexOfRectangle + i], 0,
                DictionaryValuesRectangle.ZFixedFromIndex[this.IndexOfRectangle + i]);
            OriginAnimation.Duration = new Duration(TimeSpan.FromSeconds(DurationOfAnimation));
            OriginAnimation.EasingFunction = easingFunction;

            NormalAnimation = new Vector3DAnimation();
            NormalAnimation.From = this.NormalRect;
            NormalAnimation.To = new Vector3D(DictionaryValuesRectangle.XNormalFixedFromIndex[this.IndexOfRectangle + i], 0, 1);
            NormalAnimation.Duration = new Duration(TimeSpan.FromSeconds(DurationOfAnimation));
            NormalAnimation.EasingFunction = easingFunction;

            //Checking if the animation is completed for the property release
            //needs to be placed BEFORE the beginning of animation, else never reached
            OriginAnimation.Completed += OriginAnimation_Completed;
            NormalAnimation.Completed += NormalAnimation_Completed;

            this.BeginAnimation(RectangleForCarousel3D.OriginProperty, OriginAnimation);
            this.BeginAnimation(RectangleForCarousel3D.NormalProperty, NormalAnimation);

            this.IndexOfRectangle = this.IndexOfRectangle + i;

            //Apply the new values to the rectangle
            this.OriginRect.X = DictionaryValuesRectangle.XFixedFromIndex[this.IndexOfRectangle];
            this.OriginRect.Y = 0;
            this.OriginRect.Z = DictionaryValuesRectangle.ZFixedFromIndex[this.IndexOfRectangle];

            this.Origin = this.OriginRect;

            this.NormalRect.X = DictionaryValuesRectangle.XNormalFixedFromIndex[this.IndexOfRectangle];
            this.NormalRect.Y = 0;
            this.NormalRect.Z = 1;
            this.XPosition = DictionaryValuesRectangle.XFixedFromIndex[this.IndexOfRectangle];
            this.ZPosition = DictionaryValuesRectangle.ZFixedFromIndex[this.IndexOfRectangle];
            this.RotationX = DictionaryValuesRectangle.XNormalFixedFromIndex[this.IndexOfRectangle];
        }
示例#17
0
        public void AnimateScene(int i)
        {
            OriginAnimation      = new Point3DAnimation();
            OriginAnimation.From = this.OriginRect;
            OriginAnimation.To   = new Point3D(DictionaryValuesRectangle.XFixedFromIndex[this.IndexOfRectangle + i], 0,
                                               DictionaryValuesRectangle.ZFixedFromIndex[this.IndexOfRectangle + i]);
            OriginAnimation.Duration       = new Duration(TimeSpan.FromSeconds(DurationOfAnimation));
            OriginAnimation.EasingFunction = easingFunction;

            NormalAnimation                = new Vector3DAnimation();
            NormalAnimation.From           = this.NormalRect;
            NormalAnimation.To             = new Vector3D(DictionaryValuesRectangle.XNormalFixedFromIndex[this.IndexOfRectangle + i], 0, 1);
            NormalAnimation.Duration       = new Duration(TimeSpan.FromSeconds(DurationOfAnimation));
            NormalAnimation.EasingFunction = easingFunction;

            //Checking if the animation is completed for the property release
            //needs to be placed BEFORE the beginning of animation, else never reached
            OriginAnimation.Completed += OriginAnimation_Completed;
            NormalAnimation.Completed += NormalAnimation_Completed;

            this.BeginAnimation(RectangleForCarousel3D.OriginProperty, OriginAnimation);
            this.BeginAnimation(RectangleForCarousel3D.NormalProperty, NormalAnimation);

            this.IndexOfRectangle = this.IndexOfRectangle + i;

            //Apply the new values to the rectangle
            this.OriginRect.X = DictionaryValuesRectangle.XFixedFromIndex[this.IndexOfRectangle];
            this.OriginRect.Y = 0;
            this.OriginRect.Z = DictionaryValuesRectangle.ZFixedFromIndex[this.IndexOfRectangle];

            this.Origin = this.OriginRect;

            this.NormalRect.X = DictionaryValuesRectangle.XNormalFixedFromIndex[this.IndexOfRectangle];
            this.NormalRect.Y = 0;
            this.NormalRect.Z = 1;
            this.XPosition    = DictionaryValuesRectangle.XFixedFromIndex[this.IndexOfRectangle];
            this.ZPosition    = DictionaryValuesRectangle.ZFixedFromIndex[this.IndexOfRectangle];
            this.RotationX    = DictionaryValuesRectangle.XNormalFixedFromIndex[this.IndexOfRectangle];
        }
示例#18
0
        public void MovingView(object sender, RoutedEventArgs e)
        {
            _origCameraBeforeMovingView = Camera;
            var newCamera = _origCameraBeforeMovingView.Clone();

            #region set new camera animation
            Viewport.Camera = newCamera;

            const int duration = 3;

            var currentPosition = newCamera.Position;

            var nextPosition = new Point3D {
                X = currentPosition.X, Y = currentPosition.Y + 5, Z = currentPosition.Z
            };
            var positionAnimation = new Point3DAnimation(currentPosition, nextPosition, TimeSpan.FromSeconds(duration));
            positionAnimation.Completed += PositionAnimationCompleted;

            var currentLookDirection = new Vector3D(0, -5, -1);
            var nextLookDirection    = new Vector3D(-nextPosition.X, -nextPosition.Y, -nextPosition.Z);
            var lookAnimation        = new Vector3DAnimation(currentLookDirection, nextLookDirection, TimeSpan.FromMilliseconds(duration));

            var transform3DGroup     = new Transform3DGroup();
            var rotateTransform3D1   = new RotateTransform3D();
            var axisAngleRotation3D1 = new AxisAngleRotation3D(new Vector3D(0, 1, 0), 0.0);
            rotateTransform3D1.Rotation = axisAngleRotation3D1;
            transform3DGroup.Children.Add(rotateTransform3D1);
            newCamera.Transform = transform3DGroup;

            var tl = new DoubleAnimation(360, TimeSpan.FromSeconds(duration));

            axisAngleRotation3D1.BeginAnimation(AxisAngleRotation3D.AngleProperty, tl);
            newCamera.BeginAnimation(PerspectiveCamera.PositionProperty, positionAnimation);
            newCamera.BeginAnimation(PerspectiveCamera.LookDirectionProperty, lookAnimation);
            #endregion
        }
示例#19
0
        /// <summary>
        /// Initializes a new Workshop3D instance.
        /// </summary>
        public Workshop3D()
        {
            this.Focusable = true;

            _viewport           = new Viewport3D();
            _viewport.Focusable = false;
            AddVisualChild(_viewport);

            PerspectiveCamera camera = new PerspectiveCamera();

            _viewport.Camera = camera;
            InitializeCamera();

            // INameScope ns = NameScope.GetNameScope(_viewport);
            // NameScope.SetNameScope(this, ns);

            // NameScope.SetNameScope(this, NameScope.GetNameScope(_viewport));
            // this.DataContext = _viewport.DataContext;

            DirectionalLight light1 = new DirectionalLight(Colors.White, new Vector3D(0.0, -1.0, 1.0));
            DirectionalLight light2 = new DirectionalLight(Colors.White, new Vector3D(-1.0, -1.0, -1.0));
            DirectionalLight light3 = new DirectionalLight(Colors.White, new Vector3D(1.0, -1.0, -1.0));
            DirectionalLight light4 = new DirectionalLight(Colors.White, new Vector3D(0.0, 1.0, 0.0));

            Model3DGroup mg = new Model3DGroup();

            mg.Children.Add(light1);
            mg.Children.Add(light2);
            mg.Children.Add(light3);
            mg.Children.Add(light4);
            _defaultLightingModel.Content = mg;
            _viewport.Children.Add(_defaultLightingModel);

            _rsd = new ResourceStringDecorator();
            _rsd.AssemblyName = "Perspective.Wpf";
            _rsd.BaseName     = "Controls.Strings.Workshop3D";
            AddVisualChild(_rsd);

            _commandPanel             = new StackPanel();
            _commandPanel.Focusable   = false;
            _commandPanel.Orientation = Orientation.Vertical;
            ComponentResourceKey panelStyleKey = new ComponentResourceKey(typeof(ResourceKeys), "PanelStyle");

            _commandPanel.Style   = (Style)this.FindResource(panelStyleKey);
            _commandPanel.Opacity = _opacity;
            _rsd.Child            = _commandPanel;

            ComponentResourceKey groupBoxStyleKey = new ComponentResourceKey(typeof(ResourceKeys), "GroupBoxStyle");
            Style groupBoxStyle = (Style)this.FindResource(groupBoxStyleKey);

            GroupBox gbZoom = new GroupBox();

            gbZoom.Style = groupBoxStyle;
            _commandPanel.Children.Add(gbZoom);

            // must be called after the insertion in the element tree
            // to get benefit of the ResourceManager inherited property
            gbZoom.Header = ResourceStringDecorator.InitializeValue(gbZoom, GroupBox.HeaderProperty, "FieldOfView");

            StackPanel spZoom = new StackPanel();

            gbZoom.Content = spZoom;

            _cameraZoomJoystick            = new Joystick();
            _cameraZoomJoystick.Dimensions = Dimensions.One;
            _cameraZoomJoystick.Focusable  = false;
            _cameraZoomJoystick.IsTabStop  = false;
            _cameraZoomJoystick.Startup   += new StartupEventHandler(_cameraZoomJoystick_Startup);
            _cameraZoomJoystick.Stop      += new RoutedEventHandler(_cameraZoomJoystick_Stop);
            spZoom.Children.Add(_cameraZoomJoystick);

            TextBlock     tbZoom = new TextBlock();
            SignalBinding bZoom  = new SignalBinding();

#if DN35
            // C# 3.0 : lambda expressions
            bZoom.Converting += (sender, e) =>
#else
            // C# 2.0 : anonymous methods
            bZoom.Converting += delegate(object sender, ConverterEventArgs e)
#endif
            {
                e.ConvertedValue = String.Format(e.Culture, "{0:###.0}°", e.Value);
            };

            bZoom.Source = camera;
            bZoom.Path   = new PropertyPath("FieldOfView");
            tbZoom.SetBinding(TextBlock.TextProperty, bZoom);
            spZoom.Children.Add(tbZoom);

            GroupBox gbPosition = new GroupBox();
            gbPosition.Style = groupBoxStyle;
            _commandPanel.Children.Add(gbPosition);

            // must be called after the insertion in the element tree
            // to get benefit of the ResourceManager inherited property
            gbPosition.Header = ResourceStringDecorator.InitializeValue(gbPosition, GroupBox.HeaderProperty, "Position");

            StackPanel spPosition = new StackPanel();
            gbPosition.Content = spPosition;

            _cameraPositionJoystick           = new Joystick();
            _cameraPositionJoystick.Focusable = false;
            _cameraPositionJoystick.IsTabStop = false;
            _cameraPositionJoystick.Startup  += new StartupEventHandler(_cameraPositionJoystick_Startup);
            _cameraPositionJoystick.Stop     += new RoutedEventHandler(_cameraPositionJoystick_Stop);
            spPosition.Children.Add(_cameraPositionJoystick);

            TextBlock     tbPosition = new TextBlock();
            SignalBinding bPosition  = new SignalBinding();

#if DN35
            // C# 3.0 : lambda expressions
            bPosition.Converting += (sender, e) =>
#else
            // C# 2.0 : anonymous methods
            bPosition.Converting += delegate(object sender, ConverterEventArgs e)
#endif
            {
                Point3D p = (Point3D)e.Value;
                e.ConvertedValue = String.Format(
                    e.Culture,
                    "{0:###.0}, {1:###.0}, {2:###.0}",
                    p.X, p.Y, p.Z);
            };

            bPosition.Source = camera;
            bPosition.Path   = new PropertyPath("Position");
            tbPosition.SetBinding(TextBlock.TextProperty, bPosition);
            spPosition.Children.Add(tbPosition);

            GroupBox gbLookDirection = new GroupBox();
            gbLookDirection.Style = groupBoxStyle;
            _commandPanel.Children.Add(gbLookDirection);

            // must be called after the insertion in the element tree
            // to get benefit of the ResourceManager inherited property
            gbLookDirection.Header = ResourceStringDecorator.InitializeValue(gbLookDirection, GroupBox.HeaderProperty, "LookDirection");

            StackPanel spLookDirection = new StackPanel();
            gbLookDirection.Content = spLookDirection;

            _cameraLookDirectionJoystick            = new Joystick();
            _cameraLookDirectionJoystick.Dimensions = Dimensions.Two;
            _cameraLookDirectionJoystick.Focusable  = false;
            _cameraLookDirectionJoystick.IsTabStop  = false;
            _cameraLookDirectionJoystick.Startup   += new StartupEventHandler(_cameraLookDirectionJoystick_Startup);
            _cameraLookDirectionJoystick.Stop      += new RoutedEventHandler(_cameraLookDirectionJoystick_Stop);
            spLookDirection.Children.Add(_cameraLookDirectionJoystick);

            TextBlock     tbLookDirection = new TextBlock();
            SignalBinding bLookDirection  = new SignalBinding();
#if DN35
            // C# 3.0 : lambda expressions
            bLookDirection.Converting += (sender, e) =>
#else
            // C# 2.0 : anonymous methods
            bLookDirection.Converting += delegate(object sender, ConverterEventArgs e)
#endif
            {
                Vector3D v = (Vector3D)e.Value;
                e.ConvertedValue = String.Format(
                    e.Culture,
                    "{0:N1}, {1:N1}, {2:N1}",
                    v.X, v.Y, v.Z);
            };

            bLookDirection.Source = camera;
            bLookDirection.Path   = new PropertyPath("LookDirection");
            tbLookDirection.SetBinding(TextBlock.TextProperty, bLookDirection);
            spLookDirection.Children.Add(tbLookDirection);

            // maps the Children property on the Viewport3D Children property
            SetValue(ChildrenPropertyKey, _viewport.Children);

            Duration duration = new Duration(TimeSpan.FromSeconds(2.0));

            _cameraPositionAnimation            = new Point3DAnimation();
            _cameraPositionAnimation.Duration   = duration;
            _cameraPositionAnimation.Completed += _cameraPositionAnimation_Completed;

            _cameraLookDirectionAnimation            = new Vector3DAnimation();
            _cameraLookDirectionAnimation.Duration   = duration;
            _cameraLookDirectionAnimation.Completed += _cameraLookDirectionAnimation_Completed;

            _cameraZoomAnimation                   = new DoubleAnimation();
            _cameraZoomAnimation.Duration          = duration;
            _cameraZoomAnimation.AccelerationRatio = 0.2;
            _cameraZoomAnimation.DecelerationRatio = 0.2;

            _cameraPositionRotation        = new AxisAngleRotation3D();
            _cameraPositionRotateTransform = new RotateTransform3D(_cameraPositionRotation);

            _cameraLookDirectionRotation        = new AxisAngleRotation3D();
            _cameraLookDirectionRotateTransform = new RotateTransform3D(_cameraLookDirectionRotation);

            this.Focusable = true;
        }