Código:
#include <windows.h>
#include <C:\GLUT\include\GL\glut.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
int angx = 0, angy = 0; // Con estas se esta rotando sobre el eje x y sobre el eje y
GLUquadricObj *quadric;
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); // Aqui solo se le limpia el buffer de pixeles, ahora tambien se debe de hacer el buffer de profundidad que es siguiente
glColor3f( 0, 1, 0);
glPushMatrix();
glTranslatef( 0, 0.5, -4);
glRotatef( angx, 1, 0, 0);
glRotatef( angy, 0, 1, 0);
// Cabeza
glPushMatrix();
glTranslatef( 0, 2.1, 0);
glScalef( 1, 1.2, 1 );
glutSolidSphere( 0.6, 28, 28 );
glPopMatrix();
// Cuerpo
glPushMatrix();
glTranslatef( 0, 0.2, 0);
glScalef( 1.2, 2.3, 0.8 );
glutSolidSphere( 0.6, 28, 28 );
glPopMatrix();
// Hombro derecho
glPushMatrix();
glTranslatef( 0.55, 1.2, 0);
glutSolidSphere( 0.21, 28, 28 );
glPopMatrix();
// Brazo derecho, vista usuario
glPushMatrix();
glTranslatef( 0.75, 0.73, 0);
glRotatef( -75, 0, 0, 1 );
glScalef( 4, 0.7, 0.7 );
glutSolidCube( 0.28 );
glPopMatrix();
// Union con antebrazo derecho
glPushMatrix();
glTranslatef( 0.86, 0.32, 0);
glutSolidSphere( 0.21, 28, 28 );
glPopMatrix();
// Antebrazo derecho
glPushMatrix();
glTranslatef( 0.86, 0.0, 0);
glScalef( 0.65, 2.8, 0.65 );
glutSolidCube( 0.28 );
glPopMatrix();
// Mano derecha
glPushMatrix();
glTranslatef( 0.86, -0.38, 0);
glScalef( 1, 2, 1 );
glutSolidSphere( 0.15, 28, 28 );
glPopMatrix();
// Hombro izquierdo ///////////////////////////
glPushMatrix();
glTranslatef( -0.55, 1.2, 0);
glutSolidSphere( 0.21, 28, 28 );
glPopMatrix();
// Brazo izquierdo, vista usuario
glPushMatrix();
glTranslatef( -0.75, 0.73, 0);
glRotatef( 75, 0, 0, 1 );
glScalef( 4, 0.7, 0.7 );
glutSolidCube( 0.28 );
glPopMatrix();
// Union con antebrazo izquierdo
glPushMatrix();
glTranslatef( -0.86, 0.32, 0);
glutSolidSphere( 0.21, 28, 28 );
glPopMatrix();
// Antebrazo izquierdo
glPushMatrix();
glTranslatef( -0.86, 0.0, 0);
glScalef( 0.65, 2.8, 0.65 );
glutSolidCube( 0.28 );
glPopMatrix();
// Mano izquierda
glPushMatrix();
glTranslatef( -0.86, -0.38, 0);
glScalef( 1, 2, 1 );
glutSolidSphere( 0.15, 28, 28 );
glPopMatrix();
// Pierna izquierda /////////////////////////////
glPushMatrix();
glTranslatef( -0.45, -1, 0);
glutSolidSphere( 0.26, 28, 28 );
glPopMatrix();
// Muslo izquierdo
glPushMatrix();
glTranslatef( -0.56, -1.6, 0);
glRotatef( -6, 0, 0, 1);
glScalef( 0.9, 3.2, 0.9);
glutSolidCube( 0.32 );
glPopMatrix();
// Rodilla
glPushMatrix();
glTranslatef( -0.62, -2.2, 0);
glutSolidSphere( 0.23, 28, 28 );
glPopMatrix();
// Pantorrilla izquierda
glPushMatrix();
glTranslatef( -0.62, -2.6, 0);
glScalef( 0.9, 3, 0.9);
glutSolidCube( 0.32 );
glPopMatrix();
// Pie izquierdo
glPushMatrix();
glTranslatef( -0.62, -3.35, 0);
glRotatef( 90, 0, 1, 0 );
glRotatef( -90, 1, 0, 0 );
glutSolidCone( 0.32, 0.6, 28, 28 );
glPopMatrix();
// Pierna derecha /////////////////////////////
glPushMatrix();
glTranslatef( 0.45, -1, 0);
glutSolidSphere( 0.26, 28, 28 );
glPopMatrix();
// Muslo derecho
glPushMatrix();
glTranslatef( 0.56, -1.6, 0);
glRotatef( 6, 0, 0, 1);
glScalef( 0.9, 3.2, 0.9);
glutSolidCube( 0.32 );
glPopMatrix();
// Rodilla derecha
glPushMatrix();
glTranslatef( 0.62, -2.2, 0);
glutSolidSphere( 0.23, 28, 28 );
glPopMatrix();
// Pantorrilla derecha
glPushMatrix();
glTranslatef( 0.62, -2.6, 0);
glScalef( 0.9, 3, 0.9);
glutSolidCube( 0.32 );
glPopMatrix();
// Pie derecho
glPushMatrix();
glTranslatef( 0.62, -3.35, 0);
glRotatef( 90, 0, 1, 0 );
glRotatef( -90, 1, 0, 0 );
glutSolidCone( 0.32, 0.6, 28, 28 );
glPopMatrix();
glPopMatrix();
glFlush();
}
void setOrtho( void )
{
glOrtho( -2, 2, -4, 4, -2, 100);
}
void proy( unsigned char key, int x, int y)
{
glMatrixMode(GL_PROJECTION); // Se apila una proyección, indica que se va a tener un tipo de proyección y abajo se indica en el caso p y o
glLoadIdentity();
switch (key){
case 27:
exit(0);
case 'p':
gluPerspective( 90, 0.5, 0.1, 100); // zNear es como desde donde se coloca la camara o mira de la persona, mientras que zFar es hasta donde verá y por tanto cuantos objetos se veran
break;
case 'o':
setOrtho();
break;
}
/* 2.- Se agrega una matriz para la presentacion de un modelo */
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glutPostRedisplay();
}
void girar(int key, int x, int y)
{
switch(key){
case GLUT_KEY_UP:
angx=angx+3;
break;
case GLUT_KEY_DOWN:
angx=angx-3;
break;
case GLUT_KEY_LEFT:
angy=angy+3;
break;
case GLUT_KEY_RIGHT:
angy=angy-3;
break;
}
glutPostRedisplay();
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB|GLUT_DEPTH|GLUT_STENCIL);
glutInitWindowSize( 400, 800);
glutInitWindowPosition( 10, 10);
glutCreateWindow ("Humanoide");
/* 1.- La luz default es una luz direccional desde la camara */
glEnable(GL_DEPTH_TEST); // Habilita un test de profundidad
glEnable(GL_LIGHTING); // Habilitar iluminacion
glEnable(GL_LIGHT0);
glutDisplayFunc(display);
glutKeyboardFunc(proy);
glutSpecialFunc(girar);
glutMainLoop();
return 0;
}

No hay comentarios.:
Publicar un comentario