Esempio n. 1
0
// Draw the rubix cube to the window with its current rotation, textures, and position.
// To have a multi-texture cube and prevent clipping, additional quads are draw slightly
// raised off the main cube.
void drawRubixCube() {
	glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
	glLoadIdentity();
	
	glTranslatef (0, 0, -6);
	glColor3f(0, 0, 0);

	rotateCube();
	
	glBegin(GL_QUADS);
		for( int i = 0; i < 6; i++ )
			drawQuad(i, 0);
	glEnd();
	
	glColor3f(1, 1, 1);

	for( int i = 0; i < 6; i++ ) {
		glBindTexture(GL_TEXTURE_2D, texture[i]);
		glBegin(GL_QUADS);
			drawQuad(i, 0.005);
		glEnd();
	}

	SDL_GL_SwapWindow(mainWindow);
}
Esempio n. 2
0
void drawCube() {

    rotateCube();

    glPushMatrix();
    glTranslatef(0.0f, 0.0f, 0.5f);
    if (cubeColors[2] == 0) {
        drawRectangle(0.3f, 0.3f, 0.3f, 1.0f, 1.0f);
    } else {
        drawRectangle(0.0f, 0.0f, 1.0f, 1.0f, 1.0f);
    }
    glTranslatef(0.0f,0.0f,-1.0f);
    if (cubeColors[0] == 0) {
        drawRectangle(0.3f, 0.3f, 0.3f, 1.0f, 1.0f);
    } else {
        drawRectangle(0.0f, 0.0f, 1.0f, 1.0f, 1.0f);
    }
    glPopMatrix();

    glPushMatrix();
    glRotatef(90,0.0f,1.0f,0.0f);
    glTranslatef(0.0f,0.0f,0.5f);
    if (cubeColors[5] == 0) {
        drawRectangle(0.3f, 0.3f, 0.3f, 1.0f, 1.0f);
    } else {
        drawRectangle(0.0f, 0.0f, 1.0f, 1.0f, 1.0f);
    }
    glTranslatef(0.0f,0.0f,-1.0f);
    if (cubeColors[4] == 0) {
        drawRectangle(0.3f, 0.3f, 0.3f, 1.0f, 1.0f);
    } else {
        drawRectangle(0.0f, 0.0f, 1.0f, 1.0f, 1.0f);
    }
    glPopMatrix();

    glPushMatrix();
    glRotatef(90,1.0f,0.0f,0.0f);
    glTranslatef(0.0f,0.0f,0.5f);
    if (cubeColors[1] == 0) {
        drawRectangle(0.3f, 0.3f, 0.3f, 1.0f, 1.0f);
    } else {
        drawRectangle(0.0f, 0.0f, 1.0f, 1.0f, 1.0f);
    }
    glTranslatef(0.0f,0.0f,-1.0f);
    if (cubeColors[3] == 0) {
        drawRectangle(0.3f, 0.3f, 0.3f, 1.0f, 1.0f);
    } else {
        drawRectangle(0.0f, 0.0f, 1.0f, 1.0f, 1.0f);
    }
    glPopMatrix();
}
Esempio n. 3
0
// Draw the rubik's cube to the window with its current rotation, textures, and position.
// To have a multi-texture cube and prevent clipping, additional quads are draw slightly
// raised off the main cube.
void drawRubiksCube() {
	glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
	glLoadIdentity();
	glTranslatef (0, 0, -6);
	
	rotateCube();
	
	glColor3f(0, 0, 0);
	glPushMatrix();
	for( int i = 0; i < 6; i++ ) {
		drawFace(i);
	}
	glPopMatrix();

	SDL_GL_SwapWindow(mainWindow);
}
// ************************************************************
int main( void)
{
//    double t;
    short v, i, j;
    char start;
    char roll;
    char s[32], kj;

    // init offsets
    x0 = 125;
    y0 = 100;
    z0 = 200;
    
    // hardware and video initialization 
    MMBInit();
    initVideo();
    initMatrix( mw, AOFFS, BOFFS, GOFFS, x0, y0, z0);
        
    // 3. main loop
    while( 1)
    {
        roll = 1;
        start = 0;
        gClearScreen();          
    
        // splash screen
        setColor( 2);  // red
        AT(8, 1); putsV( "Rubik's Cube Demo");
        AT(8, 3); putsV( "   LDJ v1.0");
        AT(8, 5); putsV( " for PIC32MX4 MMB");
        copyV();                        // update visible screen
        while( !MMBReadKey());
        srand( ReadCoreTimer());
             
        // clear all objects
        objc = MAXOBJ;
        pyc = MAXPOLY;
        pc = MAXP;
        
        // init all objects angles
        for( i=0; i<MAXOBJ; i++)
            a[i] = b[i] = g[i] = 0;
     
        // create the rubik cube
        newCube();
        
        // init cursor and define grid
        qx = 1; qy = 1;
        initGrid();        
        
        while ( roll)
        {
            // paint cube in current position (with cursor)
            gClearScreen();                 // clear the hidden screen
            for( i=objc; i<MAXOBJ; i++)
            {
                initMatrix( mo, 0, 0, 0, 0, 0, 0);
                drawObject( mo, i);
            }
            drawCursor( qx, qy);
            copyV();
            
            // read the joystick and rotate center rows 
            kj = MMBGetKey();
            
            if ( kj & 0x80)         // long pressure 
            {
                switch( kj & 0x7F){
                  case JOY_RIGHT:   // rotate whole cube
                        rotateCube( 0, +1, 0);
                    break;
                  case JOY_LEFT:    // rotate whole cube
                        rotateCube( 0, -1, 0);
                    break;
                  case JOY_UP:      // rotate whole cube
                        rotateCube( -1, 0, 0);
                    break;
                  case JOY_DOWN:    // rotate whole cube
                        rotateCube( +1, 0, 0);
                    break;
                  case JOY_SELECT:  // rotate face counter clockwise
                        rotateRow( 0, 0, 1, 2, +1);
                    break;
                }
            }
            else                    // short pressure
            {                       
                switch( kj){
                  case JOY_RIGHT:   // rotate only the current row 
                    if (qx == 2)
                        rotateRow( 0, 1, 0, qy, +1);
                    else qx++;
                    break;
                  case JOY_LEFT:    // rotate only the current row 
                    if (qx == 0)
                        rotateRow( 0, 1, 0, qy, -1);
                    else qx--;
                    break;
                  case JOY_UP:      // rotate only the current row 
                    if (qy == 2)
                        rotateRow( 1, 0, 0, qx, -1);
                    else qy++;
                    break;
                  case JOY_DOWN:    // rotate only the current row 
                    if (qy == 0)
                        rotateRow( 1, 0, 0, qx, +1);
                    else qy--;
                    break;
                  case JOY_SELECT:  // rotate face clockwise
                        rotateRow( 0, 0, 1, 2, -1);
                    break;
                } // switch
            } // short pressure     
        } //roll        
    } // main loop
} // main
Esempio n. 5
0
void update(int x){
	cube_a.createNormals();
	cube_b.createNormals();
	cube_c.createNormals();
	cube_d.createNormals();
	cube_e.createNormals();

	cube_a.createEdges();
	cube_b.createEdges();
	cube_c.createEdges();
	cube_d.createEdges();
	cube_e.createEdges();

	checkInsideVF(&cube_a);
	checkInsideVF(&cube_b);
	checkInsideVF(&cube_c);
	checkInsideVF(&cube_d);
	checkInsideVF(&cube_e);

	//check for cubes colliding with each other
	if(cubesColliding(&cube_a, &cube_b)){
		swapCubeProperties(&cube_a, &cube_b);
	}

	if(cubesColliding(&cube_a, &cube_c)){
		swapCubeProperties(&cube_a, &cube_c);
	}

	if(cubesColliding(&cube_a, &cube_d)){
		swapCubeProperties(&cube_a, &cube_d);
	}

	if(cubesColliding(&cube_a, &cube_e)){
		swapCubeProperties(&cube_a, &cube_e);
	}

	if(cubesColliding(&cube_b, &cube_c)){
		swapCubeProperties(&cube_b, &cube_c);
	}

	if(cubesColliding(&cube_b, &cube_d)){
		swapCubeProperties(&cube_b, &cube_d);
	}

	if(cubesColliding(&cube_b, &cube_e)){
		swapCubeProperties(&cube_b, &cube_e);
	}

	if(cubesColliding(&cube_c, &cube_d)){
		swapCubeProperties(&cube_c, &cube_d);
	}

	if(cubesColliding(&cube_c, &cube_e)){
		swapCubeProperties(&cube_c, &cube_e);
	}

	if(cubesColliding(&cube_d, &cube_e)){
		swapCubeProperties(&cube_d, &cube_e);
	}

	translateCube(&cube_a);
	translateCube(&cube_b);
	translateCube(&cube_c);
	translateCube(&cube_d);
	translateCube(&cube_e);

	rotateCube(&cube_a);
	rotateCube(&cube_b);
	rotateCube(&cube_c);
	rotateCube(&cube_d);
	rotateCube(&cube_e);

	glutTimerFunc(16, update, 0);
	glutPostRedisplay();  
}