Пример #1
0
        protected override void BeginTransition3D(TransitionElement transitionElement, ContentPresenter oldContent, ContentPresenter newContent, Viewport3D viewport)
        {
            Brush clone = CreateBrush(oldContent);

            Size size = transitionElement.RenderSize;
            MeshGeometry3D leftDoor = CreateMesh(new Point3D(),
               new Vector3D(size.Width / 2, 0, 0),
               new Vector3D(0, size.Height, 0),
               1,
               1,
               new Rect(0, 0, 0.5, 1));

            GeometryModel3D leftDoorGeometry = new GeometryModel3D();
            leftDoorGeometry.Geometry = leftDoor;
            leftDoorGeometry.Material = new DiffuseMaterial(clone);

            AxisAngleRotation3D leftRotation = new AxisAngleRotation3D(new Vector3D(0, 1, 0), 0);
            leftDoorGeometry.Transform = new RotateTransform3D(leftRotation);

            GeometryModel3D rightDoorGeometry = new GeometryModel3D();
            MeshGeometry3D rightDoor = CreateMesh(new Point3D(size.Width / 2, 0, 0),
                 new Vector3D(size.Width / 2, 0, 0),
                 new Vector3D(0, size.Height, 0),
                 1,
                 1,
                 new Rect(0.5, 0, 0.5, 1));

            rightDoorGeometry.Geometry = rightDoor;
            rightDoorGeometry.Material = new DiffuseMaterial(clone);

            AxisAngleRotation3D rightRotation = new AxisAngleRotation3D(new Vector3D(0, 1, 0), 0);
            rightDoorGeometry.Transform = new RotateTransform3D(rightRotation, size.Width, 0, 0);


            Model3DGroup doors = new Model3DGroup();
            doors.Children.Add(leftDoorGeometry);
            doors.Children.Add(rightDoorGeometry);

            ModelVisual3D model = new ModelVisual3D();
            model.Content = doors;

            // Replace old content in visual tree with new 3d model
            transitionElement.HideContent(oldContent);
            viewport.Children.Add(model);

            DoubleAnimation da = new DoubleAnimation(90 - 0.5 * FieldOfView, Duration);
            leftRotation.BeginAnimation(AxisAngleRotation3D.AngleProperty, da);

            da = new DoubleAnimation(-(90 - 0.5 * FieldOfView), Duration);
            rightRotation.BeginAnimation(AxisAngleRotation3D.AngleProperty, da);

            da = new DoubleAnimation(0, Duration);
            da.Completed += delegate
            {
                EndTransition(transitionElement, oldContent, newContent);
            };
            clone.BeginAnimation(Brush.OpacityProperty, da);
        }
Пример #2
0
 void BoardViewerViewPort3D_BoardChanged()
 {
     if (Board != null)
     {
         //this.Board = new BoardVisual(new XmlBoard(8, 8));
         DoubleAnimation da = new DoubleAnimation();
         da.From = 0;
         da.To = 360;
         da.Duration = TimeSpan.FromSeconds(15);
         da.RepeatBehavior = RepeatBehavior.Forever;
         AxisAngleRotation3D r = new AxisAngleRotation3D();
         r.Axis = new Vector3D(0, 1, 0);
         this.Board.Transform = new RotateTransform3D(r);
         r.BeginAnimation(AxisAngleRotation3D.AngleProperty, da);
     }
 }
Пример #3
0
        public void Grid_MouseDown(object sender, MouseButtonEventArgs e)
        {
            DoubleAnimation da = new DoubleAnimation();

            da.Duration = new Duration(TimeSpan.FromSeconds(1));
            if (e.ClickCount == 2)
            {
                da.To = 0d;
            }
            else
            {
                da.To = 180d;
            }
            System.Windows.Media.Media3D.AxisAngleRotation3D aar = Application.Current.MainWindow.FindName("aar") as AxisAngleRotation3D;
            aar.BeginAnimation(AxisAngleRotation3D.AngleProperty, da);
        }
Пример #4
0
        private DoubleAnimation Rotate(int face, double angle, double animationTime = 200)
        {
            Vector3D axis = RotationAxis[face];
            DoubleAnimation result = null;

            // we must update the array that contains the position of each cubelet
            var rotatedCubelets = new Model3DGroup[Size, Size, Size];
            for (int i = 0; i < Size; i++)
                for (int j = 0; j < Size; j++)
                    for (int k = 0; k < Size; k++)
                        rotatedCubelets[i, j, k] = cubelets[i, j, k];

            // positive angle is turning clockwise
            // turning face 0: (fix,*,*)

            //  2,0 2,1 2,2      2,2 1,2 0,2
            //  1,0 1,1 1,2  =>  2,1 1,1 0,1 
            //  0,0 0,1 0,2      2,0 1,0 0,0

            // if angle is negative we need to rotate 
            // the cubelets the other way

            int n = Size - 1;

            // this method only supports rotating the outer sides of the cube

            for (int a = 0; a < Size; a++)
            {
                for (int b = 0; b < Size; b++)
                {
                    int at = b;
                    int bt = n - a;
                    if (angle < 0)
                    {
                        at = n - b;
                        bt = a;
                    }

                    Model3DGroup group = null;
                    switch (face)
                    {
                        case 0:
                            group = rotatedCubelets[0, at, bt] = cubelets[0, a, b];
                            break;
                        case 1:
                            group = rotatedCubelets[n, bt, at] = cubelets[n, b, a];
                            break;
                        case 2:
                            group = rotatedCubelets[bt, 0, at] = cubelets[b, 0, a];
                            break;
                        case 3:
                            group = rotatedCubelets[at, n, bt] = cubelets[a, n, b];
                            break;
                        case 4:
                            group = rotatedCubelets[at, bt, 0] = cubelets[a, b, 0];
                            break;
                        case 5:
                            group = rotatedCubelets[bt, at, n] = cubelets[b, a, n];
                            break;
                        default:
                            continue;
                    }

                    var rot = new AxisAngleRotation3D { Axis = axis };
                    var anim = new DoubleAnimation(angle, new Duration(TimeSpan.FromMilliseconds(animationTime)))
                                   {
                                       AccelerationRatio = 0.3,
                                       DecelerationRatio = 0.5
                                   };

                    rot.BeginAnimation(AxisAngleRotation3D.AngleProperty, anim);
                    if (result == null)
                        result = anim;

                    var rott = new RotateTransform3D(rot);
                    var gt = new Transform3DGroup();
                    gt.Children.Add(group.Transform);
                    gt.Children.Add(rott);
                    group.Transform = gt;
                }
            }
            cubelets = rotatedCubelets;

            // can subscribe to the Completed event on this
            return result;
        }
Пример #5
0
        private ModelVisual3D MakeSide(
            ContentPresenter content,
            Point3D origin,
            Vector3D u,
            Vector3D v,
            double endAngle,
            Point3D rotationCenter,
            Vector3D rotationAxis,
            EventHandler onCompleted)
        {
            MeshGeometry3D sideMesh = CreateMesh(origin, u, v, 1, 1, new Rect(0, 0, 1, 1));

            GeometryModel3D sideModel = new GeometryModel3D();
            sideModel.Geometry = sideMesh;

            Brush clone = CreateBrush(content);
            sideModel.Material = new DiffuseMaterial(clone);

            AxisAngleRotation3D rotation = new AxisAngleRotation3D(rotationAxis, 0);
            sideModel.Transform = new RotateTransform3D(rotation, rotationCenter);

            DoubleAnimation da = new DoubleAnimation(endAngle, Duration);
            if (onCompleted != null)
                da.Completed += onCompleted;

            rotation.BeginAnimation(AxisAngleRotation3D.AngleProperty, da);

            ModelVisual3D side = new ModelVisual3D();
            side.Content = sideModel;
            return side;
        }
Пример #6
0
        protected override void BeginTransition3D(TransitionPresenter transitionElement, ContentPresenter oldContent, ContentPresenter newContent, Viewport3D viewport)
        {
            Size size = transitionElement.RenderSize;

            // Create a rectangle
            MeshGeometry3D mesh = CreateMesh(new Point3D(),
                new Vector3D(size.Width, 0, 0),
                new Vector3D(0, size.Height, 0),
                1,
                1,
                new Rect(0, 0, 1, 1));

            GeometryModel3D geometry = new GeometryModel3D();
            geometry.Geometry = mesh;
            VisualBrush clone = new VisualBrush(oldContent);
            geometry.Material = new DiffuseMaterial(clone);

            ModelVisual3D model = new ModelVisual3D();
            model.Content = geometry;

            viewport.Children.Add(model);

            Vector3D axis;
            Point3D center = new Point3D();
            switch (Direction)
            {
                case RotateDirection.Left:
                    axis = new Vector3D(0, 1, 0);
                    break;
                case RotateDirection.Right:
                    axis = new Vector3D(0, -1, 0);
                    center = new Point3D(size.Width, 0, 0);
                    break;
                case RotateDirection.Up:
                    axis = new Vector3D(-1, 0, 0);
                    break;
                default:
                    axis = new Vector3D(1, 0, 0);
                    center = new Point3D(0, size.Height, 0);
                    break;
            }
            AxisAngleRotation3D rotation = new AxisAngleRotation3D(axis, 0);
            model.Transform = new RotateTransform3D(rotation, center);

            DoubleAnimation da = new DoubleAnimation(0, Duration);
            clone.BeginAnimation(Brush.OpacityProperty, da);

            da = new DoubleAnimation(90 , Duration);
            da.Completed += delegate
            {
                EndTransition(transitionElement, oldContent, newContent);
            };
            rotation.BeginAnimation(AxisAngleRotation3D.AngleProperty, da);
        }
Пример #7
0
        void animate(int i)
        {
            Dictionary<Move, CubeFace> dominantFaces = new Dictionary<Move, CubeFace> {
                {Move.B, CubeFace.R},
                {Move.D, CubeFace.R},
                {Move.E, CubeFace.R},
                {Move.F, CubeFace.R},
                {Move.L, CubeFace.F},
                {Move.M, CubeFace.F},
                {Move.R, CubeFace.F},
                {Move.S, CubeFace.R},
                {Move.U, CubeFace.F},
            };

            HashSet<Move> possibleMoves = new HashSet<Move>();
            Vector3D axis = new Vector3D();
            double angle = 90 * Convert.ToInt32(moves[i].Value);
            axis = getRotationAxis(moves[i].Key);

            AxisAngleRotation3D rotation = new AxisAngleRotation3D(axis, angle);
            RotateTransform3D transform = new RotateTransform3D(rotation, new Point3D(0, 0, 0));

            DoubleAnimation animation = new DoubleAnimation(0, angle, animationDuration);

            foreach (Cube c in this.Children) {
                possibleMoves = new HashSet<Move>(c.possibleMoves);
                possibleMoves.Remove((Move)dominantFaces[moves[i].Key]);

                if (possibleMoves.Contains(moves[i].Key)) {
                    c.possibleMoves = getNextPossibleMoves(c.possibleMoves, moves[i].Key, moves[i].Value);
                    c.rotations.Children.Add(transform); rotation.BeginAnimation(AxisAngleRotation3D.AngleProperty, animation);
                }
            }

            animation.Completed += new EventHandler(animation_Completed);
            rotation.BeginAnimation(AxisAngleRotation3D.AngleProperty, animation);
            projection.rotate(moves[i]);
        }
Пример #8
0
        public bool rotate(KeyValuePair<Move, RotationDirection> move)
        {
            if (animation_lock) {
                return false;
            }

            Dictionary<Move, CubeFace> dominantFaces = new Dictionary<Move, CubeFace> {
                {Move.B, CubeFace.R},
                {Move.D, CubeFace.R},
                {Move.E, CubeFace.R},
                {Move.F, CubeFace.R},
                {Move.L, CubeFace.F},
                {Move.M, CubeFace.F},
                {Move.R, CubeFace.F},
                {Move.S, CubeFace.R},
                {Move.U, CubeFace.F},
            };

            HashSet<Move> possibleMoves = new HashSet<Move>();
            Vector3D axis = getRotationAxis(move.Key);

            double angle = 90 * Convert.ToInt32(move.Value);

            AxisAngleRotation3D rotation = new AxisAngleRotation3D(axis, angle);
            RotateTransform3D transform = new RotateTransform3D(rotation, new Point3D(0, 0, 0));

            DoubleAnimation animation = new DoubleAnimation(0, angle, animationDuration);

            foreach(Cube c in this.Children){
                possibleMoves = new HashSet<Move>(c.possibleMoves);
                possibleMoves.Remove((Move)dominantFaces[move.Key]);
                if(possibleMoves.Contains(move.Key)){
                    c.possibleMoves = getNextPossibleMoves(c.possibleMoves, move.Key, move.Value);

                    c.rotations.Children.Add(transform);
                }
            }

            projection.rotate(move);
            rotation.BeginAnimation(AxisAngleRotation3D.AngleProperty, animation);

            return true;
        }
Пример #9
0
        private void InitAnimations()
        {
            foreach (GradientBall ball in _balls)
            {
                var animation = new DoubleAnimation(0, 360, new Duration(new TimeSpan(0, 0, 5))) { By = 0.5, RepeatBehavior = RepeatBehavior.Forever };

                var vect = new Vector3D(0, 1, 0);
                var rt3D = new AxisAngleRotation3D(vect, 0);
                var transform = new RotateTransform3D(rt3D);
                ball.TransformGroup.Children.Add(transform);
                rt3D.BeginAnimation(AxisAngleRotation3D.AngleProperty, animation);
            }
        }