Práctica.- Figuras predeterminadas
La siguiente práctica tiene el propósito de mostrar las diferentes figuras en 3D predeterminadas que vienen por default en las librerías de OpenGL.
El código se presenta a continuación:
------------------------------------------------------------------------------------------
/*
Sáenz Morales Carlos Giovanni
*/
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include <iostream>
using namespace std;
void Dibuja(){
cerr << "Dibuja() \n";
glClearColor(0,0,0,0);
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
/* glPushMatrix();
glTranslatef(-0.8,0.8,0.0);
glColor3f(0.0, 1.0, 0.0);
glutWireSphere(0.2, 15, 15);
glPopMatrix();
*/
/* Este bloque permite que se dibuje la segunda esfera pero borra la primera.. es necesario para trasladar el eje
glClearColor(0,0,0,0);
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
*/
//Sin embrago puede sustituirse por la siguientes lineas
glPushMatrix(); //Esta linea es para guardar la matriz
glTranslatef(0.75,0.4,0.0);
glScalef(1.0, 1.0, 1.0); //Esta linea permite hacer figuras a escala.. en este caso a la mitad
glRotatef(45, 0, 1, 1); //Esta linea permite rotar la imagen
glColor3f(0.0, 0.0, 1.0);
glutWireSphere(0.2, 15, 15);
glPopMatrix();//Esta otra linea permite cambiar las coordenadas al centro nuevamente
glPushMatrix();
glTranslatef(0.75,-0.05,0.0);
glRotatef(45, 0, 1, 1);
glScalef(1.0, 1.0, 1.0);
glColor3f(0.0, 0.0, 1.0);
glutSolidSphere(0.2,30,30);
glPopMatrix();
/*
glPushMatrix();
glTranslatef(0.8,-0.8,0.0);
glColor3f(1.0, 0.0, 0.0);
glutWireSphere(0.2, 15, 15);
glPopMatrix();
glPushMatrix();
glTranslatef(-0.5,-0.5,0.0);
glRotatef(45, 0, 1, 1);
glScalef(2.0, 2.0, 2.0);
glColor3f(1.0, 1.0, 1.0);
glutWireSphere(0.2, 15, 15);
glPopMatrix();
*/
glPushMatrix();
glTranslatef(-0.75,-0.75,0.0);
glRotatef(90, 0, 1, 1);
glScalef(2.0, 2.0, 2.0);
glColor3f(0.0, 1.0, 0.0);
glutWireCube(0.1);
glPopMatrix();
glPushMatrix();
glTranslatef(-0.75,-0.45,0.0);
glRotatef(90, 0, 1, 1);
glScalef(2.0, 2.0, 2.0);
glColor3f(0.0, 1.0, 0.0);
glutSolidCube(0.1);
glPopMatrix();
glPushMatrix();
glTranslatef(-0.3,-0.7,0.0);
glRotatef(70, 45, 1, 1);
glScalef(0.5, 0.5, 0.5);
glColor3f(1.0, 0.0, 0.0);
glutWireCone(0.2,0.4,15,15);
glPopMatrix();
glPushMatrix();
glTranslatef(-0.3,-0.45,0.0);
glRotatef(70, 45, 1, 1);
glScalef(0.5, 0.5, 0.5);
glColor3f(1.0, 0.0, 0.0);
glutSolidCone(0.2,0.4,15,15);
glPopMatrix();
glPushMatrix();
glTranslatef(0.2,-0.75,0.0);
glRotatef(60, 1, 0, 0);
glScalef(0.7, 0.7, 0.7);
glColor3f(1.0, 0.5, 0.0);
glutWireTorus(0.10,0.15,15,15);
glPopMatrix();
glPushMatrix();
glTranslatef(0.2,-0.45,0.0);
glRotatef(60, 1, 0, 0);
glScalef(0.7, 0.7, 0.7);
glColor3f(1.0, 0.5, 0.0);
glutSolidTorus(0.10,0.15,15,15);
glPopMatrix();
glPushMatrix();
glTranslatef(0.7,-0.80,0.0);
glRotatef(60, 1, 0, 0);
glScalef(0.1, 0.1, 0.1);
glColor3f(1.0, 1.0, 0.0);
glutWireDodecahedron();
glPopMatrix();
glPushMatrix();
glTranslatef(0.7,-0.45,0.0);
glRotatef(60, 1, 0, 0);
glScalef(0.1, 0.1, 0.1);
glColor3f(1.0, 1.0, 0.0);
glutSolidDodecahedron();
glPopMatrix();
glPushMatrix();
glTranslatef(-0.75,0.4,0.0);
glRotatef(75, 1, 0, 0);
glScalef(0.2, 0.2, 0.2);
glColor3f(1.0, 0.7, 1.0);
glutWireOctahedron();
glPopMatrix();
glPushMatrix();
glTranslatef(-0.75,0.0,0.0);
glRotatef(75, 1, 0, 0);
glScalef(0.2, 0.2, 0.2);
glColor3f(1.0, 0.7, 1.0);
glutSolidOctahedron();
glPopMatrix();
glPushMatrix();
glTranslatef(-0.2,0.4,0.0);
glRotatef(60, 1, 1, 0);
glScalef(0.3, 0.3, 0.3);
glColor3f(1.0, 0.7, 0.2);
glutWireTetrahedron();
glPopMatrix();
glPushMatrix();
glTranslatef(-0.2,-0.05,0.0);
glRotatef(60, 1, 1, 0);
glScalef(0.3, 0.3, 0.3);
glColor3f(1.0, 0.7, 0.2);
glutSolidTetrahedron();
glPopMatrix();
glPushMatrix();
glTranslatef(0.3,0.4,0.0);
glRotatef(30, 1, 0, 0);
glScalef(0.15, 0.15, 0.15);
glColor3f(0.5, 0.5, 0.5);
glutWireIcosahedron();
glPopMatrix();
glPushMatrix();
glTranslatef(0.3,0.0,0.0);
glRotatef(30, 1, 0, 0);
glScalef(0.15, 0.15, 0.15);
glColor3f(0.5, 0.5, 0.5);
glutSolidIcosahedron();
glPopMatrix();
glPushMatrix();
glTranslatef(-0.4,0.8,0.0);
glRotatef(20, 1, 0, 0);
glScalef(0.7, 0.7, 0.7);
glColor3f(0.0, 0.5, 0.0);
glutWireTeapot(0.3);
glPopMatrix();
glPushMatrix();
glTranslatef(0.4,0.8,0.0);
glRotatef(20, 1, 0, 0);
glScalef(0.7, 0.7, 0.7);
glColor3f(0.0, 0.5, 0.0);
glutSolidTeapot(0.3);
glPopMatrix();
glFlush();
}
int main (){
cerr << "main() \n" ;
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(920, 680);
glutCreateWindow("");
glutDisplayFunc(Dibuja);
glutMainLoop();
}
------------------------------------------------------------------------------------------
Y las figuras que se representan gráficamente son las siguientes:

No hay comentarios.:
Publicar un comentario