Esempio n. 1
0
int GLWidget::selectCube(int mouseX, int mouseY)
{
    const int BUFFER_SIZE = 512;
    GLuint selectionBuffer[BUFFER_SIZE];
    memset(selectionBuffer, 0, sizeof(int) * BUFFER_SIZE);
    GLint viewport[4];
    glGetIntegerv (GL_VIEWPORT, viewport);

    // tell OpenGL to use selection buffer
    glSelectBuffer(BUFFER_SIZE, selectionBuffer);

    // enter selection mode
    glRenderMode(GL_SELECT);

    // init name stack
    glInitNames();

    // Pick Matrix
    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
    gluPickMatrix(mouseX, viewport[3] - mouseY, 2, 2, viewport);
    //gluPerspective(FOV_Y,  (float)viewport[2] / viewport[3], 0.1f, 1000.0f);
    glFrustum(-1,1, -1,1, 2.0,10000.0);

    // view transform
    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();

    //glDisable(GL_BLEND);
    //glDisable(GL_LIGHTING);
    glShadeModel(GL_FLAT);

    // draw cubes
    drawCubes();

    //glEnable(GL_BLEND);
    //glEnable(GL_LIGHTING);
    glShadeModel(GL_SMOOTH);

    glMatrixMode(GL_PROJECTION);
    glPopMatrix();
    //glMatrixMode(GL_MODELVIEW);
    //glPopMatrix();
    //glFlush();

    // leave selection mode
    int hitCount = glRenderMode(GL_RENDER);

    // process hits
    if(hitCount > 0)
        return processHits(hitCount, selectionBuffer);
    else
        return -1; // not hit
}
Esempio n. 2
0
void GLWidget::paintGL()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    glTranslatef(0, 0, -cameraDistance);
    glRotatef(xRot / 16.0, 1.0, 0.0, 0.0);
    glRotatef(yRot / 16.0, 0.0, 1.0, 0.0);

    drawCubes();
}
Esempio n. 3
0
void display ( void )
{
  if ( debugOpt != DRAW_WITHOUT_SHADERS &&
       debugOpt != DRAW_WITHOUT_PHYSICS )
  {
    runCollisionDetection () ;
    runPhysics            () ;
  }

  /* Now render the scene using the results */

  glViewport ( 0, 0, win_width, win_height ) ;

  drawCubes () ;

  /* All done! */

  glutSwapBuffers   () ;
  glutPostRedisplay () ;
}
Esempio n. 4
0
/*Displays the level 1 and level 2 menus to the user*/
void menu(rubix*myRubix)
{
	int level1MenuInput = 2;
	int level2MenuInput = 1;
	do
	{
		printf("Select mode of solution\n");
		printf("1. Manual Mode\n");
		printf("2. Automated Mode\n");
		printf("Enter your selection: ");
		
		
		fflush(stdin);
		scanf("%i", &level1MenuInput);
		
		
		switch (level1MenuInput)
		{
		case 1:
		{
			printf("\n----------------------------------------------------------\n");
			printf("\nManual Mode\nTransform Operations:\n");
			
			eraseGraphics();
			drawCubes(myRubix);
			
			do
			{
				printf("\nn0 = Switch rows for the nth column from the left, where n = 1,2,3,4\n");
				printf("\n7 = Rotate Upper row left one step\n");
				printf("\n1 = Rotate Lower row left one step\n");
				printf("\n2 = Rotate the mid four \"squares/numbers\" Clockwise one step\n");
				printf("\n8 = Rotate the mid four \"squares/numbers\" aNti-clockwise one step\n");
				printf("\nEnter Transform Operation (one at a time)");
				
				fflush(stdin);
				scanf("%i", &level2MenuInput);
				
				printf("\n----------------------------------------------------------\n");
				
				
				
				manualTransform(myRubix, level2MenuInput);
				
			}while (checkCube(myRubix) == 1);
			
			break;
			
			case 2:
			{
			
				printf("\n----------------------------------------------------------\n");
				
				printf("\nAutomated Mode\nTransform Operations:\n");
				printf("\nn0 = Switch rows for the nth column from the left, where n = 1,2,3,4\n");
				printf("\n7 = Rotate Upper row left one step\n");
				printf("\n1 = Rotate Lower row left one step\n");
				printf("\n2 = Rotate the mid four \"squares/numbers\" Clockwise one step\n");
				printf("\n8 = Rotate the mid four \"squares/numbers\" aNti-clockwise one step\n");
				
				printf("\n----------------------------------------------------------\n");
				
				automaticTransform(myRubix);
				
				break;
			}
		}
		default:
		{
			printf("\nError: You have entered an invalid menu option\n");
		}
		}
	}
	while (level1MenuInput != 1 && level1MenuInput != 2);
}
//--------------------------------------------------------------
void ofApp::draw(){
    drawCubes();
    drawCopying();
    gui.draw();
}
Esempio n. 6
0
//--------------------------------------------------------------
void testApp::draw(){
	drawCubes();
	//ofDrawBitmapString("FPS: "+ofToString(ofGetFrameRate(), 0), 3, 15);
}