1.- Escriba el código para dibuajr un mano:
void cubo(void) //construcción del cubo , cara por cara
{
glBegin(GL_LINE_LOOP);
glVertex3f(0.5f,0.5f,0.5f);
glVertex3f(-0.5f,0.5f,0.5f);
glVertex3f(-0.5f,-0.5f,0.5f);
glVertex3f(0.5f,-0.5f,0.5f);
glEnd();
glBegin(GL_LINE_LOOP);
glVertex3f(-0.5f,0.5f,-0.5f);
glVertex3f( 0.5f,0.5f,-0.5f);
glVertex3f(0.5f,-0.5f,-0.5f);
glVertex3f(-0.5f,-0.5f,-0.5f);
glEnd();
glBegin(GL_LINE_LOOP);
glVertex3f(-0.5f,0.5f,0.5f);
glVertex3f(-0.5f,0.5f,-0.5f);
glVertex3f(-0.5f,-0.5f,-0.5f);
glVertex3f(-0.5f,-0.5f,0.5f);
glEnd();
glBegin(GL_LINE_LOOP);
glVertex3f(0.5f,0.5f,0.5f);
glVertex3f(0.5f,-0.5f,0.5f);
glVertex3f( 0.5f,-0.5f,-0.5f);
glVertex3f(0.5f,0.5f,-0.5f);
glEnd();
glBegin(GL_LINE_LOOP);
glVertex3f(-0.5f,0.5f,-0.5f);
glVertex3f(-0.5f,0.5f,0.5f);
glVertex3f(0.5f,0.5f,0.5f);
glVertex3f( 0.5f,0.5f,-0.5f);
glEnd();
glBegin(GL_LINE_LOOP);
glVertex3f(0.5f,-0.5f,-0.5f);
glVertex3f(-0.5f,-0.5f,-0.5f);
glVertex3f(-0.5f,-0.5f,0.5f);
glVertex3f(0.5f,-0.5f,0.5f);
glEnd();
}
void palma (void)
{
glPushMatrix();
glScalef(2,2,0);
cubo();
glPopMatrix();
}
void dedo (void)
{
glPushMatrix();
glScalef(0.5,0.5,0);
cubo();
glPopMatrix();
glPushMatrix();
glScalef(0.5,0.5,0);
glTranslatef(0,1,0);
cubo();
glPopMatrix();
glPushMatrix();
glScalef(0.5,0.5,0);
glTranslatef(0,2,0);
cubo();
glPopMatrix();
}
void dedoGordo (void) //dedo flexioando de la mano
{
glPushMatrix(); //primera parte
glScalef(0.4,0.6,0);
glRotatef(30,0,0,1);
cubo();
glPopMatrix();
glPushMatrix(); //segunda parte
glRotatef(10,0,0,1);
glScalef(0.4,0.6,0);
glTranslatef(-0.2,1.2,0);
cubo();
glPopMatrix();
glPushMatrix(); //terrcera parte
glRotatef(-30,0,0,1);
glScalef(0.4,0.6,0);
glTranslatef(-1.9,2.0,0);
cubo();
glPopMatrix();
}
// Funcion que dibuja la mano:
void manoRobot()
{
glPushMatrix();
palma();
glTranslatef(-0.75,1.25,0);
dedo();
glPopMatrix();
glPushMatrix();
palma();
glTranslatef(-0.25,1.25,0);
dedo();
glPopMatrix();
glPushMatrix();
palma();
glTranslatef(0.25,1.25,0);
dedo();
glPopMatrix();
glPushMatrix();
palma();
glTranslatef(0.75,1.25,0);
dedo();
glPopMatrix();
glPushMatrix();
palma();
glTranslatef(-1.3,-0.75f,0);
dedoGordo();
glPopMatrix();
}
2.- El código de brazoRobotConTenazas() parametricelo para que pueda modificarse la apertura de las articualciones, Por ejemplo brazoRobotConTenazas(float fHombro,fCodo,fNudillo)
void brazoRobotConTenazas(float fhombro, float fcodo, float fnudillo)
{
glPushMatrix();
glRotatef(-fhombro,0,0,1);
glTranslatef(0,1.5,0);
glPushMatrix();
glScalef(0.5,3.0,0.5);
cubo();
glPopMatrix();
glTranslatef(0,1.5,0);
glRotatef(-fcodo,0,0,1);
glTranslatef(0,1,0);
glPushMatrix();
glScalef(0.5,2.0,0.5);
cubo();
glPopMatrix();
glPushMatrix();
glTranslatef(0,2,0);
glRotatef(-fnudillo,-4,-2,0);
glScalef(0.2,0.9,0.2);
glColor3f(0,1,0);
cubo();
glPopMatrix();
glTranslatef(.3,2,0);
glRotatef(-fnudillo,-4,-2,5);
glScalef(0.2,0.9,0.2);
glColor3f(0,1,0);
cubo();
glPopMatrix();
glPopMatrix();
}
3.-Agregue la mano al modelo del humanoide, creando uan nueva función humanoideConManos()
void cubo(void) //construcción del cubo , cara por cara
{
glBegin(GL_LINE_LOOP);
glVertex3f(0.5f,0.5f,0.5f);
glVertex3f(-0.5f,0.5f,0.5f);
glVertex3f(-0.5f,-0.5f,0.5f);
glVertex3f(0.5f,-0.5f,0.5f);
glEnd();
glBegin(GL_LINE_LOOP);
glVertex3f(-0.5f,0.5f,-0.5f);
glVertex3f( 0.5f,0.5f,-0.5f);
glVertex3f(0.5f,-0.5f,-0.5f);
glVertex3f(-0.5f,-0.5f,-0.5f);
glEnd();
glBegin(GL_LINE_LOOP);
glVertex3f(-0.5f,0.5f,0.5f);
glVertex3f(-0.5f,0.5f,-0.5f);
glVertex3f(-0.5f,-0.5f,-0.5f);
glVertex3f(-0.5f,-0.5f,0.5f);
glEnd();
glBegin(GL_LINE_LOOP);
glVertex3f(0.5f,0.5f,0.5f);
glVertex3f(0.5f,-0.5f,0.5f);
glVertex3f( 0.5f,-0.5f,-0.5f);
glVertex3f(0.5f,0.5f,-0.5f);
glEnd();
glBegin(GL_LINE_LOOP);
glVertex3f(-0.5f,0.5f,-0.5f);
glVertex3f(-0.5f,0.5f,0.5f);
glVertex3f(0.5f,0.5f,0.5f);
glVertex3f( 0.5f,0.5f,-0.5f);
glEnd();
glBegin(GL_LINE_LOOP);
glVertex3f(0.5f,-0.5f,-0.5f);
glVertex3f(-0.5f,-0.5f,-0.5f);
glVertex3f(-0.5f,-0.5f,0.5f);
glVertex3f(0.5f,-0.5f,0.5f);
glEnd();
}
void dedo (void)
{
glPushMatrix();
glScalef(0.5,0.5,0);
cubo();
glPopMatrix();
glPushMatrix();
glScalef(0.5,0.5,0);
glTranslatef(0,1,0);
cubo();
glPopMatrix();
glPushMatrix();
glScalef(0.5,0.5,0);
glTranslatef(0,2,0);
cubo();
glPopMatrix();
}
void dedoGordo (void) //dedo flexioando de la mano
{
glPushMatrix(); //primera parte
glScalef(0.4,0.6,0);
glRotatef(30,0,0,1);
cubo();
glPopMatrix();
glPushMatrix(); //segunda parte
glRotatef(10,0,0,1);
glScalef(0.4,0.6,0);
glTranslatef(-0.2,1.2,0);
cubo();
glPopMatrix();
glPushMatrix(); //rcera parte
glRotatef(-30,0,0,1);
glScalef(0.4,0.6,0);
glTranslatef(-1.9,2.0,0);
cubo();
glPopMatrix();
}
void manoRobot()
{
glPushMatrix();
palma();
glTranslatef(-0.75,1.25,0);
dedo();
glPopMatrix();
glPushMatrix();
palma();
glTranslatef(-0.25,1.25,0);
dedo();
glPopMatrix();
glPushMatrix();
palma();
glTranslatef(0.25,1.25,0);
dedo();
glPopMatrix();
glPushMatrix();
palma();
glTranslatef(0.75,1.25,0);
dedo();
glPopMatrix();
glPushMatrix();
palma();
glTranslatef(-1.3,-0.75f,0);
dedoGordo();
glPopMatrix();
}
void robot()
{
//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,1.0,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,-0.7,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,-0.7,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
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
//glColor3f (1.0, 0.0, 0.0); /* clear the matrix */
/* viewing transformation */
gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
glScalef (0.5, 0.8, 0.2); /* modeling transformation */
//glRotatef(Ang,0.0f,1.0f,0.0f);
//se manda construye el robot con sus manos;
robot();
glPushMatrix();
glTranslatef(3,0.3,0.0);
glRotatef(-90,0,0,1);
glScalef (0.2, 0.2, 0.0);
manoRobot();
glPopMatrix();
robot();
glPushMatrix();
glTranslatef(-3,0.3,0.0);
glRotatef(-270,0,0,1);
glScalef (0.2, 0.2, 0.0);
manoRobot();
glPopMatrix();
glutSwapBuffers();
glFlush ();
}
No hay comentarios:
Publicar un comentario