martes, 27 de marzo de 2007

Reporte Práctica 4 Laboratorio

Anexo el código de las manos

/** mano_reflejo.c
Este programa despliega una mano formado unicamente por cubos de diferetes tamaños, todos creados a apartir
de un cubo base y aplicando transformadas de traslacion, escalamiento y rotacion, para rotar las manos apretar q,w y e*/
#include
#include

static int posicionx = 0;
static int posiciony = 0;
static int posicionz = 0;
/*falanges dedo chiquito*/
static int chiquito1 = 0;
static int chiquito2 = 0;
static int chiquito3 = 0;
/*falanges dedo anular*/
static int anular1 = 0;
static int anular2 = 0;
static int anular3 = 0;
/*falanges dedo medio*/
static int medio1 = 0;
static int medio2 = 0;
static int medio3 = 0;
/*falanges dedo indice*/
static int indice1 = 0;
static int indice2 = 0;
static int indice3 = 0;
/*falanges dedo gordo*/
static int gordo1a = 0;
static int gordo1b = 0;
static int gordo2 = 0;
static int gordo3 = 0;

GLUquadricObj *sphereObj;

void init(void)
{
glClearColor (0.0, 0.0, 0.0, 0.0);
glShadeModel (GL_FLAT);
}
void actualizaArticulaciones(void)
{
int i;
for (i=0;i<20000000;i++)
{
}
chiquito1 = (chiquito1 +5)%90;
chiquito2 = (chiquito2 + 5)%90;
chiquito3 = (chiquito3 + 5)%90;
/*falanges dedo anular*/
anular1 = (anular1 + 5)%90;
anular2 = (anular2 + 5)%90;
anular3 = (anular3 + 5)%90;
/*falanges dedo medio*/
medio1 = (medio1 + 5)%90;
medio2 = (medio2 + 5)%90;
medio3 = (medio3 + 5)%90;
/*falanges dedo indice*/
indice1 = (indice1 + 5)%90;
indice2 = (indice2 + 5)%90;
indice3 = (indice3 + 5)%90;
/*falanges dedo gordo*/
gordo1a = -45;
gordo1b = (gordo1b + 5)%90;
gordo2 = (gordo2 + 5)%90;
gordo3 = (gordo3 + 5)%90;

}

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 muneca (int px, int py, int pz)
{
/*muñeca y palma*/
glTranslatef(0.0,0.0,0.0);
glRotatef(px,1.0,0.0,0.0);
glRotatef(py,0.0,1.0,0.0);
glRotatef(pz,0.0,0.0,1.0);
glTranslatef(0.0,0.5,0.0);
glPushMatrix();
glScalef(1.0,1.0,0.33333);
cubohueco();
glPopMatrix();
}
void dedos(int ch1,int ch2,int ch3,int a1,int a2,int a3,int m1,int m2,int m3,
int i1,int i2,int i3,int g1a,int g1b, int g2, int g3)
{
/*dedo chito*/
glScalef(1.0,1.0,1.0);
glPushMatrix();
/*primera falange*/
glScalef(0.25,0.25,0.25);
glTranslatef(-1.5,2.2,0.0);
glRotatef(ch1,1.0,0.0,0.0);
gluSphere(sphereObj, 0.65, 12, 5);
glTranslatef(0.0,1.0,0.0);
glPushMatrix();
glScalef(1.0,1.5,1.0);
cubohueco();
glPopMatrix();
/*segunda falange*/
glTranslatef(0.0,0.90,0.0);
glRotatef(ch2,1.0,0.0,0.0);
gluSphere(sphereObj, 0.65, 12, 5);
glTranslatef(0.0,0.85,0.0);
glPushMatrix();
glScalef(1.0,1.0,1.0);
cubohueco();
glPopMatrix();
/*tercera falange*/
glTranslatef(0.0,0.90,0.0);
glRotatef(ch3,1.0,0.0,0.0);
gluSphere(sphereObj, 0.60, 12, 5);
glTranslatef(0.0,0.75,0.0);
glPushMatrix();
glScalef(1.0,1.0,1.0);
cubohueco();
glPopMatrix();
glPopMatrix();/*fin dedo chiquito*/
/*dedo anular*/
glPushMatrix();
/*primera falange*/
glScalef(0.25,0.25,0.25);
glTranslatef(-0.5,2.2,0.0);
glRotatef(a1,1.0,0.0,0.0);
gluSphere(sphereObj, 0.65, 12, 5);
glTranslatef(0.0,1.0,0.0);
glPushMatrix();
glScalef(1.0,1.5,1.0);
cubohueco();
glPopMatrix();
/*segunda falange*/
glTranslatef(0.0,0.90,0.0);
glRotatef(a2,1.0,0.0,0.0);
gluSphere(sphereObj, 0.65, 12, 5);
glTranslatef(0.0,1.25,0.0);
glPushMatrix();
glScalef(1.0,1.75,1.0);
cubohueco();
glPopMatrix();
/*tercera falange*/
glTranslatef(0.0,0.90,0.0);
glRotatef(a3,1.0,0.0,0.0);
gluSphere(sphereObj, 0.60, 12, 5);
glTranslatef(0.0,0.75,0.0);
glPushMatrix();
glScalef(1.0,1.0,1.0);
cubohueco();
glPopMatrix();
glPopMatrix();/*fin dedo anular*/
/*dedo medio*/
glPushMatrix();
/*primera falange*/
glScalef(0.25,0.25,0.25);
glTranslatef(0.5,2.2,0.0);
glRotatef(m1,1.0,0.0,0.0);
gluSphere(sphereObj, 0.65, 12, 5);
glTranslatef(0.0,1.0,0.0);
glPushMatrix();
glScalef(1.0,1.5,1.0);
cubohueco();
glPopMatrix();
/*segunda falange*/
glTranslatef(0.0,0.90,0.0);
glRotatef(m2,1.0,0.0,0.0);
gluSphere(sphereObj, 0.65, 12, 5);
glTranslatef(0.0,1.5,0.0);
glPushMatrix();
glScalef(1.0,2.25,1.0);
cubohueco();
glPopMatrix();
/*tercera falange*/
glTranslatef(0.0,0.90,0.0);
glRotatef(m3,1.0,0.0,0.0);
gluSphere(sphereObj, 0.60, 12, 5);
glTranslatef(0.0,0.75,0.0);
glPushMatrix();
glScalef(1.0,1.0,1.0);
cubohueco();
glPopMatrix();
glPopMatrix();/*fin dedo medio*/
/*dedo indice*/
glPushMatrix();
/*primera falange*/
glScalef(0.25,0.25,0.25);
glTranslatef(1.5,2.2,0.0);
glRotatef(i1,1.0,0.0,0.0);
gluSphere(sphereObj, 0.65, 12, 5);
glTranslatef(0.0,1.0,0.0);
glPushMatrix();
glScalef(1.0,1.5,1.0);
cubohueco();
glPopMatrix();
/*segunda falange*/
glTranslatef(0.0,0.90,0.0);
glRotatef(i2,1.0,0.0,0.0);
gluSphere(sphereObj, 0.65, 12, 5);
glTranslatef(0.0,1.25,0.0);
glPushMatrix();
glScalef(1.0,1.75,1.0);
cubohueco();
glPopMatrix();
/*tercera falange*/
glTranslatef(0.0,0.90,0.0);
glRotatef(i3,1.0,0.0,0.0);
gluSphere(sphereObj, 0.60, 12, 5);
glTranslatef(0.0,0.75,0.0);
glPushMatrix();
glScalef(1.0,1.0,1.0);
cubohueco();
glPopMatrix();
glPopMatrix();/*fin dedo indice*/
/*dedo gordo*/
glPushMatrix();
/*primera falange*/
glScalef(0.25,0.25,0.25);
glTranslatef(2.0,-1.25,0.0);
glRotatef(g1a,0.0,-1.0,0.0);
glRotatef(g1b,0.0,0.0,1.0);
glScalef(1.3,1.3,1.0);
gluSphere(sphereObj, 0.65, 12, 5);
glTranslatef(0.75,0.0,0.0);
glPushMatrix();
glScalef(1.0,1.0,1.0);
cubohueco();
glPopMatrix();
/*segunda falange*/
glTranslatef(0.9,0.0,0.0);
glRotatef(g2,0.0,0.0,1.0);
gluSphere(sphereObj, 0.65, 12, 5);
glTranslatef(0.6,0.0,0.0);
glPushMatrix();
glScalef(0.75,1.0,1.0);
cubohueco();
glPopMatrix();
/*tercera falange*/
glTranslatef(0.75,0.0,0.0);
glRotatef(g3,0.0,0.0,1.0);
gluSphere(sphereObj, 0.60, 12, 5);
glTranslatef(0.5,0.0,0.0);
glPushMatrix();
glScalef(0.75,1.0,1.0);
cubohueco();
glPopMatrix();
glPopMatrix();/*fin dedo gordo*/
}
void mano(int posx, int posy, int posz,int chi1, int chi2, int chi3,int an1, int an2, int an3,
int med1, int med2, int med3,int in1, int in2, int in3,int go1a,int go1b,int go2,int go3)
{
//glScalef(1.0,1.0,1.0);
muneca(posx,posy,posz);
dedos(chi1,chi2,chi3,an1,an2,an3,med1,med2,med3,in1,in2,in3,go1a,go1b,go2,go3);
}
void display(void)
{
glClear (GL_COLOR_BUFFER_BIT);
glColor3f (1.0, 1.0, 1.0);
glLoadIdentity ();
gluLookAt (0.0,0.0,6.0,0.0,0.0, 0.0, 0.0, 1.0, 0.0);
sphereObj = gluNewQuadric();
gluQuadricDrawStyle(sphereObj, GLU_LINE);
glPushMatrix();
glTranslatef(2,-1,0);
glRotatef(-90,0.0,1.0,0.0);
mano(posicionx,posiciony,posicionz,chiquito1,chiquito2,chiquito3,anular1,anular2,anular3,
medio1,medio2,medio3,indice1,indice2,indice3,gordo1a,gordo1b,gordo2,gordo3);
glPopMatrix();
glPushMatrix();
glTranslatef(-2,-1,0);
glScalef(-1,1,1);
glRotatef(-90,0.0,1.0,0.0);
mano(posicionx,posiciony,posicionz,chiquito1,chiquito2,chiquito3,anular1,anular2,anular3,
medio1,medio2,medio3,indice1,indice2,indice3,gordo1a,gordo1b,gordo2,gordo3);
glPopMatrix();
glFlush ();
}

void idle(void)
{
actualizaArticulaciones();
display();
}
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;
case 'q':
posicionx = (posicionx+3)%360;
glutPostRedisplay();
break;
case 'w':
posiciony = (posiciony+3)%360;
glutPostRedisplay();
break;
case 'e':
posicionz = (posicionz+3)%360;
glutPostRedisplay();
break;
case 'a':
posicionx = 0;
posiciony = 0;
posicionz = 0;
glutPostRedisplay();
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);
glutIdleFunc(idle);
glutKeyboardFunc(keyboard);
glutMainLoop();
return 0;
}

No hay comentarios.: