//tronco
Push;
Cilindro (radio=2, largo=7);
Pop;
//cabeza
Push;
Translate(0,0,3.5);
Esfera (radio=2);
//trompa
Push;
Translatef(0,-0.5,1.75);
Cilindro (radio=0.5, largo=0.7);
Pop;
//orejas
Push;
Rotate(-90,0,1,0);
Rotate(-45,1,0,0);
Translate(0.0f,0.3f,2.0f);
Cono(radio=0.5,altura=1);
Pop:
Push;
Rotate(90,0,1,0);
Rotate(-45,1,0,0);
Translate(0.0f,0.3f,2.0f);
Cono(radio=0.5,altura=1);
Pop;
//ojos
Push;
Translate(-1,0.6,2);
Esfera(radio=0.5);
Pop:
Push;
Translate(1,0.6,2);
Esfera(radio=0.5);
Pop;
Pop;
//cola
Push;
Translate(0.0f,1.2f,-
Rotate(40,1,0,0);
Cilindro (radio= 0.2,largo=1);
Pop;
//Patas delanteras
Push;
Translate(-1.0f,-1.5f,0.0f);
Rotate(90,1,0,0);
Cilindro (Radio= 0.7,
Push;
Translatef(0.0f,0.0f,2.0f);
Cilindro (radio= 0.4,Largo=1);
Pop;
Pop;
Push;
Translate(1.0f,-1.5f,0.0f);
Rotate(90,1,0,0);
Cilindro (Radio= 0.7,
Push;
Translatef(0.0f,0.0f,2.0f);
Cilindro (radio= 0.4,Largo=1);
Pop;
Pop
//patas traseras
Push;
Translate(1.0f,-1.5f,-
Rotate(135,1,0,0);
Cilindro(radio= 0.7,largo=2.1213);
Push;
Translate(0.0f,-0.7f,2.5213f);
Rotate(-90,1,0,0);
Cilindror(radio= 0.4,largo=2.1142);
Pop;
Pop;
Push;
Translate(-1.0f,-1.5f,-
Rotate(135,1,0,0);
Cilindro(radio= 0.7,largo=2.1213);
Push;
Translate(0.0f,-0.7f,2.5213f);
Rotate(-90,1,0,0);
Cilindror(radio= 0.4,largo=2.1142);
Pop;
Pop;
Código en C++; //tiene funciones de teclado para mover y hacercar la imagen en 3d
#include "glut.h"
float angleX = 0.0f;
float angleY = 0.0f;
float angleZ = 0.0f;
float transZ = -10.0f;
int proOr=0;
float al,an,pro;
GLint venAncho=600;
GLint venAlto=600;
void puerco_araña();
void reshape(int width, int height);
void keyboard(unsigned char key, int x, int y);
int main(int argc, char **argv) {
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowPosition(20,20);
glutInitWindowSize( 600, 600);
glClearColor(0,0,0,0);
glEnable(GL_DEPTH_TEST);
glutCreateWindow("Puerco Araña");
glutDisplayFunc(puerco_araña);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutIdleFunc(puerco_araña);
glutMainLoop();
return 0;
}
void puerco_araña(void){
GLUquadricObj *qobj;
qobj = gluNewQuadric ();
gluQuadricDrawStyle(qobj,GLU_FILL);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
if(proOr==1){
glRotatef(90,0,1,0);
glTranslatef(0,0,15);
}
else {
glMatrixMode(GL_PROJECTION);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
glTranslatef(0.0f, 0.0f, transZ);
glRotatef(angleX, 1.0f, 0.0f, 0.0f);
glRotatef(angleY, 0.0f, 1.0f, 0.0f);
glRotatef(angleZ, 0.0f, 0.0f, 1.0f);
glPushMatrix();
//tronco
glPushMatrix();
glTranslatef(0,0,-5.5f);
glColor3f(0.6f,0.0f,0.0f);
gluCylinder(qobj, 2, 2,7, 20, 20);
glPopMatrix();
//cabeza
glPushMatrix();
glTranslatef(0,0,3.5f);
glColor3f(0.0f,0.6f,0.2f);
glutSolidSphere(2,20,20);
//trompa
glPushMatrix();
glColor3f(0.6f,0.0f,0.0f);
glTranslatef(0.0f,-0.5f,1.75f);
gluCylinder(qobj, 0.5,0.5,0.75, 20, 20);
glPopMatrix();
//orejas
glPushMatrix();
glColor3f(0.0f,0.0f,0.9f);
glRotatef(-90,0,1,0);
glRotatef(-45,1,0,0);
glTranslatef(0.0f,0.3f,2.0f);
glutSolidCone (0.5, 1, 20, 20);
glPopMatrix();
glPushMatrix();
glColor3f(0.0f,0.0f,0.9f);
glRotatef(90,0,1,0);
glRotatef(-45,1,0,0);
glTranslatef(0.0f,0.3f,2.0f);
glutSolidCone (0.5, 1, 20, 20);
glPopMatrix();
//ojos
glPushMatrix();
glTranslatef(-1,0.6,2);
glColor3f(0.0f,0.9f,0.0f);
glutSolidSphere(0.5f,20,20);
glPopMatrix();
glPushMatrix();
glTranslatef(1,0.6,2);
glColor3f(0.0f,0.9f,0.0f);
glutSolidSphere(0.5f,20,20);
glPopMatrix();
glPopMatrix();
//cola
glPushMatrix();
glColor3f(0.6f,0.2f,0.9f);
glTranslatef(0.0f,1.2f,-6.2f);
glRotatef(40,1,0,0);
gluCylinder(qobj, 0.2,0.2,1,20,20);
glPopMatrix();
//patas delanteras
glPushMatrix();
glColor3f(0.6f,0.9f,0.2f);
glTranslatef(-1.0f,-1.5f,0.0f);
glRotatef(90,1,0,0);
gluCylinder(qobj, 0.7,0.7,2,20,20);
glPushMatrix();
glColor3f(0.0f,0.9f,0.9f);
glTranslatef(0.0f,0.0f,2.0f);
gluCylinder(qobj, 0.4,0.4,1,20,20);
glPopMatrix();
glPopMatrix();
glPushMatrix();
glColor3f(0.6f,0.9f,0.2f);
glTranslatef(1.0f,-1.5f,0.0f);
glRotatef(90,1,0,0);
gluCylinder(qobj, 0.7,0.7,2,20,20);
glPushMatrix();
glColor3f(0.0f,0.9f,0.9f);
glTranslatef(0.0f,0.0f,2.0f);
gluCylinder(qobj, 0.4,0.4,1,20,20);
glPopMatrix();
glPopMatrix();
//patas traseras
glPushMatrix();
glColor3f(0.6f,0.9f,0.2f);
glTranslatef(1.0f,-1.5f,-4.0f);
glRotatef(135,1,0,0);
gluCylinder(qobj, 0.7,0.7,2.1213f,20,20);
glPushMatrix();
glColor3f(0.0f,0.1f,0.9f);
glTranslatef(0.0f,-0.7f,2.5213f);
glRotatef(-90,1,0,0);
gluCylinder(qobj, 0.4,0.4,2.1142,20,20);
glPopMatrix();
glPopMatrix();
glPushMatrix();
glColor3f(0.6f,0.9f,0.2f);
glTranslatef(-1.0f,-1.5f,-4.0f);
glRotatef(135,1,0,0);
gluCylinder(qobj, 0.7,0.7,2.1213f,20,20);
glPushMatrix();
glColor3f(0.0f,0.1f,0.9f);
glTranslatef(0.0f,-0.7f,2.5213f);
glRotatef(-90,1,0,0);
gluCylinder(qobj, 0.4,0.4,2.1142,20,20);
glPopMatrix();
glPopMatrix();
glPopMatrix();
glutSwapBuffers();
}
void reshape(int width, int height){
glViewport(0, 0, width, height);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
if(proOr!=2)
glOrtho(-20, 20, -20, 20, -50, 50);
if(proOr==2)
gluPerspective(90, (GLfloat) width/(GLfloat) height,2.0, 70.0);
glMatrixMode (GL_MODELVIEW);
venAncho = width;
venAlto = height;
}
void keyboard(unsigned char key, int x, int y){
switch(key)
{
case 27:
exit(0);
case 'w':
angleX += 1.0f;
break;
case 'W':
angleX -= 1.0f;
break;
case 's':
angleZ += 1.0f;
break;
case 'S':
angleZ -= 1.0f;
break;
case 'a':
angleY += 1.0f;
break;
case 'A':
angleY -= 1.0f;
break;
case 'z':
transZ += 0.1f;
break;
case 'Z':
transZ -= 0.1f;
break;
case '1':
proOr=1;
break;
case '2':
proOr=0;
break;
case '3':
proOr=2;
break;
default:
break;
}
}
No hay comentarios:
Publicar un comentario