proj home

Files   Classes   Functions   Hierarchy  

cube Class Reference

Cube model. More...

#include <cube.h>

Collaboration diagram for cube:

List of all members.

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.
colordefaccess (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.
ostreamprint (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.


Detailed Description

Cube model.

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.


Member Enumeration Documentation

Each face of the cube has a color.

Enumerator:
red 
green 
blue 
yellow 
white 
orange 

Definition at line 40 of file cube.h.

00041   { red, green, blue, 
00042     yellow, white, orange };


Constructor & Destructor Documentation

cube::cube (  ) 

The cube is initially a completed cube.

Definition at line 196 of file cube.cpp.

References reset().

00197 {
00198   reset();
00199 }


Member Function Documentation

colordef& cube::access ( uintc  k,
uintc  j 
) [inline]

Access the k'th face for the i'th 2D matrix value where the face is a 3*3 matrix.

Definition at line 54 of file cube.h.

References xi.

Referenced by right(), and up().

00055     { assert(k<6); assert(j<9); return xi[k*9+j]; }

void cube::down (  )  [inline]

Move the column with the cursor down.

Definition at line 75 of file cube.h.

References cs, down(), and cursor::j.

Referenced by down(), and facedown().

00075 { down(cs.j); }

void cube::down ( uintc  i  ) 

Move i'th column down.

Definition at line 165 of file cube.cpp.

References up().

Referenced by cubegui::keyboard01().

00166 {
00167   up(i);
00168   up(i);
00169   up(i);
00170 }

void cube::facedown (  ) 

Move the front face cube down.

Definition at line 51 of file cube.cpp.

References down().

Referenced by cubegui::keyboard01().

00052 {
00053   for (uint i=0; i<3; ++i)
00054     down(i);
00055 }

void cube::faceleft (  ) 

Move the front face cube left.

Definition at line 33 of file cube.cpp.

References left().

Referenced by cubegui::keyboard01().

00034 {
00035   for (uint i=0; i<3; ++i)
00036     left(i);
00037 }

void cube::faceright (  ) 

Move the front face cube right.

Definition at line 39 of file cube.cpp.

References right().

Referenced by cubegui::keyboard01().

00040 {
00041   for (uint i=0; i<3; ++i)
00042     right(i);
00043 }

void cube::faceset ( uintc  i,
colordef const   c 
)

Set the face to a uniform color.

Definition at line 182 of file cube.cpp.

References xi.

Referenced by reset().

00183 {
00184   uint index = i*9;
00185 
00186   for (uint i=0; i<9; ++i)
00187     xi[index++] = c;
00188 }

void cube::faceup (  ) 

Move the front face cube up.

Definition at line 45 of file cube.cpp.

References up().

Referenced by cubegui::keyboard01().

00046 {
00047   for (uint i=0; i<3; ++i)
00048     up(i);
00049 }

void cube::left (  ) 

Move the row with the cursor left.

Definition at line 20 of file cube.cpp.

References cs, and cursor::k.

Referenced by faceleft().

00021 {
00022   // Adjusting for different coordinate system.
00023   uint k = cs.k;
00024   switch (k)
00025   {
00026     case 0: k=2; break;
00027     case 2: k=0; break;
00028   }
00029 
00030   left(k);
00031 }

void cube::left ( uintc  i  ) 

Move i'th row left.

Definition at line 158 of file cube.cpp.

References right().

Referenced by cubegui::keyboard01().

00159 {
00160   right(i);
00161   right(i);
00162   right(i);
00163 }

ostream & cube::print ( ostream os  )  const

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.

References cs, and cursor::k.

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]

Move the column with the cursor up.

Definition at line 73 of file cube.h.

References cs, cursor::j, and up().

Referenced by down(), faceup(), and up().

00073 { up(cs.j); }

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 }


Member Data Documentation

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().

The cube is defined for a fixed position.

It is composed of 6 faces with 9 elements each where each element is associated with a face and position.

Definition at line 47 of file cube.h.

Referenced by access(), cubedraw::colorset(), faceset(), print(), and read().


The documentation for this class was generated from the following files:

Generated on Fri Mar 4 00:49:52 2011 for Chelton Evans Source by  doxygen 1.5.8