#include <GL/glut.h>
#include <math.h>
#include < stdio.h>
#include < stdlib.h>
GLfloat anguloPiramideX=0.0f;
GLfloat anguloPiramideY=0.0f;
GLint ancho=400;
GLint alto=400;
int Perspectiva=0;
GLfloat anguloCamaraY = 0.0f;
GLfloat anguloCamaraX = 0.0f;
GLfloat anguloCamaraZ= 0.0f;
GLfloat anguloCamara2Z = 0.0f;
GLfloat posObjeto = -5.0f;
int lookAt=0;
int h=0;
GLfloat axisy = 0;
GLfloat axisx = 0;
GLfloat axisz = 0;
GLfloat axisyy = 1;
GLfloat axisxx = 1;
GLfloat axiszz = 1;
void reshape(int width, int height)
{
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if(Perspectiva)
gluPerspective(60.0f,(GLfloat)width/(GLfloat)height,1.0f,20.0f);
else
glOrtho(-15, 15, -15, 15, -15, 15);
glMatrixMode(GL_MODELVIEW);
}
void display(){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef( axisx, axisy, axisz);
glScalef( axisxx, axisyy, axiszz);
if (!lookAt){
//glTranslatef(0.0f, 0.0f, posObjeto); // zoom
// eje horizontal.
glRotatef(anguloCamaraY, 0.0f, 1.0f, 0.0f);
// eje vertical.
glRotatef(anguloCamaraX,1.0f,0.0f,0.0f);
} else {
gluLookAt(-5,10,5,0,0,0,1,12,4);
}
glColor3f(0.0f,1.0f,0.0f); //TRASERA
glBegin(GL_TRIANGLES);
glVertex3f(-1.0f,0.0f,-1.0f);
glVertex3f(1.0f,0.0f,-1.0f);
glVertex3f(0.0f,2.0f,0.0f);
glEnd();
glColor3f(1.0f,0.9f,0.0f); //FRONTAL
glBegin(GL_TRIANGLES);
glVertex3f(1.0f,0.0f,1.0f);
glVertex3f(-1.0f,0.0f,1.0f);
glVertex3f(0.0f,2.0f,0.0f);
glEnd();
glColor3f(0.0f,0.0f,1.0f); //LATERAL IZQ
glBegin(GL_TRIANGLES);
glVertex3f(-1.0f,0.0f,-1.0f);
glVertex3f(-1.0f,0.0f,1.0f);
glVertex3f(0.0f,2.0f,0.0f);
glEnd();
glColor3f(0.0f,1.0f,0.0f); //LATERAL DER
glBegin(GL_TRIANGLES);
glVertex3f(1.0f,0.0f,1.0f);
glVertex3f(1.0f,0.0f,-1.0f);
glVertex3f(0.0f,2.0f,0.0f);
glEnd();
glColor3f(1.0f,0.0f,0.0f);
glBegin(GL_QUADS);
glVertex3f(-1,-1, 1);
glVertex3f(1,-1, 1);
glVertex3f(1,-1, -1);
glVertex3f(-1,-1,-1);
glEnd();
glFlush();
}
void keyboard(unsigned char key, int x, int y){
switch(key) {
// ROTAR CAMARA LA DERECHA
case '1':
anguloCamaraY++;
printf("Angulo de rotacion de la camara en torno al eje Y: %i \n",((int)anguloCamaraY % 360));
display();
break;
// ROTAR CAMARA LA IZQUIERDA
case '2':
anguloCamaraY--;
printf("Angulo de rotacion de la camara en torno al eje Y: %i \n",((int)anguloCamaraY % 360));
display();
break;
// ROTAR CAMARA HACIA ARRIBA
case '3':
anguloCamaraX++;
printf("Angulo de rotacion de la camara en torno al eje X: %i \n",((int)anguloCamaraX % 360));
display();
break;
// ROTAR CAMARA HACIA ABAJO
case '4':
anguloCamaraX--;
printf("Angulo de rotacion de la camara en torno al eje X: %i \n",((int)anguloCamaraX % 360));
display();
break;
case '5':
posObjeto++;
display();
break;
case '6':
posObjeto--;
display();
break;
case '7':
if (lookAt==0){
lookAt=1;
}else{
lookAt=0;
}
display();
break;
case 'q':
axisx=axisx+0.1;
display();
break;
case 'w':
axisy=axisy+0.1;
display();
break;
case 'a':
axisxx=axisxx+0.1;
display();
break;
case 's':
axisyy=axisyy+0.1;
display();
break;
case 'e':
axisx=axisx-0.1;
display();
break;
case 'r':
axisy=axisy-0.1;
display();
break;
case 'd':
axisxx=axisxx-0.1;
display();
break;
case 'f':
axisyy=axisyy-0.1;
display();
break;
}
}
void init()
{
glClearColor(1,0,0,0);
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowPosition(50, 50);
glutInitWindowSize(500, 500);
glutCreateWindow("Hello OpenGL");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutMainLoop();
return 0;
}
No hay comentarios:
Publicar un comentario