Aqui presento el código dejado en el laboratorio para el desarrollo de la escena de cuatro humanoides con los parámetros que nos dio el Ingeniero. Este es el DESARROLLO de la práctica, el reporte de la misma y el "previo" de la práctica 4 se entregan en una entrada diferente que es la creación de la mano.
/*humanoide_escnaF.c es un programa realizado por Adrian Araya y Antonio Davalos para el laboratorio de computación gráfica*/
#include
#include
static int posicionx = 0;
static int posiciony = 0;
static int posicionz = 0;
/*cabeza*/
static int cuelloy = 0;
/*brazo derecho*/
static int hombroderx = 0;
static int hombrodery = 0;
static int hombroderz = 0;
static int cododerz = 0;
/*brazo izquierdo*/
static int hombroizqx = 0;
static int hombroizqy = 0;
static int hombroizqz = 0;
static int codoizqz = 90;
/*pierna derecha*/
static int musloderx = 0;
static int muslodery = 0;
static int musloderz = 0;
static int rodilladerx = 90;
static int piedery = 0;
/*pierna izquierda*/
static int musloizqx = 0;
static int musloizqy = 0;
static int musloizqz = 0;
static int rodillaizqx = 0;
static int pieizqy = 0;
void init(void)
{
glClearColor (0.0, 0.0, 0.0, 0.0);
glShadeModel (GL_FLAT);
}
void cuborelleno(void)
{
glBegin(GL_QUADS);
glVertex3f(0.5,0.5,0.5);//v1
glVertex3f(-0.5,0.5,0.5);//v2
glVertex3f(-0.5,-0.5,0.5);//v3
glVertex3f(0.5,-0.5,0.5);//v4
glEnd();
glBegin(GL_QUADS);
glVertex3f(-0.5,0.5,-0.5);//v5
glVertex3f( 0.5,0.5,-0.5);//v6
glVertex3f(0.5,-0.5,-0.5);//v7
glVertex3f(-0.5,-0.5,-0.5);//v8
glEnd();
glBegin(GL_QUADS);
glVertex3f(-0.5,0.5,0.5);//v2
glVertex3f(-0.5,0.5,-0.5);//v5
glVertex3f(-0.5,-0.5,-0.5);//v8
glVertex3f(-0.5,-0.5,0.5);//v3
glEnd();
glBegin(GL_QUADS);
glVertex3f(0.5,0.5,0.5);//v1
glVertex3f(0.5,-0.5,0.5);//v4
glVertex3f( 0.5,-0.5,-0.5);//v7
glVertex3f(0.5,0.5,-0.5);//v6
glEnd();
glBegin(GL_QUADS);
glVertex3f(-0.5,0.5,-0.5);//v5
glVertex3f(-0.5,0.5,0.5);//v2
glVertex3f(0.5,0.5,0.5);//v1
glVertex3f( 0.5,0.5,-0.5);//v6
glEnd();
glBegin(GL_QUADS);
glVertex3f(0.5,-0.5,-0.5);//v7
glVertex3f(-0.5,-0.5,-0.5);//v8
glVertex3f(-0.5,-0.5,0.5);//v3
glVertex3f(0.5,-0.5,0.5);//v4
glEnd();
}
void cubohueco(void)
{
glBegin(GL_LINE_LOOP);
glVertex3f(0.5,0.5,0.5);//v1
glVertex3f(-0.5,0.5,0.5);//v2
glVertex3f(-0.5,-0.5,0.5);//v3
glVertex3f(0.5,-0.5,0.5);//v4
glEnd();
glBegin(GL_LINE_LOOP);
glVertex3f(-0.5,0.5,-0.5);//v5
glVertex3f( 0.5,0.5,-0.5);//v6
glVertex3f(0.5,-0.5,-0.5);//v7
glVertex3f(-0.5,-0.5,-0.5);//v8
glEnd();
glBegin(GL_LINE_LOOP);
glVertex3f(-0.5,0.5,0.5);//v2
glVertex3f(-0.5,0.5,-0.5);//v5
glVertex3f(-0.5,-0.5,-0.5);//v8
glVertex3f(-0.5,-0.5,0.5);//v3
glEnd();
glBegin(GL_LINE_LOOP);
glVertex3f(0.5,0.5,0.5);//v1
glVertex3f(0.5,-0.5,0.5);//v4
glVertex3f( 0.5,-0.5,-0.5);//v7
glVertex3f(0.5,0.5,-0.5);//v6
glEnd();
glBegin(GL_LINE_LOOP);
glVertex3f(-0.5,0.5,-0.5);//v5
glVertex3f(-0.5,0.5,0.5);//v2
glVertex3f(0.5,0.5,0.5);//v1
glVertex3f( 0.5,0.5,-0.5);//v6
glEnd();
glBegin(GL_LINE_LOOP);
glVertex3f(0.5,-0.5,-0.5);//v7
glVertex3f(-0.5,-0.5,-0.5);//v8
glVertex3f(-0.5,-0.5,0.5);//v3
glVertex3f(0.5,-0.5,0.5);//v4
glEnd();
}
void torso (int posx,int posy,int posz)
{
glTranslatef(0.0,1.5,0.0);
glScalef (0.5, 0.5, 0.5);
glRotatef(posx,1.0,0.0,0.0);
glRotatef(posy,0.0,1.0,0.0);
glRotatef(posz,0.0,0.0,1.0);
glTranslatef(0.0,0.0,0.0);
glPushMatrix();
glScalef (2.0, 3.0, 1.0);
cubohueco();
glPopMatrix();
}
void cara (int cuey)
{
glPushMatrix();
glRotatef(cuey,0.0,1.0,0.0);
glTranslatef(0.0,2.0,0.0);
cubohueco();
glPopMatrix();
}
void brazoderecho (int hombrodx,int hombrody,int hombrodz,int cododz)
{
/*brazo derecho*/
glPushMatrix();
glTranslatef(1.0,1.0,0.0);
glRotatef(hombrodx,1.0,0.0,0.0);
glRotatef(hombrody,0.0,1.0,0.0);
glRotatef(hombrodz,0.0,0.0,1.0);
glTranslatef(1.0,0.25,0.0);
glPushMatrix();
glScalef(2.0,0.5,1.0);
cubohueco();
glPopMatrix();
/*antebrazo derecho*/
glTranslatef(1.0,0.0,0.0);
glRotatef(cododz,0.0,0.0,1.0);
glTranslatef(1.0,0.0,0.0);
glPushMatrix();
glScalef(2.0,1.0,1.0);
cubohueco();
glPopMatrix();
/*mano derecha*/
glTranslatef(1.25,0.0,0.0);
glPushMatrix();
glScalef(0.5,0.5,1.0);
cubohueco();
glPopMatrix();
glPopMatrix();/*brazo derecho completo*/
}
void brazoizquierdo (int hombroix,int hombroiy,int hombroiz,int codoiz)
{
/*brazo izquierdo*/
glPushMatrix();
glTranslatef(-1.0,1.0,0.0);
glRotatef(hombroix,1.0,0.0,0.0);
glRotatef(hombroiy,0.0,1.0,0.0);
glRotatef(hombroiz,0.0,0.0,1.0);
glTranslatef(-1.0,0.25,0.0);
glPushMatrix();
glScalef(2.0,0.5,1.0);
cubohueco();
glPopMatrix();
/*antebrazo izquierdo*/
glTranslatef(-1.0,0.0,0.0);
glRotatef(codoiz,0.0,0.0,1.0);
glTranslatef(-1.0,0.0,0.0);
glPushMatrix();
glScalef(2.0,1.0,1.0);
cubohueco();
glPopMatrix();
/*mano derecha*/
glTranslatef(-1.25,0.0,0.0);
glPushMatrix();
glScalef(0.5,0.5,1.0);
cubohueco();
glPopMatrix();
glPopMatrix();/*brazo izquierdo completo*/
}
void piernaderecha(int muslodx,int muslody,int muslodz,int rodilladx,int piedy)
{
/*muslo derecho*/
glPushMatrix();
glTranslatef(0.665,-1.5,0.0);
glRotatef(muslodx,1.0,0.0,0.0);
glRotatef(muslody,0.0,1.0,0.0);
glRotatef(muslodz,0.0,0.0,1.0);
glTranslatef(0.0,-1.2,0.0);
glPushMatrix();
glScalef(0.68,2.4,1.0);
cubohueco();
glPopMatrix();
/*pantorrilla derecha*/
glTranslatef(0.0,-1.2,0.0);
glRotatef(rodilladx,1.0,0.0,0.0);
glTranslatef(0.0,-1.2,0.0);
glPushMatrix();
glScalef(1.0,2.4,1.0);
cubohueco();
glPopMatrix();
/*pie derecho*/
glTranslatef(0.0,0.-1.25,0.0);
glRotatef(piedy,0.0,1.0,0.0);
glTranslatef(0.25,-0.35,0.0);
glPushMatrix();
glScalef(1.5,0.75,1.0);
cubohueco();
glPopMatrix();
glPopMatrix();/*pie derecho completo*/
}
void piernaizquierda(int musloix,int musloiy,int musloiz,int rodillaix,int pieiy)
{
/*muslo izquierdo*/
glPushMatrix();
glTranslatef(-0.665,-1.5,0.0);
glRotatef(musloix,1.0,0.0,0.0);
glRotatef(musloiy,0.0,1.0,0.0);
glRotatef(musloiz,0.0,0.0,1.0);
glTranslatef(0.0,-1.2,0.0);
glPushMatrix();
glScalef(0.68,2.4,1.0);
cubohueco();
glPopMatrix();
/*pantorrilla izquierda*/
glTranslatef(0.0,-1.2,0.0);
glRotatef(rodillaix,1.0,0.0,0.0);
glTranslatef(0.0,-1.2,0.0);
glPushMatrix();
glScalef(1.0,2.4,1.0);
cubohueco();
glPopMatrix();
/*pie izquierdo*/
glTranslatef(0.0,0.-1.25,0.0);
glRotatef(pieiy,0.0,1.0,0.0);
glTranslatef(-0.25,-0.35,0.0);
glPushMatrix();
glScalef(1.5,0.75,1.0);
cubohueco();
glPopMatrix();
glPopMatrix();/*pierna izquierda completo*/
}
void humanoide (int px,int py,int pz,int cy,int hdx,int hdy,int hdz,int cdz,int hix,int hiy,int hiz,int ciz,
int mdx,int mdy,int mdz,int rdx,int pdy,int mix,int miy,int miz,int rix,int piy)
{
torso(px,py,pz);
cara(cy);
brazoderecho(hdx,hdy,hdz,cdz);
brazoizquierdo(hix,hiy,hiz,ciz);
piernaderecha(mdx,mdy,mdz,rdx,pdy);
piernaizquierda(mix,miy,miz,rix,piy);
}
void display(void)
{
glClear (GL_COLOR_BUFFER_BIT);
glColor3f (1.0, 1.0, 1.0);
glLoadIdentity ();
//Angulo de vision de los humanoides
gluLookAt (5.0,0.0,10.0,0.0, 0.0, 2.0, 0.0, 1.0, 0.0);
//despliegue de los humanoides, cada ocasión se realiza un push para guardar a la
//matriz original, se crea el humanoide en cuestion y se realiza un pop para obtener la
//matriz original
glPushMatrix();
glScalef(0.5,0.5,0.5);
glRotatef(-45,0.0,1.0,0.0);
glTranslatef(5.0,0.0,2.0);
glColor3f (0.0, 0.0, 1.0);
humanoide(posicionx,posiciony,posicionz,cuelloy,
hombroderx,hombrodery,hombroderz,cododerz,
hombroizqx,hombroizqy,hombroizqz,codoizqz,
musloderx,muslodery,musloderz,rodilladerx,piedery,
musloizqx,musloizqy,musloizqz,rodillaizqx,pieizqy);
glPopMatrix();
/*humanoide2*/
glPushMatrix();
glTranslatef(1.0,1.0,1.0);
glRotatef(15,1.0,0.0,0.0);
glScalef(0.5,-1.5,0.8);
glColor3f (0.0, 1.0, 0.0);
humanoide(posicionx,posiciony,posicionz,cuelloy,
hombroderx,hombrodery,hombroderz,cododerz,
hombroizqx,hombroizqy,hombroizqz,codoizqz,
musloderx,muslodery,musloderz,rodilladerx,piedery,
musloizqx,musloizqy,musloizqz,rodillaizqx,pieizqy);
glPopMatrix();
/*humanoide3*/
glPushMatrix();
glRotatef(20,0.0,1.0,0.0);
glTranslatef(-2.0,-1.0,-3.0);
glColor3f (1.0, 0.0, 0.0);
humanoide(posicionx,posiciony,posicionz,cuelloy,
hombroderx,hombrodery,hombroderz,cododerz,
hombroizqx,hombroizqy,hombroizqz,codoizqz,
musloderx,muslodery,musloderz,rodilladerx,piedery,
musloizqx,musloizqy,musloizqz,rodillaizqx,pieizqy);
glPopMatrix();
/*humanoide4*/
glPushMatrix();
glScalef(2.0,0.5,1.0);
glRotatef(45,0.0,0.0,1.0);
glTranslatef(-3.0,1.0,2.0);
glColor3f (1.0, 0.0, 1.0);
humanoide(posicionx,posiciony,posicionz,cuelloy,
hombroderx,hombrodery,hombroderz,cododerz,
hombroizqx,hombroizqy,hombroizqz,codoizqz,
musloderx,muslodery,musloderz,rodilladerx,piedery,
musloizqx,musloizqy,musloizqz,rodillaizqx,pieizqy);
glPopMatrix();
glFlush ();
}
void reshape (int w, int h)
{
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glFrustum (-1.0, 1.0, -1.0, 1.0, 1.5, 20.0);
glMatrixMode (GL_MODELVIEW);
}
/* ARGSUSED1 */
void keyboard(unsigned char key, int x, int y)
{
switch (key) {
case 27:
exit(0);
break;
}
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (800, 800);
glutInitWindowPosition (90, 90);
glutCreateWindow (argv[0]);
init ();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutMainLoop();
return 0;
}

No hay comentarios.:
Publicar un comentario