Exemplo n.º 1
0
//----------resize----------
void resize(int newWidth, int newHeight){
	//Resize Viewport
	WIDTH= newWidth;
	HEIGHT= newHeight;
	GLdouble RatioViewPort= (float)WIDTH/(float)HEIGHT;
	glViewport ( xInit, yInit, WIDTH, HEIGHT ) ;
  
	//Resize Scene Visible Area 
	//Se actualiza el área visible de la escena
	//para que su ratio coincida con ratioViewPort
	GLdouble SVAWidth= _escena.get_xRight() - _escena.get_xLeft();
	GLdouble SVAHeight= _escena.get_yTop() - _escena.get_yBot();
	GLdouble SVARatio= SVAWidth/SVAHeight;
	if (SVARatio >= RatioViewPort) {
		// Increase SVAHeight
		GLdouble newHeight= SVAWidth/RatioViewPort;
		GLdouble yMiddle= ( _escena.get_yBot() + _escena.get_yTop() )/2.0;
		_escena.set_yTop( yMiddle + newHeight/2.0);
		_escena.set_yBot( yMiddle - newHeight/2.0);
		}
	else {
		//Increase SVAWidth
		GLdouble newWidth= SVAHeight*RatioViewPort;
		GLdouble xMiddle= ( _escena.get_xLeft() + _escena.get_xRight() )/2.0;
		_escena.set_xRight( xMiddle + newWidth/2.0);
		_escena.set_xLeft(  xMiddle - newWidth/2.0);
	}

	_escena.actualizarAVE(_escena.get_xLeft(), _escena.get_xRight(), _escena.get_yBot(), _escena.get_yTop());
}
Exemplo n.º 2
0
//----------initGl----------
void intitGL() {
	glClearColor(1.0,1.0,1.0,1.0);
	glColor3f(1.0,0.0,0.0); 

	glPointSize(4.0);
	glLineWidth(2.0);

	// Viewport
    glViewport(xInit, yInit, WIDTH, HEIGHT);
    
	// Model transformation
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

	_escena.actualizarAVE(_escena.get_xLeft(), _escena.get_xRight(), _escena.get_yBot(), _escena.get_yTop());
 }
Exemplo n.º 3
0
//----------key----------
void key(unsigned char key, int x, int y) {
 
  bool need_redisplay = true;

  switch (key) {
  case 27:  /* Escape key */
    //continue_in_main_loop = false; // (**)
	glutLeaveMainLoop (); //Freeglut's sentence for stopping glut's main loop (*)
    break;

  case 13:  /* ENTER key */
	_escena.step(); //Freeglut's sentence for stopping glut's main loop (*)
    break;

  case 'w' :
	_escena.trasladarVertical( (_escena.get_yTop() - _escena.get_yBot())/10);
    break ;

  case 's' :
    _escena.trasladarVertical( -(_escena.get_yTop() - _escena.get_yBot())/10);
    break ;
  case 'a' :
    _escena.trasladarHorizontal(-(_escena.get_xRight() - _escena.get_xLeft())/10 );
    break ;

  case 'd' :
    _escena.trasladarHorizontal((_escena.get_xRight() - _escena.get_xLeft())/10 );
    break ;

  case '-' :
	_escena.quitaPelota();
    break ;

  case '+' :
	_escena.nuevaPelota();
    break ;

  case '/' :
	_escena.zoomProgresivo(0.5, 1.5);
    break ;

  case '*' :
	_escena.zoomProgresivo(2.0, 1.5);
    break ;

  case 'z' :
	cout << "Introduzca el numero de columnas a embaldosar: " ;
	cin >> nCols;
    break ;

  case 't' :
	if(_modo_timer)
		_modo_timer = false;
	else
		_modo_timer = true;
    break ;

  case 'n' :
	  if(_escena._pintar_normales)
		_escena._pintar_normales = false;
	else
		_escena._pintar_normales = true;
    break ;

  case 'm' :
	  if(_escena._pintar_mascaras)
		_escena._pintar_mascaras = false;
	else
		_escena._pintar_mascaras = true;
    break ;

	case 'b' :
	  if(_escena._usar_mascaras)
		_escena._usar_mascaras = false;
	else
		_escena._usar_mascaras = true;
    break ;

  default:
    need_redisplay = false;
    break;

  }//switch

  if (need_redisplay)
    glutPostRedisplay();
}