Now, here is the full code of my Cube.But I forget the rotation on the z-Axis -.- Hopefully it´s not so hard to implement this.
void RubiksCube::drawCube(void)
{
glColor3f(0.0f,0.0f,0.0f);
glLineWidth(4.0f);
glutWireCube(2);
glBegin(GL_QUADS); // begin drawing a cube
// Front Face
glColor3f(0.0f,0.0f,1.0f);
glNormal3f( 0.0f, 0.0f, 1.0f); // front face points out of the screen on z.
glVertex3f(-1.0f, -1.0f, 1.0f); // Bottom Left
glVertex3f( 1.0f, -1.0f, 1.0f); // Bottom Right
glVertex3f( 1.0f, 1.0f, 1.0f); // Top Right
glVertex3f(-1.0f, 1.0f, 1.0f); // Top Left
// Back Face
glColor3f(1.0f,0.0f,0.0f);
glNormal3f( 0.0f, 0.0f,-1.0f); // back face points into the screen on z.
glVertex3f(-1.0f, -1.0f, -1.0f); // Bottom Right
glVertex3f(-1.0f, 1.0f, -1.0f); // Top Right
glVertex3f( 1.0f, 1.0f, -1.0f); // Top Left
glVertex3f( 1.0f, -1.0f, -1.0f); // Bottom Left
// Top Face
glColor3f(0.0f,1.0f,0.0f);
glNormal3f( 0.0f, 1.0f, 0.0f); // top face points up on y.
glVertex3f(-1.0f, 1.0f, -1.0f); // Top Left
glVertex3f(-1.0f, 1.0f, 1.0f); // Bottom Left
glVertex3f( 1.0f, 1.0f, 1.0f); // Bottom Right
glVertex3f( 1.0f, 1.0f, -1.0f); // Top Right
// Bottom Face
glColor3f(1.0f,0.5f,0.0f);
glNormal3f( 0.0f, -1.0f, 0.0f); // bottom face points down on y.
glVertex3f(-1.0f, -1.0f, -1.0f); // Top Right
glVertex3f( 1.0f, -1.0f, -1.0f); // Top Left
glVertex3f( 1.0f, -1.0f, 1.0f); // Bottom Left
glVertex3f(-1.0f, -1.0f, 1.0f); // Bottom Right
// Right face
glColor3f(1.0f,1.0f,-1.0f);
glNormal3f( 1.0f, 0.0f, 0.0f); // right face points right on x.
glVertex3f( 1.0f, -1.0f, -1.0f); // Bottom Right
glVertex3f( 1.0f, 1.0f, -1.0f); // Top Right
glVertex3f( 1.0f, 1.0f, 1.0f); // Top Left
glVertex3f( 1.0f, -1.0f, 1.0f); // Bottom Left
// Left Face
glColor3f(1.0f,1.0f,1.0f);
glNormal3f(-1.0f, 0.0f, 0.0f); // left face points left on x.
glVertex3f(-1.0f, -1.0f, -1.0f); // Bottom Left
glVertex3f(-1.0f, -1.0f, 1.0f); // Bottom Right
glVertex3f(-1.0f, 1.0f, 1.0f); // Top Right
glVertex3f(-1.0f, 1.0f, -1.0f); // Top Left
glEnd();
}
// Konstruktor
RubiksCube::RubiksCube(void)
{
rotX = 0.0f;
rotY = 0.0f;
rotZ = 0.0f;
}
void RubiksCube::move1stRow(void)
{
rotY_0 += 90.0f;
}
void RubiksCube::move1stRowBack(void)
{
rotY_0 += -90.0f;
}
void RubiksCube::move2ndRow(void)
{
rotY_1 += 90.0f;
}
void RubiksCube::move2ndRowBack(void)
{
rotY_1 += -90.0f;
}
void RubiksCube::move3rdRow(void)
{
rotY_2 += 90.0f;
}
void RubiksCube::move3rdRowBack(void)
{
rotY_2 += -90.0f;
}
void RubiksCube::move1stColumn(void)
{
rotX_0 += 90.0f;
}
void RubiksCube::move1stColumnBack(void)
{
rotX_0 += -90.0f;
}
void RubiksCube::move2ndColumn(void)
{
rotX_1 += 90.0f;
}
void RubiksCube::move2ndColumnBack(void)
{
rotX_1 += -90.0f;
}
void RubiksCube::move3rdColumn(void)
{
rotX_2 += 90.0f;
}
void RubiksCube::move3rdColumnBack(void)
{
rotX_2 += -90.0f;
}
void RubiksCube::moveZAxis1stRow(void)
{
rotZ_0 += 90.0f;
}
void RubiksCube::moveZAxis2ndRow(void)
{
rotZ_1 += 90.0f;
}
void RubiksCube::moveZAxis3rdRow(void)
{
rotZ_2 += 90.0f;
}
void RubiksCube::moveZAxis1stRowBack(void)
{
rotZ_0 += -90.0f;
}
void RubiksCube::moveZAxis2ndRowBack(void)
{
rotZ_1 += -90.0f;
}
void RubiksCube::moveZAxis3rdRowBack(void)
{
rotZ_2 += -90.0f;
}
// Ausgabe des Würfels
void RubiksCube::draw(void)
{
// WÜRFEL OBERE EBENE
//Würfel hinten rechts
glPushMatrix();
glRotatef(rotX_2, 1.0f, 0.0f, 0.0f);
glTranslatef(2.0f, 2.0f, -2.0f);
glRotatef(rotY_2, 0.0f, 1.0f, 0.0f);
drawCube();
glPopMatrix();
//Würfel Mitte
glPushMatrix();
glRotatef(rotX_1, 1.0f, 0.0f, 0.0f);
glTranslatef(0.0f, 2.0f, -2.0f);
glRotatef(rotY_2, 0.0f, 1.0f, 0.0f);
drawCube();
glPopMatrix();
//Würfel hinten links
glPushMatrix();
glRotatef(rotX_0, 1.0f, 0.0f, 0.0f);
glTranslatef(-2.0f, 2.0f, -2.0f);
glRotatef(rotY_2, 0.0f, 1.0f, 0.0f);
drawCube();
glPopMatrix();
//Würfel rechts vorne
glPushMatrix();
glRotatef(rotX_2, 1.0f, 0.0f, 0.0f);
glTranslatef(2.0f, 2.0f, 2.0f);
glRotatef(rotY_2, 0.0f, 1.0f, 0.0f);
drawCube();
glPopMatrix();
//Würfel Mitte
glPushMatrix();
glRotatef(rotX_1, 1.0f, 0.0f, 0.0f);
glTranslatef(0.0f, 2.0f, 2.0f);
glRotatef(rotY_2, 0.0f, 1.0f, 0.0f);
drawCube();
glPopMatrix();
//Würfel vorne links
glPushMatrix();
glRotatef(rotX_0, 1.0f, 0.0f, 0.0f);
glTranslatef(-2.0f, 2.0f, 2.0f);
glRotatef(rotY_2, 0.0f, 1.0f, 0.0f);
drawCube();
glPopMatrix();
//Würfel links neben Zentrum
glPushMatrix();
glRotatef(rotX_0, 1.0f, 0.0f, 0.0f);
glTranslatef(-2.0f, 2.0f, 0.0f);
glRotatef(rotY_2, 0.0f, 1.0f, 0.0f);
drawCube();
glPopMatrix();
// Würfel rechts neben Zentrum
glPushMatrix();
glRotatef(rotX_2, 1.0f, 0.0f, 0.0f);
glTranslatef(2.0f, 2.0f, 0.0f);
glRotatef(rotY_2, 0.0f, 1.0f, 0.0f);
drawCube();
glPopMatrix();
// Würfel Mitte
glPushMatrix();
glRotatef(rotX_1, 1.0f, 0.0f, 0.0f);
glTranslatef(0.0f, 2.0f, 0.0f);
glRotatef(rotY_2, 0.0f, 1.0f, 0.0f);
drawCube();
glPopMatrix();
// WÜRFEL UNTERE EBENE
//Würfel hinten rechts
glPushMatrix();
glRotatef(rotX_2, 1.0f, 0.0f, 0.0f);
glTranslatef(2.0f, -2.0f, -2.0f);
glRotatef(rotY_0, 0.0f, 1.0f, 0.0f);
drawCube();
glPopMatrix();
//Würfel Mitte
glPushMatrix();
glRotatef(rotX_1, 1.0f, 0.0f, 0.0f);
glTranslatef(0.0f, -2.0f, -2.0f);
glRotatef(rotY_0, 0.0f, 1.0f, 0.0f);
drawCube();
glPopMatrix();
//Würfel hinten links
glPushMatrix();
glRotatef(rotX_0, 1.0f, 0.0f, 0.0f);
glTranslatef(-2.0f, -2.0f, -2.0f);
glRotatef(rotY_0, 0.0f, 1.0f, 0.0f);
drawCube();
glPopMatrix();
//Würfel rechts vorne
glPushMatrix();
glRotatef(rotX_2, 1.0f, 0.0f, 0.0f);
glTranslatef(2.0f, -2.0f, 2.0f);
glRotatef(rotY_0, 0.0f, 1.0f, 0.0f);
drawCube();
glPopMatrix();
//Würfel Mitte
glPushMatrix();
glRotatef(rotX_1, 1.0f, 0.0f, 0.0f);
glTranslatef(0.0f, -2.0f, 2.0f);
glRotatef(rotY_0, 0.0f, 1.0f, 0.0f);
drawCube();
glPopMatrix();
//Würfel vorne links
glPushMatrix();
glRotatef(rotX_0, 1.0f, 0.0f, 0.0f);
glTranslatef(-2.0f, -2.0f, 2.0f);
glRotatef(rotY_0, 0.0f, 1.0f, 0.0f);
drawCube();
glPopMatrix();
//Würfel links neben Zentrum
glPushMatrix();
glRotatef(rotX_0, 1.0f, 0.0f, 0.0f);
glTranslatef(-2.0f, -2.0f, 0.0f);
glRotatef(rotY_0, 0.0f, 1.0f, 0.0f);
drawCube();
glPopMatrix();
// Würfel rechts neben Zentrum
glPushMatrix();
glRotatef(rotX_2, 1.0f, 0.0f, 0.0f);
glTranslatef(2.0f, -2.0f, 0.0f);
glRotatef(rotY_0, 0.0f, 1.0f, 0.0f);
drawCube();
glPopMatrix();
// Würfel Mitte
glPushMatrix();
glRotatef(rotX_1, 1.0f, 0.0f, 0.0f);
glTranslatef(0.0f, -2.0f, 0.0f);
glRotatef(rotY_0, 0.0f, 1.0f, 0.0f);
drawCube();
glPopMatrix();
// WÜRFEL MITTLERE EBENE
//Würfel rechts hinten
glPushMatrix();
glRotatef(rotX_2, 1.0f, 0.0f, 0.0f);
glTranslatef(2.0f, 0.0f, -2.0f);
glRotatef(rotY_1, 0.0f, 1.0f, 0.0f);
drawCube();
glPopMatrix();
//Würfel Mitte
glPushMatrix();
glRotatef(rotX_1, 1.0f, 0.0f, 0.0f);
glTranslatef(0.0f, 0.0f, -2.0f);
glRotatef(rotY_1, 0.0f, 1.0f, 0.0f);
drawCube();
glPopMatrix();
//Würfel hinten links
glPushMatrix();
glRotatef(rotX_0, 1.0f, 0.0f, 0.0f);
glTranslatef(-2.0f, 0.0f, -2.0f);
glRotatef(rotY_1, 0.0f, 1.0f, 0.0f);
drawCube();
glPopMatrix();
//Würfel rechts vorne
glPushMatrix();
glRotatef(rotX_2, 1.0f, 0.0f, 0.0f);
glTranslatef(2.0f, 0.0f, 2.0f);
glRotatef(rotY_1, 0.0f, 1.0f, 0.0f);
drawCube();
glPopMatrix();
//Würfel Mitte
glPushMatrix();
glRotatef(rotX_1, 1.0f, 0.0f, 0.0f);
glTranslatef(0.0f, 0.0f, 2.0f);
glRotatef(rotY_1, 0.0f, 1.0f, 0.0f);
drawCube();
glPopMatrix();
//Würfel vorne links
glPushMatrix();
glRotatef(rotX_0, 1.0f, 0.0f, 0.0f);
glTranslatef(-2.0f, 0.0f, 2.0f);
glRotatef(rotY_1, 0.0f, 1.0f, 0.0f);
drawCube();
glPopMatrix();
//Würfel links neben Zentrum
glPushMatrix();
glRotatef(rotX_0, 1.0f, 0.0f, 0.0f);
glTranslatef(-2.0f, 0.0f, 0.0f);
glRotatef(rotY_1, 0.0f, 1.0f, 0.0f);
drawCube();
glPopMatrix();
// Würfel rechts neben Zentrum
glPushMatrix();
glRotatef(rotX_2, 1.0f, 0.0f, 0.0f);
glTranslatef(2.0f, 0.0f, 0.0f);
glRotatef(rotY_1, 0.0f, 1.0f, 0.0f);
drawCube();
glPopMatrix();
// Würfel im Zentrum
glPushMatrix();
glRotatef(rotX_1, 1.0f, 0.0f, 0.0f);
glRotatef(rotY_1, 0.0f, 1.0f, 0.0f);
drawCubeCenter();
glPopMatrix();
}
void RubiksCube::drawCubeCenter(void)
{
glutSolidCube(2);
}