#include <GL/glut.h>
GLfloat anguloCuboX = 0.0f;
GLfloat anguloCuboY = 0.0f;
GLfloat anguloEsfera = 0.0f;
GLfloat TrasEsferax= 3.0f;
GLfloat TrasEsferay= 0.0f;
GLfloat TrasEsferaz= -5.0f;
GLint ancho=400;
GLint alto=400;
int hazPerspectiva = 0;
void reshape(int width, int height)
{
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if(hazPerspectiva)
gluPerspective(60.0f, (GLfloat)width/(GLfloat)height, 1.0f, 20.0f);
else
glOrtho(-4,4, -4, 4, 1, 10);
glMatrixMode(GL_MODELVIEW);
ancho = width;
alto = height;
}
void drawCube(void)
{
glColor3f(0.0f, 0.0f, 0.5f);
glBegin(GL_QUADS);
glVertex3f( 4.0f,-4.0f, -4.0f);
glVertex3f( 4.0f,-4.0f, 4.0f);
glVertex3f(-4.0f,-4.0f, 4.0f);
glVertex3f(-4.0f,-4.0f, -4.0f);
glEnd();
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0f, 0.0f, -5.0f);
glRotatef(5, 1.0f, 0.0f, 0.0f);
glRotatef(5, 0.0f, 1.0f, 0.0f);
drawCube();
glLoadIdentity();
glTranslatef(TrasEsferax,TrasEsferay,TrasEsferaz);
glColor3f(0.0f, 1.0f, 0.0f);
glutWireSphere(0.5f, 8, 8);
glFlush();
glutSwapBuffers();
}
void init()
{
glClearColor(0,0,0,0);
glEnable(GL_DEPTH_TEST);
ancho = 400;
alto = 400;
}
void idle()
{
display();
}
void keyboard(unsigned char key, int x, int y)
{
switch(key)
{
case 'p':
case 'P':
hazPerspectiva=1;
reshape(ancho,alto);
break;
case 'o':
case 'O':
hazPerspectiva=0;
reshape(ancho,alto);
break;
case 'j':
case 'J':
TrasEsferax-=1.0;
break;
case 'l':
case 'L':
TrasEsferax+=1.0;
break;
case 'i':
case 'I':
TrasEsferay+=1.0;
break;
case 'k':
case 'K':
TrasEsferay-=1.0;
break;
case 'u':
case 'U':
TrasEsferaz+=0.5;
break;
case 'y':
case 'Y':
TrasEsferaz-=0.5;
break;
case 27:
// exit(0);
break;
}
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowPosition(100, 100);
glutInitWindowSize(ancho, alto);
glutCreateWindow("Piso y pelota");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutIdleFunc(idle);
glutKeyboardFunc(keyboard);
glutMainLoop();
return 0;
}
Corrida
No hay comentarios:
Publicar un comentario