In this project, you will simulate the behavior of one of the most popular hand held puzzles of all time. This is not a group assignment!
We have provided a couple of useful C++ classes to parse command line arguments and to query a high resolution timer for rate control. There is also a little main function that shows you how to use the parser and the timer. The main function is already set up to parse the required command line arguments for your assignment.
A solution to this assignment is here (windows) (and you will also need glut32.dll if it's not already installed)
The following features are required of your simulator:
The cube should be drawn in 3D using perspective
The cube should start in a "solved" state
The user should be able to auto-scramble the cube
The solution to a scrambled cube should be animated and "rate controlled"
The user should be able to specify the "dicing" of the cube --- it should not be restricted to 3x3x3
The user should be able to rotate the entire cube with the mouse (even while it is animating).
If you don't know how to solve a Rubiks cube (or ones with more little cubies), don't worry, all you have to do is remember the sequence of moves you used to scramble it, and undo them. That's very hard for a human, but not much work for a computer.
The turns of your cube faces should be rate controlled. That means that it always takes the same amount of time for a face to complete a turn, regardless of the speed of the computer you're running on. To do this, you will need to use an "idle" callback function that checks the current time and sets a turn angle for the currently turning face.
The mouse manipulation doesn't have to be as sophisticated as the one in the sample solution. It's enough just to rotate the cube around one of its axes as the mouse is moved around with a button down. Just make sure that the animation keeps going while the rotation happens.
The sample solution is a little nuts. Here are some things it supports:
Textured cube faces. We will provide 54 textures (9 of each color), scanned from an original Rubiks Cube. Place these randomly on the individual faces. Be careful that the textures don't flip or rotate when the cube rotates. The textures are available below.
Arcball based manipulation of the cube. This is an intuitive 3D manipulator based on Ken Shoemake's graphics gem. See here for more information.
Predefined patterns. The user can specify (either in the command line or in a file) a set of moves to be applied to the outer faces of a solved cube, and the program will animate those moves. The moves are specified in a semi-standard notation used to describe Rubiks Cube patterns.
Cube dumps. The user can dump the current state of the cube on the screen to a file and re-load that configuration later.
Full solution algorithm. The program can solve an arbitrary Rubiks Cube using a real solution algorithm (not by undoing moves). There are many such algorithms available online.
You could also try to implement other sequential movement puzzle types (Skewb, Square-1, Pyraminx, Siamese cube, Rubiks Snake, etc.)
The sample solution supports several command line arguments. Some of them are required of your submission; those are shown in red.
-t <rate>: Set the rate of rotation (in seconds). Default .33 (one third, not 33 seconds)
-d <dimension>: Set the size of the cube (NxNxN). Default 3
-m <moves>: Set the number of moves to apply when scrambling. Default 20
-p <pattern>: Animate the specified pattern applied to a solved cube
-f <file>: Animate the pattern contained in the specified file to a solved cube
-s <file>: Read the initial state of the cube from the specified file
In addition, you can press a few keys in the window:
't': toggle texturing. The program needs to be able to FIND the texture files. Set the environment variable RUBIKS_IMAGES to the directory containing the 55 textures.
'd': dump. Spits out a file called 'dump' that can be read back in with '-s' later.
'q': quit
's': scramble. This applies some random moves to the cube.
'f': fix. This solves the cube.
'r': reset cube to solved state
'n': Execute the next step in the (partially completed) cube solution algorithm.
Enclosed in the zip file below are 54 textures, which are scans of the individual cube faces from my Rubiks cube.
Each texture is 256x256, and is in "RAW" format, meaning that there is absolutely NO header information in the file, and no compression. The file is simply raw image data, with 8 bits per color channel. Each pixel is contiguous, so the first three bytes of the file represent the color of the first pixel in the image, and so on.
To use these textures in the sample implementation, uncompress them to a directory called "images", and run the sample program from its parent directory. Alternately, you can set the RUBIKS_IMAGES environment variable to point to the full path of the "images" directory you just created, and run the binary from anywhere.
Submit hw4.zip when finished.