Intro Graphics Assignment 5
Rubiks Cube
Due: November 4, 2003
Goals
In this project, you will simulate the behavior of one of the most popular hand held puzzles of all time.
Useful stuff to get you started
Very little. 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.
My solution to this assignment is here (windows)
Assignment Specifications
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.
Rate Control
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 function that checks the current time and sets a turn angle for the currently turning face.
Manipulation
The whole-cube 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.
Extra credit
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 here.
Arcball based manipulation of the cube. This is an intuitive 3D manipulator based on Ken Shoemake's graphics gem. See me if you're interseted in providing a more sophisticated manipulator.
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). The algorithm used is the one Greg knows, although there are many others. Note: I only got about 2/3 of the way through this.
You could also try to implement other sequential movement puzzle types (Skewb, Square-1, Pyraminx, Siamese cube, Rubiks Snake, etc.)
Using the sample solution
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 plausible moves to the cube.
'f': fix. This undoes any scrambling by reversing the moves.
'r': reset cube to solved state
'n': Execute the next step in Greg's cube solution algorithm.