martes, 4 de septiembre de 2007

Practica 2 (LABORATORIO)

2.- Busque documentación en la API de GLUT y escriba programas utilizando:
  • Un cubo (glutSolidCube)
  • Un cono (glutSolidCono)
  • Un toro (glutSolidTorus)

Código:

para dibujar el cubo:

void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
glScalef (1.0, 2.0, 1.0); /* modeling transformation */

//Cubo:
glutSolidCube(1);

glutSwapBuffers();
glFlush ();

}


Para dibujar el cono:

void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
glScalef (1.0, 2.0, 1.0); /* modeling transformation */

//Cono
glutSolidCone(1,1.2,200,2);

glutSwapBuffers();
glFlush ();

}


Para dibujar el toro:

void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
glScalef (1.0, 2.0, 1.0); /* modeling transformation */

//Cono
glutSolidTorus(.5,1,200,20);

glutSwapBuffers();
glFlush ();

}


2.- A cada uno de estos objetos aplíqueñles una composición de transformación, utilizando el código:
glRotatef(30.0,1.0,0.0,0.0);
glTranslatef(0.5,0.5,-5.0);
glScalef(2,0.5,1.0);

Aplicando transformaciones:

void display(void)
{

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);



glRotatef(30.0,1.0,0.0,0.0);
glTranslatef(0.5,0.5,-5.0);
glScalef(2,0.5,1.0);

//solidcube
glutSolidCube(1);

//solidcone
glutSolidCone(1,1.2,200,2);


//toroide
glutSolidTorus(.5,1,200,20);


glutSwapBuffers();
glFlush ();

}

No hay comentarios: