Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h> // printf
- #include "RgbImage.h"
- #include <math.h>
- #include <time.h>
- #include <OpenGL/gl.h>
- #include <OpenGL/glu.h>
- #include <GLUT/glut.h> // openGL
- //==================================================================== Definir cores
- #define AZUL 0.0, 0.0, 1.0, 1.0
- #define VERMELHO 1.0, 0.0, 0.0, 1.0
- #define AMARELO 1.0, 1.0, 0.0, 1.0
- #define VERDE 0.0, 1.0, 0.0, 1.0
- #define LARANJA 0.8, 0.6, 0.1, 1.0
- #define WHITE 1.0, 1.0, 1.0, 1.0
- #define BLACK 0.0, 0.0, 0.0, 1.0
- #define GRAY1 0.2, 0.2, 0.2, 1.0
- #define GRAY2 0.8, 0.8, 0.8, 1.0
- #define PRETO 0.0, 0.0, 0.0, 1.0
- #include "RgbImage.h"
- #define PI 3.14159
- //================================================================================
- //===========================================================Variaveis e constantes
- //------------------------------------------------------------ Sistema Coordenadas
- GLfloat xC = 16.0, zC = 15.0;
- GLint wScreen = 800, hScreen = 500;
- GLint msec = 100; //.. definicao do timer (actualizacao)
- //------------------------------------------------------------ Observador
- GLfloat rVisao = 3.0, aVisao = 0.5 * PI, incVisao = 0.1;
- GLfloat angPersp = 109.0;
- GLfloat obsPini[] = {1, 1.0, 0.5 * xC};
- GLfloat obsPfin[] = {obsPini[0] - rVisao * cos(aVisao), obsPini[1], obsPini[2] - rVisao *sin(aVisao)};
- RgbImage imag;
- //--------------------------------------------- Escada
- int y = 0, z = 0;
- //------------------------------
- int verticesESC = 3 * 52; // 53 vertices (x,y,z) = 53*3
- int facesESC = 13; // 53/4
- int plataformas = 2;
- static GLuint poligono[] = {};
- static GLfloat vertices[] = {
- -2.000000, -0.000000, -0.960000, 2.000000, -0.000000, -0.960000, 2.000000, 0.000000, -0.000000, -2.000000, 0.000000, -0.000000, -2.000000, 0.000000, -0.960000, 2.000000, 0.000000, -0.960000, 2.000000, 0.160000, -0.960000, -2.000000, 0.160000, -0.960000, -2.000000, 0.160000, -1.280000, 2.000000, 0.160000, -1.280000, 2.000000, 0.160000, -0.960000, -2.000000, 0.160000, -0.960000, -2.000000, 0.160000, -1.280000, 2.000000, 0.160000, -1.280000, 2.000000, 0.320000, -1.280000, -2.000000, 0.320000, -1.280000, -2.000000, 0.320000, -1.600000, 2.000000, 0.320000, -1.600000, 2.000000, 0.320000, -1.280000, -2.000000, 0.320000, -1.280000, -2.000000, 0.320000, -1.600000, 2.000000, 0.320000, -1.600000, 2.000000, 0.480000, -1.600000, -2.000000, 0.480000, -1.600000, -2.000000, 0.480000, -2.560000, 2.000000, 0.480000, -2.560000, 2.000000, 0.480000, -1.600000, -2.000000, 0.480000, -1.600000, -2.000000, 0.480000, -2.560000, 2.000000, 0.480000, -2.560000, 2.000000, 0.640000, -2.560000, -2.000000, 0.640000, -2.560000, -2.000000, 0.640000, -2.880000, 2.000000, 0.640000, -2.880000, 2.000000, 0.640000, -2.560000, -2.000000, 0.640000, -2.560000, -2.000000, 0.640000, -2.880000, 2.000000, 0.640000, -2.880000, 2.000000, 0.800000, -2.880000, -2.000000, 0.800000, -2.880000, -2.000000, 0.800000, -3.200000, 2.000000, 0.800000, -3.200000, 2.000000, 0.800000, -2.880000, -2.000000, 0.800000, -2.880000, -2.000000, 0.800000, -3.200000, 2.000000, 0.800000, -3.200000, 2.000000, 0.960000, -3.200000, -2.000000, 0.960000, -3.200000, -2.000000, 0.960000, -4.160000, 2.000000, 0.960000, -4.160000, 2.000000, 0.960000, -3.200000, -2.000000, 0.960000, -3.200000};
- static GLfloat normais[] = {
- 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000};
- // -------------- objectos
- void drawEscada()
- {
- //------------------------- ESCADA
- glColor4f(GRAY2);
- glPushMatrix();
- glTranslatef(5, -4.0, 0.0);
- glScalef(20, 20, 19);
- for (int p = 0; p < facesESC; p++)
- {
- poligono[0] = p * 4 + 0;
- poligono[1] = p * 4 + 1;
- poligono[2] = p * 4 + 2;
- poligono[3] = p * 4 + 3;
- glDrawElements(GL_POLYGON, 4, GL_UNSIGNED_INT, poligono);
- }
- glPopMatrix();
- }
- void plataforma2(){
- //------------------------- ESCADA
- glColor4f(GRAY1);
- glPushMatrix();
- glTranslatef(15, 18.0, -100.0);
- glScalef(20, 20, 19);
- for (int p = 0; p < facesESC; p++)
- {
- poligono[0] = p * 4 + 0;
- poligono[1] = p * 4 + 1;
- poligono[2] = p * 4 + 2;
- poligono[3] = p * 4 + 3;
- glDrawElements(GL_POLYGON, 4, GL_UNSIGNED_INT, poligono);
- }
- glPopMatrix();
- }
- void drawColuna(){
- glColor4f(0.5f, 0.35f, 0.05f, 1.0f);
- glPushMatrix();
- glBegin(GL_QUADS);
- glVertex3i(-5, 0, 2);
- glVertex3i(10, 0, 2);
- glVertex3i(10, 0, -5);
- glVertex3i(-5, 0, -5);
- glEnd();
- glPopMatrix();
- }
- void init(void)
- {
- glClearColor(WHITE);
- glShadeModel(GL_SMOOTH);
- glEnable(GL_DEPTH_TEST);
- //-------------------------------
- glVertexPointer(3, GL_FLOAT, 0, vertices);
- glEnableClientState(GL_VERTEX_ARRAY);
- glNormalPointer(GL_FLOAT, 0, normais);
- glEnableClientState(GL_NORMAL_ARRAY);
- }
- GLvoid resize(GLsizei width, GLsizei height)
- {
- wScreen = width;
- hScreen = height;
- glViewport(0, 0, wScreen, hScreen);
- glutPostRedisplay();
- }
- void drawOrientacao()
- {
- glDisable(GL_TEXTURE_2D);
- //----------------------- OBSERVADOR
- glPushMatrix();
- glColor4f(VERDE);
- glTranslatef(obsPini[0], obsPini[1], obsPini[2]);
- glutSolidCube(1);
- glPopMatrix();
- glPushMatrix();
- glColor4f(PRETO);
- glTranslatef(obsPfin[0], obsPfin[1], obsPfin[2]);
- glutSolidCube(1.0);
- glPopMatrix();
- }
- void display(void)
- {
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- //----------------------------------------- Viewport
- glViewport(wScreen / 5, 0, 0.75 * wScreen, hScreen);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluPerspective(angPersp, (float)wScreen / hScreen, 0.1, 100.0);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- gluLookAt(obsPini[0], obsPini[1], obsPini[2], obsPfin[0], obsPfin[1], obsPfin[2], 0, 1, 0);
- drawEscada();
- plataforma2();
- drawColuna();
- glutSwapBuffers();
- }
- void updateVisao()
- {
- obsPfin[0] = obsPini[0] + rVisao * cos(aVisao);
- obsPfin[2] = obsPini[2] - rVisao * sin(aVisao);
- glutPostRedisplay();
- }
- void keyboard(unsigned char key, int x, int y)
- {
- switch (key)
- {
- //--------------------------- Escape
- case 27:
- exit(0);
- break;
- }
- }
- void teclasNotAscii(int key, int x, int y)
- {
- if (key == GLUT_KEY_UP)
- {
- obsPini[0] = obsPini[0] + incVisao * cos(aVisao)*10;
- obsPini[2] = obsPini[2] - incVisao * sin(aVisao)*10;
- }
- if (key == GLUT_KEY_DOWN)
- {
- obsPini[0] = obsPini[0] - incVisao * cos(aVisao)*10;
- obsPini[2] = obsPini[2] + incVisao * sin(aVisao)*10;
- }
- if (key == GLUT_KEY_LEFT)
- aVisao = (aVisao + 0.01);
- if (key == GLUT_KEY_RIGHT)
- aVisao = (aVisao - 0.01);
- updateVisao();
- }
- void Timer(int value)
- {
- glutPostRedisplay();
- glutTimerFunc(msec, Timer, 1);
- }
- //======================================================= MAIN
- int main(int argc, char **argv)
- {
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
- glutInitWindowSize(wScreen, hScreen);
- glutInitWindowPosition(400, 100);
- glutCreateWindow("Escadas Moumentais - Ines & David");
- init();
- glutSpecialFunc(teclasNotAscii);
- glutReshapeFunc(resize);
- glutDisplayFunc(display);
- glutKeyboardFunc(keyboard);
- glutTimerFunc(msec, Timer, 1);
- glutMainLoop();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement