Esempio n. 1
0
        private void SetupCublelets()
        {
            // The number of cubelets is volume of a solid cube minus the volume of the inside
            // cubelets.
            cubelets = new Cubelet[(int)Math.Pow(cubeSize, 3) - (int)Math.Pow(cubeSize - 2, 3)];

            // Calculate the index of the center cubelet.
            Vector3 cubeCenter = new Vector3((cubeSize - 1) / 2.0f);

            // Calculate the actual center of the Rubiks cube.
            Vector3 center = new Vector3(((scale + offset) * cubeSize - offset) / 2.0f);

            // Point the camera at the actual center.
            Camera.UpdateLookAt(center);

            // Loop through the entire solid cube and create the cubelets at the edges.
            int index = 0;

            // Loop through each z slice.
            for (int z = 0; z < cubeSize; z++)
            {
                bool isFront = z == 0;
                bool isBack  = z == cubeSize - 1;

                // Loop through each row in the current slice.
                for (int y = 0; y < cubeSize; y++)
                {
                    bool isBottom = y == 0;
                    bool isTop    = y == cubeSize - 1;

                    // Loop throuhg each column in the current row.
                    for (int x = 0; x < cubeSize; x++)
                    {
                        bool isLeft  = x == cubeSize - 1;
                        bool isRight = x == 0;

                        // If the current position is on the edge, create a new cubelet there.
                        if (isLeft || isRight || isBottom || isTop || isFront || isBack)
                        {
                            // Calculate the cubelet's orientation.
                            Orientation startingOrientation = 0;
                            startingOrientation |= isFront ? Orientation.Front : 0;
                            startingOrientation |= isBack ? Orientation.Back : 0;
                            startingOrientation |= isRight ? Orientation.Right : 0;
                            startingOrientation |= isLeft ? Orientation.Left : 0;
                            startingOrientation |= isBottom ? Orientation.Bottom : 0;
                            startingOrientation |= isTop ? Orientation.Top : 0;

                            // Create the cubelet.
                            cubelets[index++] = new Cubelet(
                                new Vector3(x, y, z), center, cubeCenter, scale,
                                offset, startingOrientation);
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        private void WhiteCross()
        {
            Cubelet redWhite = GetCubelet(Color.Red, Color.White);

            if (redWhite.CubePosition.Z == 0 && redWhite.CubePosition.Y == 2)
            {
                return;
            }

            if (redWhite.CubePosition.Z == 0)
            {
                int rotation = (int)redWhite.CubePosition.X - 1;
                cube.Rotate(new Vector3(-1, -1, 0), rotation == 0 ? 2 : rotation);

                return;
            }
        }
Esempio n. 3
0
        private void SetupCublelets()
        {
            // The number of cubelets is volume of a solid cube minus the volume of the inside
            // cubelets.
            cubelets = new Cubelet[(int)Math.Pow(cubeSize, 3) - (int)Math.Pow(cubeSize - 2, 3)];

            // Calculate the index of the center cubelet.
            Vector3 cubeCenter = new Vector3((cubeSize - 1) / 2.0f);

            // Calculate the actual center of the Rubiks cube.
            Vector3 center = new Vector3(((scale + offset) * cubeSize - offset) / 2.0f);

            // Point the camera at the actual center.
            Camera.UpdateLookAt(center);

            // Loop through the entire solid cube and create the cubelets at the edges.
            int index = 0;

            // Loop through each z slice.
            for (int z = 0; z < cubeSize; z++)
            {
                bool isFront = z == 0;
                bool isBack = z == cubeSize - 1;

                // Loop through each row in the current slice.
                for (int y = 0; y < cubeSize; y++)
                {
                    bool isBottom = y == 0;
                    bool isTop = y == cubeSize - 1;

                    // Loop throuhg each column in the current row.
                    for (int x = 0; x < cubeSize; x++)
                    {
                        bool isLeft = x == cubeSize - 1;
                        bool isRight = x == 0;

                        // If the current position is on the edge, create a new cubelet there.
                        if (isLeft || isRight || isBottom || isTop || isFront || isBack)
                        {
                            // Calculate the cubelet's orientation.
                            Orientation startingOrientation = 0;
                            startingOrientation |= isFront ? Orientation.Front : 0;
                            startingOrientation |= isBack ? Orientation.Back : 0;
                            startingOrientation |= isRight ? Orientation.Right : 0;
                            startingOrientation |= isLeft ? Orientation.Left : 0;
                            startingOrientation |= isBottom ? Orientation.Bottom : 0;
                            startingOrientation |= isTop ? Orientation.Top : 0;

                            // Create the cubelet.
                            cubelets[index++] = new Cubelet(
                                new Vector3(x, y, z), center, cubeCenter, scale,
                                offset, startingOrientation);
                        }
                    }
                }
            }
        }