Files Classes Functions Hierarchy
#include <cube.h>
Public Types | |
| enum | colordef { red, green, blue, yellow, white, orange } |
| Each face of the cube has a color. More... | |
Public Member Functions | |
| cube () | |
| The cube is initially a completed cube. | |
| colordef & | access (uintc k, uintc j) |
| Access the k'th face for the i'th 2D matrix value where the face is a 3*3 matrix. | |
| void | right (uintc i) |
| Move i'th row right. | |
| void | left (uintc i) |
| Move i'th row left. | |
| void | up (uintc i) |
| Move i'th column up. | |
| void | down (uintc i) |
| Move i'th column down. | |
| void | right () |
| Move the row with the cursor right. | |
| void | left () |
| Move the row with the cursor left. | |
| void | up () |
| Move the column with the cursor up. | |
| void | down () |
| Move the column with the cursor down. | |
| void | faceleft () |
| Move the front face cube left. | |
| void | faceright () |
| Move the front face cube right. | |
| void | faceup () |
| Move the front face cube up. | |
| void | facedown () |
| Move the front face cube down. | |
| ostream & | print (ostream &os) const |
| Serialize the cube. | |
| istream & | read (istream &in) |
| Reverse of print, read in the cube. | |
| void | faceset (uintc i, colordef const c) |
| Set the face to a uniform color. | |
| void | reset () |
| All faces set to a unique color. | |
Public Attributes | |
| cursor | cs |
| The cursor is always on the front cube. | |
| colordef | xi [54] |
| The cube is defined for a fixed position. | |
Imagine a cube fixed. All movements are relative to the front face. For example to look at the left side of the cube is really moving the front face turning the cube right.
Face Layout 5 0 1 2 3 4 Face 0 1 2 3 4 5 6 7 8
Definition at line 32 of file cube.h.
| enum cube::colordef |
| cube::cube | ( | ) |
| void cube::down | ( | ) | [inline] |
| void cube::down | ( | uintc | i | ) |
| void cube::facedown | ( | ) |
| void cube::faceleft | ( | ) |
| void cube::faceright | ( | ) |
| void cube::faceup | ( | ) |
| void cube::left | ( | ) |
| void cube::left | ( | uintc | i | ) |
Serialize the cube.
Definition at line 59 of file cube.cpp.
References xi.
Referenced by operator<<().
00060 { 00061 uint index = 0; 00062 00063 for (uint i=0; i<6; ++i) 00064 { 00065 for (uint k=0; k<9; ++k) 00066 { 00067 os << (uint) (xi[index]) << " "; 00068 ++index; 00069 } 00070 os << endl; 00071 } 00072 00073 return os; 00074 }
| istream & cube::read | ( | istream & | in | ) |
Reverse of print, read in the cube.
Definition at line 76 of file cube.cpp.
References xi.
Referenced by cubepermanent::load().
00077 { 00078 00079 uint index = 0; 00080 00081 uint c; 00082 00083 for (uint i=0; i<6; ++i) 00084 { 00085 for (uint k=0; k<9; ++k) 00086 { 00087 is >> c; 00088 xi[index] = (colordef)c; 00089 ++index; 00090 } 00091 } 00092 00093 return is; 00094 }
| void cube::reset | ( | ) |
All faces set to a unique color.
Definition at line 172 of file cube.cpp.
References blue, faceset(), green, orange, red, white, and yellow.
Referenced by cube(), and cubegui::keyboard01().
00173 { 00174 faceset(0,red); 00175 faceset(1,green); 00176 faceset(2,blue); 00177 faceset(3,yellow); 00178 faceset(4,white); 00179 faceset(5,orange); 00180 }
| void cube::right | ( | ) |
Move the row with the cursor right.
Definition at line 7 of file cube.cpp.
Referenced by faceright(), and left().
00008 { 00009 // Adjusting for different coordinate system. 00010 uint k = cs.k; 00011 switch (k) 00012 { 00013 case 0: k=2; break; 00014 case 2: k=0; break; 00015 } 00016 00017 right(k); 00018 }
| void cube::right | ( | uintc | i | ) |
Move i'th row right.
Definition at line 130 of file cube.cpp.
References access().
Referenced by cubegui::keyboard01().
00131 { 00132 uintc k0 = 3*i; 00133 uintc k1 = k0+1; 00134 uintc k2 = k0+2; 00135 00136 colordef a0 = access(1,k0); 00137 colordef a1 = access(1,k1); 00138 colordef a2 = access(1,k2); 00139 00140 access(1,k0) = access(0,k0); 00141 access(1,k1) = access(0,k1); 00142 access(1,k2) = access(0,k2); 00143 00144 access(0,k0) = access(3,k0); 00145 access(0,k1) = access(3,k1); 00146 access(0,k2) = access(3,k2); 00147 00148 access(3,k0) = access(2,k0); 00149 access(3,k1) = access(2,k1); 00150 access(3,k2) = access(2,k2); 00151 00152 access(2,k0) = a0; 00153 access(2,k1) = a1; 00154 access(2,k2) = a2; 00155 }
| void cube::up | ( | ) | [inline] |
| void cube::up | ( | uintc | i | ) |
Move i'th column up.
Definition at line 97 of file cube.cpp.
References access().
Referenced by cubegui::keyboard01().
00098 { 00099 assert(i<3); 00100 00101 uintc k0 = i; 00102 uintc k1 = k0+3; 00103 uintc k2 = k0+6; 00104 00105 colordef a0 = access(5,k0); 00106 colordef a1 = access(5,k1); 00107 colordef a2 = access(5,k2); 00108 00109 access(5,k0) = access(0,k0); 00110 access(5,k1) = access(0,k1); 00111 access(5,k2) = access(0,k2); 00112 00113 access(0,k0) = access(4,k0); 00114 access(0,k1) = access(4,k1); 00115 access(0,k2) = access(4,k2); 00116 00117 uint b0 = 8-i; 00118 uint b1 = 5-i; 00119 uint b2 = 2-i; 00120 00121 access(4,k0) = access(2,b0); 00122 access(4,k1) = access(2,b1); 00123 access(4,k2) = access(2,b2); 00124 00125 access(2,b0) = a0; 00126 access(2,b1) = a1; 00127 access(2,b2) = a2; 00128 }
The cursor is always on the front cube.
Definition at line 37 of file cube.h.
Referenced by down(), cubedraw3d::draw(), cubedraw2d::draw(), cubegui::keyboard01(), left(), right(), and up().
1.5.8