A Rubik's Cube Implementation

This page documents a wxWidgets/OpenGL/C++ implementation of the Rubik's Cube.

Basic Usage

When the application is launched, you're initially presented with a standard 3x3x3 Rubik's Cube. You can, however, change this by using the "Program" menu to create a new cube of higher order. The requested cube size determines the width, height and depth of the cube. After creating a cube, click and drag the left mouse button in the window to orient the cube. Click and drag the right mouse button over faces of the cube to manipulate it. Also in the "Program" menu, you'll find a "Scramble Cube" option which you can use to randomize the cube by applying a randomly generated sequence of rotations.

Command Sequences

An alternative mode of cube manipulation is to use the command prompt at the bottom of the window, above the status bar. Here you can type a comma-delimeted sequence of rotation commands. The valid commands are "L", "R", "B", "F", "D", "U", without quotes, as well as their inverted counter-parts, which are given with an "i" appended. For example, "Li" is the left-inverse command, and "Di" is the down-inverse command. Exactly what faces of the cube are associated with the left, right, front, back, down-side and up-side of the cube is determined by the cube's current orientation. To see how the program is currently associating these commands with the various faces of the cube in its current orientation, select the "Show Perspective Labels" option from the "View" menu.

Of course, these commands are only applicable to the 2x2x2 and 3x3x3 cubes. For cubes having a larger number of cut-planes, (i.e., cubes of dimension NxNxN with N>3), the command language above is extended to accomodate such cubes with an added syntax that provides a way to describe any desired rotation from a given perspective. This is done by simply adding a colon, then a plane-index to any command. For example, "L:0, L:1" is equivalent to the sequence "L, Ri" for the 2x2x2 cube. Notice that the indices are zero-based.

Note that as of this writing, the "Solve Cube" feature should work for all NxNxN cubes with N>=3. I'm not sure when, if ever, I'll get around to solving the 2x2x2 case. The 3x3x3 case could have used code that solves the 2x2x2 case, but I didn't think that far ahead.

Bandaging

You can apply your own bandaging to your cube. The idea behind bandaging is to effectivly glue two or more cubies together, so that they can't become separated. In real-world practice, this can only be done between adjacent cubies. In virtual-practice, you can "glue" any two cubies together in the entire cube. Control-Left-click on a cubie to select one of its faces. This selects the cubie face, the cubie itself, and possibly all cubies faces of that color. In this case, we just care about the selected cubie. With the cubie selected, Control-Shift-Left-click some other cubie. Doing so, you're prompted for a bandaging color. After picking one, you'll see the two cubies drawn with that color applied. The two cubies are then "glued" together if you select the "Enforce Bandaging" option in the "Program Menu." Note that enforcement is not aloud to begin unless the cube is in the solved state. Expand the set of bandaged cubies by first Control-clicking a member of the bandaged set, then Control-Shift-clicking any non-member of the set.

Face Textures

There is some support for changing the textures used on the cube. You can't choose a texture for each little individual cubie face, but you can effectively do that by authoring your texture appropriately, because you can choose a new texture for an entire face of the cube. Control-Left-click on a cubie to select one of its faces. In this case, the face of the cube that's selected is the one on which the cubie face would reside if the cube was in the solved state. Then use the "Change Face Texture" option under the "View" menu. This will let you change the texture that is applied to all cubie faces having the same color as the one you selected. Use the "Stretch Texture Across Entire Face" option under the "View" menu so that your image is shown as complete once all appropriate cubies are positioned and oriented properly. This adds an interesting, additional complexity to solving the cube. Note that as of this writing, the solving algorithm does not pay any attention to the orientation of center-piece cubies; so while it will get all colors the same on every side of the cube, the orientation of the center cubies won't necessarily be correct.

Closing Remarks

Thanks for using my program. It's not perfect, but it is free, and you get what you pay for. If you have any feedback or would like to report a bug, feel free to do so. My e-mail address is "spencertparkin-at-gmail-dot-com".