1.-Escribe un programa en el cual :
- Se dibuje un cuadrado:
-Utilizando llamadas al cuadrado y aplicando rotaciones y traslaciones dibuje un cubo
-Rotar el cubo sobre el eje (1,1,1) en -45 °
-A partir del cubo y transformándolo construya un humanoide
Código para construir un cubo:
void cubo(void) //construcción del cubo , cara por cara
{
glBegin(GL_POLYGON);
glVertex3f(0.8,-0.8,0.8);
glVertex3f(0.8,0.8,0.8);
glVertex3f(-0.8,0.8,0.8);
glVertex3f(-0.8,-0.8,0.8);
glEnd();
glBegin(GL_POLYGON);
glVertex3f(-0.8,-0.8,-0.8);
glVertex3f(-0.8,0.8,-0.8);
glVertex3f( 0.8,0.8,-0.8);
glVertex3f(0.8,-0.8,-0.8);
glEnd();
glBegin(GL_POLYGON);
glVertex3f(-0.8,-0.8,0.8);
glVertex3f(-0.8,0.8,0.8);
glVertex3f(-0.8,0.8,-0.8);
glVertex3f(-0.8,-0.8,-0.8);
glEnd();
glBegin(GL_POLYGON);
glVertex3f(0.8,0.8,-0.8);
glVertex3f(0.8,0.8,0.8);
glVertex3f(0.8,-0.8,0.8);
glVertex3f( 0.8,-0.8,-0.8);
glEnd();
glBegin(GL_POLYGON);
glVertex3f( 0.8,0.8,-0.8);
glVertex3f(-0.8,0.8,-0.8);
glVertex3f(-0.8,0.8,0.8);
glVertex3f(0.8,0.8,0.8);
glEnd();
glBegin(GL_POLYGON);
glVertex3f(0.8,-0.8,0.8);
glVertex3f(0.8,-0.8,-0.8);
glVertex3f(-0.8,-0.8,-0.8);
glVertex3f(-0.8,-0.8,0.8);
glEnd();
}
Código para rotar el cubo sobre el eje (1,1,1) en -45°:
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glRotatef(-45,1.0f,1.0f,1.0f);
cubo();
glutSwapBuffers();
glFlush ();
}
Código para construir el humanoide, utilizando la función cubo:
//construcción de humanoide :
glPushMatrix();// caja central
glScalef(1.2,0.8,0.5);
cubo();
glPushMatrix();//segunda caja central
glScalef(1.2,0.2,0.5);
cubo();
glPopMatrix();
glPushMatrix(); //cabeza
glTranslatef(0.0,0.8,0.0);
glScalef(0.6,0.9,0.8);
cubo();
glPopMatrix();
glPushMatrix(); //brazo der. parte1
glTranslatef(0.8,0.4,0.0);
glScalef(0.7,0.2,0.5);
cubo();
glPushMatrix(); //brazo der. parte 2
glTranslatef(1.0,0.0,0.0);
glScalef(1.0,1.5 ,0.5);
cubo();
glPushMatrix();
glTranslatef(0.8,0.0,0.0);
glScalef(0.8,0.6,0.5);
cubo();
glPopMatrix();
glPopMatrix();
glPopMatrix();
glPushMatrix();//brazo izq. parte1
glTranslatef(-0.8,0.4,0.0);
glScalef(0.7,0.2,0.5);
cubo();
glPushMatrix();////brazo der. parte2
glTranslatef(-1.0,0.0,0.0);
glScalef(1.0,1.5,0.5);
cubo();
glPushMatrix();
glTranslatef(-0.8,0.0,0.0);
glScalef( 0.8,0.6,0.5);
cubo();
glPopMatrix();
glPopMatrix();
glPopMatrix();
glPushMatrix();//pie derecho parte 1
glTranslatef(0.35,-1.2,0.0);
glScalef(0.3,0.4,0.5);
cubo();
glPushMatrix();
glTranslatef(0.0,-1.0,0.0); //pie derecho parte 2
glScalef(1.2,1.0,0.5);
cubo();
glPushMatrix();
glTranslatef(0.5,-0.6,0.0); //pie derecho parte 3
glScalef(1.2,0.4,0.5);
cubo();
glPopMatrix();
glPopMatrix();
glPopMatrix();
glPushMatrix();//pie izq parte 1
glTranslatef(-0.35,-1.2,0.0);
glScalef(0.3,0.4,0.5);
cubo();
glPushMatrix();
glTranslatef(0.0,-1.0,0.0); //pie izq parte 2
glScalef(1.2,1.0,0.5);
cubo();
glPushMatrix();
glTranslatef(- 0.5,-0.6,0.0); //pie izq parte 3
glScalef(1.2,0.4,0.5);
cubo();
glPopMatrix();
glPopMatrix();
glPopMatrix();
glPopMatrix(); //fin del humanoide
No hay comentarios:
Publicar un comentario