0% encontró este documento útil (0 votos)
33 vistas3 páginas

C1B 3D Transformaciones

Descargar como pdf o txt
Descargar como pdf o txt
Descargar como pdf o txt
Está en la página 1/ 3

GRAFICACIÓN.

PROGRAMA BASICO. Con el siguiente programa

#include <windows.h>
#include <GL/glut.h>
#include <stdlib.h>

using namespace std;

void teclaOprimida(unsigned char key, int x, int y)


{ switch (key) { case 27: exit(0); } }

void RedimensionaPantalla(int w, int h)


{ glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-15,15,-15,15,-15,15);
glMatrixMode(GL_MODELVIEW);
gluPerspective(45.0, (double)w / (double)h,
1.0, 200.0);
}

void Inicializa()
{ glEnable(GL_DEPTH_TEST); }

void Dibuja()
{ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glBegin( GL_LINES);
glVertex3f(-15.0f, 0.0f, 0.0f); glVertex3f(15.0f, 0.0f, 0.0f);
glVertex3f( 0.0f,-15.0f, 0.0f); glVertex3f( 0.0f, 15.0f, 0.0f);
glVertex3f( 0.0f, 0.0f,-15.0f); glVertex3f( 0.0f, 0.0f, 15.0f);
glEnd();

glBegin(GL_QUADS);
glVertex3f(-5.0f, 12.0f, 0.0f);
glVertex3f(-1.0f, 12.0f, 0.0f);
glVertex3f(-1.0f, 8.0f, 0.0f);
glVertex3f(-5.0f, 8.0f, 0.0f);
glEnd();

glBegin(GL_TRIANGLES);
glVertex3f( 1.0f, 8.0f, 0.0f);
glVertex3f( 3.0f, 12.0f, 0.0f);
glVertex3f( 5.0f, 8.0f, 0.0f);
glEnd();

glBegin(GL_QUADS);
glVertex3f(-3.0f, 6.0f, 0.0f);
glVertex3f(-2.0f, 3.0f, 0.0f);
glVertex3f(-3.0f, 0.0f, 0.0f);
glVertex3f(-4.0f, 3.0f, 0.0f);
GRAFICACIÓN.
glEnd();

glBegin(GL_LINE_LOOP);
glVertex3f(3.0f, 6.0f, 0.0f);
glVertex3f(5.0f, 4.0f, 0.0f);
glVertex3f(5.0f, 1.0f, 0.0f);
glVertex3f(3.0f, 0.0f, 0.0f);
glVertex3f(1.0f, 1.0f, 0.0f);
glVertex3f(1.0f, 4.0f, 0.0f);
glEnd();
glutSwapBuffers();
}

int main(int argc, char **argv){


glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH );
glutInitWindowSize(800,600);
glutCreateWindow("Formas Basicas 3D");
Inicializa();
glutDisplayFunc(Dibuja);
glutKeyboardFunc(teclaOprimida);
glutReshapeFunc (RedimensionaPantalla);
glutMainLoop();
return 0; }

Este es el resultado

Para probar como funciona la profundidad tomaremos como ejemplo el primer rectangulo,

glBegin(GL_QUADS);
glVertex3f(-5.0f, 12.0f, 0.0f);
glVertex3f(-1.0f, 12.0f, 0.0f);
glVertex3f(-1.0f, 8.0f, 0.0f);
glVertex3f(-5.0f, 8.0f, 0.0f);
glEnd();
GRAFICACIÓN.
Qué pasa si al estar en la coordenada cero del eje "Z" dibujáramos un cuadro más pequeño de color rojo hacia una coordenada negativa
(atrás)

Este es el resultado

glColor3f(1.0f, 0.0f, 0.0f);


glBegin(GL_QUADS);
glVertex3f(-4.0f, 11.0f, -10.0f);
glVertex3f(-2.0f, 11.0f, -10.0f);
glVertex3f(-2.0f, 7.0f, -10.0f);
glVertex3f(-4.0f, 7.0f, -10.0f);
glEnd();
El cuadro rojo esta hacia atrás en coordenadas negativas
y si ubicáramos el cuadro rojo con coordenadas positivas que pasaría??

glColor3f(1.0f, 0.0f, 0.0f);


glBegin(GL_QUADS);
glVertex3f(-4.0f, 11.0f, 10.0f);
glVertex3f(-2.0f, 11.0f, 10.0f);
glVertex3f(-2.0f, 7.0f, 10.0f);
glVertex3f(-4.0f, 7.0f, 10.0f);
glEnd();

Es un hecho que OpenGL garantiza la ubicación de los objetos en la pantalla, pero ahora como podemos hacer rotar el cuadro rojo?
Nuestro código modificado con el nuevo cuadro rojo se ve así (veremos una parte, la parte central)

glBegin( GL_LINES);
glVertex3f(-15.0f, 0.0f, 0.0f); glVertex3f(15.0f, 0.0f, 0.0f);
glVertex3f( 0.0f,-15.0f, 0.0f); glVertex3f( 0.0f, 15.0f, 0.0f);
glVertex3f( 0.0f, 0.0f,-15.0f); glVertex3f( 0.0f, 0.0f, 15.0f);
glEnd();
glBegin(GL_QUADS);
glVertex3f(-5.0f, 12.0f, 0.0f); glVertex3f(-1.0f, 12.0f, 0.0f);
glVertex3f(-1.0f, 8.0f, 0.0f); glVertex3f(-5.0f, 8.0f, 0.0f);
glEnd();

glColor3f(1.0f, 0.0f, 0.0f); Cambia al color rojo


glBegin(GL_QUADS);
glVertex3f(-4.0f, 11.0f, 10.0f); glVertex3f(-2.0f, 11.0f, 10.0f); CODIGO NUEVO
glVertex3f(-2.0f, 7.0f, 10.0f); glVertex3f(-4.0f, 7.0f, 10.0f); AGREGADO CUADRO
glEnd(); ROJO

glColor3f(1.0f, 1.0f, 1.0f); Regresa al color blanco


glBegin(GL_TRIANGLES);
glVertex3f( 1.0f, 8.0f, 0.0f);
glVertex3f( 3.0f, 12.0f, 0.0f);
glVertex3f( 5.0f, 8.0f, 0.0f);
glEnd();

También podría gustarte

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy