void brazo(int shoulder, int joint, int wrist) {
//empieza el dibujo del primer brazo robot
glPushMatrix();
glTranslatef(-0.75,-0.5, 0.0);
glScalef(1.5,2.0,0.8);
drawBox();
glPopMatrix();
glPushMatrix();
glTranslatef(-0.75,1.0, 0.0);
drawBox();
glPopMatrix();
glPushMatrix();
//empieza el brazo
glRotatef(shoulder, 0.0, 0.0, 1.0);
glTranslatef(1.0, 0.0, 0.0);
glPushMatrix();
glScalef(2.0,0.5,0.5);
drawBox();
glPopMatrix();
//termina brazo
//empieza antebrazo
glTranslatef(1.0, 0.0, 0.0);
glRotatef(joint, 0.0, 0.0, 1.0);
glTranslatef(1.0, 0.0, 0.0);
glPushMatrix();
glScalef(2.0,0.5,0.5);
drawBox();
glPopMatrix();
//termina antebrazo-- M6
//empieza el grip
glPushMatrix();
//empieza el primer dedo
glPushMatrix();
glTranslatef(1.0,0.0,0.0);
glRotatef(wrist,0.0,0.0,1.0);
glTranslatef(0.35,0.125,0.0);
glPushMatrix();
glScalef(0.7,0.25,0.25);
drawBox();
glPopMatrix();
glPopMatrix();
//termina el primer dedo
//empieza el segundo dedo
glPushMatrix();
glTranslatef(1.0,0.0,0.0);
glRotatef(-wrist,0.0,0.0,1.0);
glTranslatef(0.35,-0.125,0.0);
glPushMatrix();
glScalef(0.7,0.25,0.25);
drawBox();
glPopMatrix();
glPopMatrix();
glPushMatrix();
glTranslatef(0.0,-1.0,0.0);
glPopMatrix();
//termina el segundo dedo
glPopMatrix();
//termina el grip
glPopMatrix();
//termina el dibujo del primer brazo robot
//empieza el brazo
glRotatef(shoulder, 0.0, 0.0, 1.0);
glTranslatef(-2.0, 0.0, 0.0);
glPushMatrix();
glScalef(2.0,0.5,0.5);
drawBox();
glPopMatrix();
//termina brazo
//empieza antebrazo
glTranslatef(-3.0, 0.0, 0.0);
glRotatef(joint, 0.0, 0.0, 1.0);
glTranslatef(1.0, 0.0, 0.0);
glPushMatrix(); glScalef(2.0,0.5,0.5);
drawBox(); glPopMatrix();
//termina antebrazo-- M6
//empieza el grip
glPushMatrix();
//empieza el primer dedo
glPushMatrix();
glTranslatef(1.0,0.0,0.0);
glRotatef(wrist,0.0,0.0,1.0);
glTranslatef(-2.35,0.125,0.0);
glPushMatrix();
glScalef(0.7,0.25,0.25);
drawBox();
glPopMatrix();
glPopMatrix();
//termina el primer dedo
//empieza el segundo dedo
glPushMatrix();
glTranslatef(1.0,0.0,0.0);
glRotatef(-wrist,0.0,0.0,1.0);
glTranslatef(-2.35,-0.125,0.0);
glPushMatrix();
glScalef(0.7,0.25,0.25);
drawBox();
glPopMatrix();
glPopMatrix();
glPushMatrix();
glTranslatef(0.0,-1.0,0.0);
glPopMatrix();
//termina el segundo dedo
glPopMatrix();
//termina el grip
glPopMatrix();
//termina el dibujo del segundo brazo robot

El fragmento de codigo anterior es un ejemplo claro de como podemos utilizar el stack para modelar jerarquicamente
No hay comentarios:
Publicar un comentario