Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <math.h>
- #include <GL/glut.h>
- // Definir cores
- #define RED 1.0, 0.0, 0.0, 1.0
- #define GREEN 0.0, 1.0, 0.0, 1.0
- #define BLUE 0.0, 0.0, 1.0, 1.0
- #define YELLOW 1.0, 1.0, 0.0, 1.0
- #define WHITE 1.0, 1.0, 1.0, 1.0
- #define BLACK 0.0, 0.0, 0.0, 1.0
- #define PI 3.14159
- // Sistema Coordenadas + objectos
- GLint wScreen=800, hScreen=600; // janela (pixeis)
- GLfloat xC=1000.0, yC=1000.0, zC=1000.0; // Mundo (unidades mundo)
- //------------------------------------------------------------ Observador
- GLfloat rVisao=10, aVisao=0.5*PI, incVisao=0.05;
- GLfloat obsP[] ={rVisao*cos(aVisao), 3.0, rVisao*sin(aVisao)};
- GLfloat angZoom=90;
- GLfloat incZoom=3;
- GLfloat mov=0;
- GLfloat alpha=0;
- GLfloat tam=2.0;
- GLfloat xx=0;
- GLfloat yy=0;
- GLfloat zz=0;
- GLboolean frenteVisivel=1;
- void inicializa(void){
- glClearColor(BLACK); // Apagar
- glEnable(GL_DEPTH_TEST); // Profundidade
- glShadeModel(GL_SMOOTH); // Interpolacao de cores
- glEnable(GL_CULL_FACE); // Faces visiveis
- glCullFace(GL_BACK); // Mostrar so as da frente
- glEnableClientState(GL_VERTEX_ARRAY);
- glEnableClientState(GL_NORMAL_ARRAY);
- glEnableClientState(GL_COLOR_ARRAY);
- }
- void drawParedes(){
- // Plano XoY
- glColor4f(RED);
- glPushMatrix();
- //glTranslatef(-10,0,-10);
- glBegin(GL_QUADS);
- glVertex3f(0,0,0);
- glVertex3f(100,0,0);
- glVertex3f(100,300,0);
- glVertex3f(0,300,0);
- glEnd();
- glBegin(GL_QUADS);
- glVertex3f(0,0,100);
- glVertex3f(0,300,100);
- glVertex3f(100,300,100);
- glVertex3f(100,0,100);
- glEnd();
- // Plano YoZ
- glColor4f(GREEN);
- glBegin(GL_QUADS);
- glVertex3f(0,0,0);
- glVertex3f(0,300,0);
- glVertex3f(0,300,100);
- glVertex3f(0,0,100);
- glEnd();
- glBegin(GL_QUADS);
- glVertex3f(100,0,0);
- glVertex3f(100,0,100);
- glVertex3f(100,300,100);
- glVertex3f(100,300,0);
- glEnd();
- // Plano XoZ - chao
- glColor4f(YELLOW);
- glBegin(GL_QUADS);
- glVertex3f(0,0,0);
- glVertex3f(0,0,100);
- glVertex3f(100,0,100);
- glVertex3f(100,0,0);
- glEnd();
- glPopMatrix();
- }
- void display(void){
- //================================================================= APaga ecran/profundidade
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
- //================================================================= Não modificar
- glViewport (0, 0, wScreen, hScreen);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- //gluPerspective(angZoom, (float)wScreen/hScreen, 0.1, 3*zC);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- gluLookAt(obsP[0], obsP[1], obsP[2], xx, yy, zz, 0, 1, 0);
- //================================================================= Não modificar
- //…………………………………………………………………………………………………………………………………………………………Objectos
- drawParedes();
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Actualizacao
- glutSwapBuffers();
- }
- int main(int argc, char** argv){
- glutInit(&argc, argv);
- glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH );
- glutInitWindowSize (wScreen, hScreen);
- glutInitWindowPosition (300, 100);
- inicializa();
- //glutSpecialFunc(teclasNotAscii);
- glutDisplayFunc(display);
- //glutKeyboardFunc(keyboard);
- glutMainLoop();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement