lunes, 17 de septiembre de 2007

TAREA 4: "PUERCO ARAÑA"

Este es el código para hacer el puerco araña

#include

GLUquadricObj * qobj;

void colaDePuerco (void)
{
glPushMatrix();
glTranslatef(0, 0,0); // cilindro al punto de origen (0,0,0)
qobj = gluNewQuadric();
gluQuadricDrawStyle(qobj,GLU_LINE);
gluCylinder(qobj, 0.8, 0.8, 1.5, 50,10);
glPopMatrix();
}

void cabezaDePuerco (void)
{
glPushMatrix();
glTranslatef(0,0,0);
glutWireSphere(3,10,10);
glPopMatrix();
}

void ojosDePuerco (void)
{
glPushMatrix();
glTranslatef(0, 0,0); // cilindro al punto de origen (0,0,0)
qobj = gluNewQuadric();
gluQuadricDrawStyle(qobj,GLU_LINE);
gluCylinder(qobj, 0.8, 0.8, 0.5, 100,5);
glPopMatrix();
}

void trompaDePuerco (void)
{
glPushMatrix();
glTranslatef(0, 0,0); // cilindro al punto de origen (0,0,0)
qobj = gluNewQuadric();
gluQuadricDrawStyle(qobj,GLU_LINE);
gluCylinder(qobj, 0.5, 0.5, 1, 8,6);
glPopMatrix();
}

void orejaDePuerco (void)
{
glPushMatrix();
glTranslatef(0,0,0);
glRotatef(-90,1,0,0);
qobj = gluNewQuadric();
gluQuadricDrawStyle(qobj,GLU_LINE);
gluCylinder(qobj, 1, 0, 1.3, 5,5);
glPopMatrix();
}

void patapuerco (void)
{
glPushMatrix();
glTranslatef(0, 0,0); // cylinder at (0,0,1)
glRotatef(90,1,0,0);
qobj = gluNewQuadric();
gluQuadricDrawStyle(qobj,GLU_LINE);
gluCylinder(qobj, 1, 1, 1.5, 10,8);
glPopMatrix();
}

void Puerco (void)
{
glDepthFunc(GL_LEQUAL);
glEnable(GL_DEPTH_TEST);
glClearDepth(1.0);
glClearColor(1.0,1.0,1.0,0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(50.0,1.0,1.0,100.0);

glMatrixMode(GL_MODELVIEW);

//gluCylinder(qobj, baseRad, topRad, height, nSlices, nStacks); Dibuja el cilindro
/*glPushMatrix();
glTranslated(0, 0,0); // cylinder at (0,0,1)
glRotatef(90,1,0,0);
qobj = gluNewQuadric();
gluQuadricDrawStyle(qobj,GLU_LINE);
glColor3d(0.1,0.3,0.7);
gluCylinder(qobj, 0.3, 1.3, 5.4, 10,8);
glPopMatrix();*/

glPushMatrix();
glColor3d(0.1,0.3,0.7);
glTranslatef(0,0,0);
glRotatef(90,0,1,0);
glutWireSphere(4,8,8);

glPushMatrix();
glTranslatef(-2.5,-2,2);
patapuerco();
glPopMatrix();

glPushMatrix();
glTranslatef(-2.5,-2,-2);
patapuerco();
glPopMatrix();

glPushMatrix();
glTranslatef(2.5,-2,2);
patapuerco();
glPopMatrix();

glPushMatrix();
glTranslatef(2.5,-2,-2);
patapuerco();
glPopMatrix();

glPushMatrix();
glTranslatef(0,1,4);
cabezaDePuerco();

glPushMatrix();
glTranslatef(-1.4,2,0.5);
orejaDePuerco();
glPopMatrix();

glPushMatrix();
glTranslatef(1.4,2,0.5);
orejaDePuerco();
glPopMatrix();

glPushMatrix();
glTranslatef(0,0,2.8);
trompaDePuerco();
glPopMatrix();

glPushMatrix();
glTranslatef(1.2,1.2,1.9);
ojosDePuerco();
glPopMatrix();

glPushMatrix();
glTranslatef(-1.2,1.2,1.9);
ojosDePuerco();
glPopMatrix();
glPopMatrix();

glPushMatrix();
glTranslatef(0,0,-5.5);
colaDePuerco();
glPopMatrix();

glPopMatrix();

glRotatef(45,1,1,1);
glFlush();
}

int main(int argc,char *argv)
{
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA| GLUT_DEPTH );
glutInitWindowPosition(0,0);
glutInitWindowSize(600,600);
glutCreateWindow("Puerco Araña");
gluLookAt(0.0, 5.0, 20.0,0.0, 0.0, 0.0,0.0, 1.0, 0.0);
//Vista desde el punto 0,0,0. Con el 3er parámetro se acerca o se aleja la cámara
glutDisplayFunc(Puerco);
glutMainLoop();
return 0;
}

No hay comentarios: