NOMBRE: CORREA ESPINOSA IVÁN SALVADOR
COMPUTACIÓN GRAFICA
#include (
#include (
#include (
#include
#include
float pos_camX = 0, pos_camY = 0, pos_camZ = -5;
int eye_camX = 0, eye_camY = 0, eye_camZ = 0;
int cube=1;
void InitGL ( GLvoid ) // Inicializamos parametros
{
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // se utilizara el fondo negro
glShadeModel (GL_SMOOTH);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable ( GL_COLOR_MATERIAL );
glClearDepth(1.0f); // Configurando Depth Buffer
glEnable(GL_DEPTH_TEST); // Habilitando Depth Testing
glDepthFunc(GL_LEQUAL); El tipo de test que se va a realizar
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
}
void display ( void ) // esta es la función donde se dibujara
{
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(pos_camX, pos_camY, pos_camZ);
glRotatef(eye_camX, 1.0, 0.0, 0.0);
glRotatef(eye_camY, 0.0, 1.0, 0.0);
glRotatef(eye_camZ, 0.0, 0.0, 1.0);
//SE CONTRUYE EL CUBO ORIGINAL
glColor3f(0.0,1.0,0.0);
glutSolidCube(cube);
glPopMatrix();
glutSwapBuffers ( );
}
void reshape ( int width , int height ) // Creamos funcion Reshape
{
if (height==0) // No se permite la division entre cero.
{
height=1;
}
glViewport(0,0,width,height);
glMatrixMode(GL_PROJECTION); // Seleccionamos Projection Matrix
glLoadIdentity();
glFrustum (-0.1, 0.1,-0.1, 0.1, 0.1, 50.0);// Se cambia la vista
glMatrixMode(GL_MODELVIEW); // Seleccionamos Modelview Matrix
glLoadIdentity();
}
void keyboard ( unsigned char key, int x, int y ) // crea la funcion del teclado
{
switch ( key ) {
case 'r': //Para rotar el cubito
case 'R':
glRotatef(45,0,0,1);//rota el cubo unos 45 grados
glutSolidCube(cube);
break;
case 'f': //para rotar el cubo en un solo punto
case 'F':
glTranslatef(1,0,0);//utiliza la funcion traslate para trasladarlo
glRotatef(45,0,0,1);//se rota nuevamente el cubo unos 45 grados
glutSolidCube(cube);
break;
case 't':
case 'T':
glTranslatef(2,0,0);
glutSolidCube(cube); break;
case 'e': //efectua la transformación de escalar
case 'E':
cube=2;
glutSolidCube(cube);
break;
case 'l':
case 'L':
break;
case 27: // sale del programa por default con la tecla ESC
exit ( 0 ); // Salir del ejecutable
break;
default: // otra funcion
break;
}
glutPostRedisplay();
}
int main ( int argc, char** argv ) // funcion principal
{
glutInit (&argc, argv); // Se inicializa la funcion
glutInitDisplayMode (GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); // Es el display
Mode (Clores RGB y alpha | Buffer Doble )
glutInitWindowSize (500, 500); // Nuevamente el tamaño de la ventana
glutInitWindowPosition (0, 0); //Posicionar la ventana
glutCreateWindow ("Cubo"); //Nombre de la ventana
InitGL (); // Los parámetros inciales
glutDisplayFunc ( display ); //dibujar la funcion
glutReshapeFunc ( reshape ); //Cambio de tamaño de la aplicacion glutKeyboardFunc ( keyboard ); //se habilita la interaccion del teclado
glutMainLoop ( ); // regresa ciclicamente
return 0;
}