Exemplo n.º 1
0
//----------mouseWheel----------
void mouseWheel(int button, int state, int x, int y)
{
	if (state > 0) // Zoom IN
    {
		_escena.zoomPercent(125);
    }
    else // Zoom OUT
    {
		_escena.zoomPercent(80);
    }

    glutPostRedisplay();
}
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
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 'a':
            escena.step();
            break;
        case 's':
            automatico = !automatico;
            break;
        case '+':
            zoom(1.2);
            break;
        case '-':
            // Zoom out 0.9
            zoom(0.8);
            break;
        default:
            need_redisplay = false;
            break;
    }//switch

    if (need_redisplay)
        glutPostRedisplay();
}
Exemplo n.º 4
0
void tick(int value) {
    //cout << "TICK: " << value << endl;
    if (automatico) {
        escena.step();
        glutPostRedisplay();
    }
    glutTimerFunc(ms, tick, value + 1);
}
Exemplo n.º 5
0
//----------display----------
void display(void) {
  glClear( GL_COLOR_BUFFER_BIT );

  // Scene rendering
  _escena.embaldosar(nCols);

  glFlush();
  glutSwapBuffers();
}
Exemplo n.º 6
0
//---------timer---------
void timer(int n)
{
	if (_modo_timer)
	{
		_escena.step();
		glutPostRedisplay();
	}

	glutTimerFunc(_delay, timer, 0);
}
Exemplo n.º 7
0
//----------mouse----------
void mouse(int button, int state, int x, int y)
{
	//se transforma en función del nCols
	x = (x%(WIDTH/nCols))*nCols;
	y = (y%(HEIGHT/nCols))*nCols;

	bool need_redisplay = true;

	switch(button) {
	case GLUT_LEFT_BUTTON:
		printf(" LEFT ");
		if (state == GLUT_DOWN) {
			printf("DOWN\n");
			printf("PV (%d, %d) - AVE (%f, %f)\n", x, y, _escena.PVtoAVE_X(x), _escena.PVtoAVE_Y(y));
		}
		else if (state == GLUT_UP) {
			printf("UP\n");
			printf("PV (%d, %d) - AVE (%f, %f)\n", x, y, _escena.PVtoAVE_X(x), _escena.PVtoAVE_Y(y));
		}
		break;

	case GLUT_RIGHT_BUTTON:
		printf(" RIGHT ");
		if (state == GLUT_DOWN) {
			printf("DOWN\n");
			printf("PV (%d, %d) - AVE (%f, %f)\n", x, y, _escena.PVtoAVE_X(x), _escena.PVtoAVE_Y(y));
		}
		else  if (state == GLUT_UP) {
			printf("UP\n");
			printf("PV (%d, %d) - AVE (%f, %f)\n", x, y, _escena.PVtoAVE_X(x), _escena.PVtoAVE_Y(y));
		}
		break;

    default:
		need_redisplay = false;
		break;

  }//switch

  if (need_redisplay)
	glutPostRedisplay();

  fflush(stdout);              // Force output to stdout

}
Exemplo n.º 8
0
void RenderRayTracer::renderiza(Escena escena, Camara c) {

	RGB color;

	// float i,j;
	int i,j;

	float alfa = (c.fov*PI)/360.0;
	float dist = 0.5/tan(alfa);

	float incx = 1.0/(float)ancho*1.0;
	float incy = 1.0/(float)alto*1.0;

	float aspectratio = (float)ancho/(float)alto;
	float alfaw = alfa*aspectratio;
	float ancho_a = tan(alfaw)*dist;


	Punto centro = c.posicion + (c.look - c.posicion).normalizar()*dist;

	// Vector horizontal y vertical por los que se mueve 
	Punto horizontal = up^(c.look - c.posicion);
	horizontal.normalizar();
	Punto vertical = (c.look - c.posicion).normalizar()^horizontal;
	vertical.normalizar();

	Punto direccion = centro - horizontal*ancho_a - vertical*0.5;
	for(i=0;i<ancho;i++) {
		for(j=0;j<alto;j++) {
			// trazamos un rayo desde centro hasta x,y -> devuelve un color
			//
			// (direccion+horizontal*i*incx+vertical*j*incy - c.posicion).escribir();
			// 
			color = escena.trazarRayo(c.posicion,(direccion+horizontal*i*incx+vertical*j*incy - c.posicion).normalizar(),1,-1,1);
			raster.push_back(color);
		}
	}
	cerr << "Tiempo renderizado:  ";
};
Exemplo n.º 9
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.º 10
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();
}
Exemplo n.º 11
0
void display(void) {
    glClear(GL_COLOR_BUFFER_BIT);
    escena.draw();
    glFlush();
    glutSwapBuffers();
}