Exemple #1
0
        public static RubiksCube CreateRubiksCube(Vector3D origin, int cubieNum, double cubieSize, OneOpDone oneOpDone, IFactory factory)
        {
            //if(cubieNum!=3) throw new ArgumentException("Invalid CubieNum");
            RubiksCube rubiksCube = new RubiksCube();

            rubiksCube.CubieSize  = cubieSize;
            rubiksCube._model     = factory.CreateModel();
            rubiksCube._oneOpDone = oneOpDone;
            CubeSize size = new CubeSize(cubieNum, cubieNum, cubieNum);

            rubiksCube.CubeSize = size;
            Vector3D start = origin;

            start.X -= (size.Width - 1) * cubieSize / 2;
            start.Y -= (size.Height - 1) * cubieSize / 2;
            start.Z -= (size.Depth - 1) * cubieSize / 2;
            Vector3D min = origin; min.X -= size.Width * cubieSize / 2; min.Y -= size.Height * cubieSize / 2; min.Z -= size.Depth * cubieSize / 2;
            Vector3D max = origin; max.X += size.Width * cubieSize / 2; max.Y += size.Height * cubieSize / 2; max.Z += size.Depth * cubieSize / 2;

            rubiksCube.BoundingBox = new BoundingBox3D(min, max);

            for (int i = 0; i < size.Width; i++)
            {
                for (int j = 0; j < size.Height; j++)
                {
                    for (int k = 0; k < size.Depth; k++)
                    {
                        //if (k == 0 || j == 0) //for debug
                        {
                            Vector3D cubieOri = start;
                            cubieOri.X += i * cubieSize; cubieOri.Y += j * cubieSize; cubieOri.Z += k * cubieSize;
                            string cubicleName = CubeConfiguration.GetCubicleName(size, i, j, k);
                            //Debug.WriteLine(string.Format("({0},{1},{2}): {3}", i,j,k, cubicleName));
                            if (!string.IsNullOrEmpty(cubicleName))
                            {
                                string  cubieName = cubicleName; //solved configuration
                                Cubicle cubicle   = Cubicle.CreateCubicle(cubicleName, cubieName, cubieOri, cubieSize, factory);
                                rubiksCube._cubicles.Add(cubicleName, cubicle);
                            }
                        }
                    }
                }
            }
            return(rubiksCube);
        }
Exemple #2
0
        private bool BeforeOp(AnimContext animContext)
        {
            string op = animContext.Op;

            if (op == CubeOperation.UndoOp)
            { //undo
                if (string.IsNullOrEmpty(_sequence))
                {
                    return(false);
                }

                op = CubeOperation.GetOp(ref _sequence, true, true);
                op = CubeOperation.GetReverseOp(op);
                if (!string.IsNullOrEmpty(op))
                {
                    animContext.Op = op;
                }
            }

            CubeSize size  = CubeSize;
            double   edgeX = CubieSize * size.Width / 2;
            double   edgeY = CubieSize * size.Height / 2;
            double   edgeZ = CubieSize * size.Depth / 2;

            if (op == CubeOperation.FoldOp || op == CubeOperation.UnFoldOp)
            {
                bool          unfold = (op == CubeOperation.UnFoldOp);
                FaceTransform f      = new FaceTransform("F", Axis.X, false, new Vector3D(0, edgeY, edgeZ), new Vector3D(), face => GetFaces(face))
                {
                    Silent      = true,
                    ChangeAngle = unfold ? -CubeOperation.PiOver2 : CubeOperation.PiOver2,
                    Begin       = 0,

                    /*
                     * Face = "F",
                     * AxisTranslationFromOrigin = new Vector3D(0, edgeY, edgeZ),
                     * Axis = Axis.X,
                     * IsAxisMoving = false
                     */
                };
                FaceTransform b = new FaceTransform("B", Axis.X, false, new Vector3D(0, edgeY, -edgeZ), new Vector3D(), face => GetFaces(face))
                {
                    Silent      = true,
                    ChangeAngle = unfold ? CubeOperation.PiOver2 : -CubeOperation.PiOver2,
                    Begin       = 0

                                  /*
                                   * Face = "B",
                                   * AxisTranslationFromOrigin = new Vector3D(0, edgeY, -edgeZ),
                                   * Axis = Axis.X,
                                   * IsAxisMoving = false
                                   */
                };
                FaceTransform l = new FaceTransform("L", Axis.Z, false, new Vector3D(-edgeX, edgeY, 0), new Vector3D(), face => GetFaces(face))
                {
                    Silent      = true,
                    ChangeAngle = unfold ? -CubeOperation.PiOver2 : CubeOperation.PiOver2,
                    Begin       = 0,

                    /*
                     * Face = "L",
                     * AxisTranslationFromOrigin = new Vector3D(-edgeX, edgeY, 0),
                     * Axis = Axis.Z,
                     * IsAxisMoving = false
                     */
                };
                FaceTransform r = new FaceTransform("R", Axis.Z, false, new Vector3D(edgeX, edgeY, 0), new Vector3D(), face => GetFaces(face))
                {
                    Silent      = true,
                    ChangeAngle = unfold ? CubeOperation.PiOver2 : -CubeOperation.PiOver2,
                    Begin       = 0

                                  /*
                                   * Face = "R",
                                   * AxisTranslationFromOrigin = new Vector3D(edgeX, edgeY, 0),
                                   * Axis = Axis.Z,
                                   * IsAxisMoving = false
                                   */
                };


                FaceTransform d;
                //if (unfold)
                {
                    d = new FaceTransform("D", Axis.Z, true, new Vector3D(edgeX, -edgeY, 0), new Vector3D(edgeX, edgeY, 0), face => GetFaces(face))
                    {
                        Silent      = true,
                        ChangeAngle = unfold ? CubeOperation.PiOver2 : -CubeOperation.PiOver2,
                        Begin       = 0

                                      /*
                                       * Face = "D",
                                       * AxisTranslationFromOrigin = new Vector3D(edgeX, -edgeY, 0),
                                       * Axis2TranslationFromOrigin = new Vector3D(edgeX, edgeY, 0),
                                       * Axis = Axis.Z,
                                       * IsAxisMoving = true
                                       */
                    };
                }
                animContext.TransformParams.Add(f);
                animContext.TransformParams.Add(b);
                animContext.TransformParams.Add(l);
                animContext.TransformParams.Add(r);
                animContext.TransformParams.Add(d);
            }
            else
            {
                if (!CubeOperation.IsValidOp(op))
                {
                    return(false);
                }

                BasicOp basicOp;
                bool    isReverse;
                CubeOperation.GetBasicOp(op, out basicOp, out isReverse);
                CubieTransform transform = new CubieTransform(op, isReverse, basicOp, cn => Cubicles[cn])
                {
                    Silent = animContext.Silent
                };
                transform.ChangeAngle = transform.RotateAngle - animContext.RotatedAngle;
                animContext.TransformParams.Add(transform);
            }


            return(true);
        }
Exemple #3
0
        //x--0:Left     Width-1 :Right
        //y--0:Down     Height-1:Up
        //z--0:Back     Depth-1 :Front
        //To make notation closewise, use pattern YXZ
        public static string GetCubicleName(CubeSize size, int x, int y, int z)
        {
            //StringBuilder sb = new StringBuilder();
            bool   xface   = true;
            bool   yface   = true;
            bool   zface   = true;
            bool   postive = true;
            string yFace   = string.Empty;
            string xFace   = string.Empty;
            string zFace   = string.Empty;

            if (y == 0)
            {
                yFace = "D";
                //sb.Append("D");
                postive = !postive;
            }
            else if (y == size.Height - 1)
            {
                //sb.Append("U");
                yFace = "U";
            }
            else if (size.Height > 3)
            {
                yface = false;
                //sb.Append(y);
                yFace = "D" + y.ToString();
            }


            if (x == 0)
            {
                //sb.Append("L");
                xFace   = "L";
                postive = !postive;
            }
            else if (x == size.Width - 1)
            {
                //sb.Append("R");
                xFace = "R";
            }
            else if (size.Width > 3)
            {
                xface = false;
                //sb.Append(x);
                xFace = "L" + x.ToString();
            }


            if (z == 0)
            //sb.Append("B");
            {
                zFace   = "B";
                postive = !postive;
            }
            else if (z == size.Depth - 1)
            {
                //sb.Append("F");
                zFace = "F";
            }
            else if (size.Depth > 3)
            {
                zface = false;
                //sb.Append("B");
                //sb.Append(z);
                zFace = "B" + z.ToString();
            }
            string name = string.Empty;

            if (!xface && !yface && !zface)
            {
                name = string.Empty;
            }
            else
            {
                if (!string.IsNullOrEmpty(xFace) && !string.IsNullOrEmpty(yFace) && !string.IsNullOrEmpty(zFace))
                {
                    name = postive ? yFace + xFace + zFace : yFace + zFace + xFace;
                }
                else
                {
                    name = yFace + xFace + zFace;
                }
            }
            return(name);
        }