daily pastebin goal
47%
SHARE
TWEET

pasta

a guest Mar 21st, 2019 112 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <windows.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <math.h>
  5. #include <GL/glut.h>
  6.  
  7. //--------------------------------- Definir cores
  8. #define BLUE     0.0, 0.0, 1.0, 1.0
  9. #define RED      1.0, 0.0, 0.0, 1.0
  10. #define YELLOW   1.0, 1.0, 0.0, 1.0
  11. #define GREEN    0.0, 1.0, 0.0, 1.0
  12. #define WHITE    1.0, 1.0, 1.0, 1.0
  13. #define BLACK    0.0, 0.0, 0.0, 1.0
  14. #define PI       3.14159
  15.  
  16. //================================================================================
  17. //===========================================================Variaveis e constantes
  18.  
  19. //------------------------------------------------------------ Sistema Coordenadas + objectos
  20. GLint       wScreen=800, hScreen=600;       //.. janela (pixeis)
  21. GLfloat     xC=5.0, yC=5.0, zC=5.0;     //.. Mundo  (unidades mundo)
  22.  
  23. //------------------------------------------------------------ Observador
  24. GLfloat  rVisao=200, aVisao=(0.5*PI) + 3.2, incVisao=0.05;
  25. GLfloat  obsP[] ={rVisao*cos(aVisao), 3.0, rVisao*sin(aVisao)};
  26. GLfloat  angZoom=90;
  27. GLfloat  incZoom=3;
  28.  
  29. GLdouble tx=0;
  30. GLdouble ty=0;
  31. GLdouble tz=0;
  32.  
  33. GLdouble Upx=0;
  34. GLdouble Upy=1;
  35. GLdouble Upz=0;
  36.  
  37. //=========================================================== FACES
  38. GLboolean   frenteVisivel=1;
  39.  
  40. static GLuint vert_ordem[48][4];
  41.  
  42. static GLuint faces[]= {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,
  43. 31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,
  44. 67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,
  45. 103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,
  46. 131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,
  47. 161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191};
  48.  
  49.  
  50. //ESCADAS
  51. static GLfloat vertices[] =
  52. {
  53.     -50.000000, 0.000000, 0.000000, 50.000000, 0.000000, 0.000000, 50.000000, 12.000000, 0.000000, -50.000000, 12.000000, 0.000000, -50.000000, 12.000000, 20.000000, 50.000000, 12.000000, 20.000000, 50.000000, 12.000000, 0.000000, -50.000000, 12.000000, 0.000000, -50.000000, 12.000000, 20.000000, 50.000000, 12.000000, 20.000000, 50.000000, 24.000000, 20.000000, -50.000000, 24.000000, 20.000000, -50.000000, 24.000000, 40.000000, 50.000000, 24.000000, 40.000000, 50.000000, 24.000000, 20.000000, -50.000000, 24.000000, 20.000000, -50.000000, 24.000000, 40.000000, 50.000000, 24.000000, 40.000000, 50.000000, 36.000000, 40.000000, -50.000000, 36.000000, 40.000000, -50.000000, 36.000000, 60.000000, 50.000000, 36.000000, 60.000000, 50.000000, 36.000000, 40.000000, -50.000000, 36.000000, 40.000000, -50.000000, 36.000000, 60.000000, 50.000000, 36.000000, 60.000000, 50.000000, 48.000000, 60.000000, -50.000000, 48.000000, 60.000000, -50.000000, 48.000000, 80.000000, 50.000000, 48.000000, 80.000000, 50.000000, 48.000000, 60.000000, -50.000000, 48.000000, 60.000000, -50.000000, 48.000000, 80.000000, 50.000000, 48.000000, 80.000000, 50.000000, 60.000000, 80.000000, -50.000000, 60.000000, 80.000000, -50.000000, 60.000000, 100.000000, 50.000000, 60.000000, 100.000000, 50.000000, 60.000000, 80.000000, -50.000000, 60.000000, 80.000000, -50.000000, 60.000000, 100.000000, 50.000000, 60.000000, 100.000000, 50.000000, 72.000000, 100.000000, -50.000000, 72.000000, 100.000000, -50.000000, 72.000000, 120.000000, 50.000000, 72.000000, 120.000000, 50.000000, 72.000000, 100.000000, -50.000000, 72.000000, 100.000000, -50.000000, 72.000000, 140.000000, 50.000000, 72.000000, 140.000000, 50.000000, 72.000000, 120.000000, -50.000000, 72.000000, 120.000000, -50.000000, 72.000000, 160.000000, 50.000000, 72.000000, 160.000000, 50.000000, 72.000000, 140.000000, -50.000000, 72.000000, 140.000000, -50.000000, 72.000000, 180.000000, 50.000000, 72.000000, 180.000000, 50.000000, 72.000000, 160.000000, -50.000000, 72.000000, 160.000000, -50.000000, 72.000000, 200.000000, 50.000000, 72.000000, 200.000000, 50.000000, 72.000000, 180.000000, -50.000000, 72.000000, 180.000000
  54. };
  55.  
  56.  
  57. static GLfloat normais[] =
  58. {
  59.     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, 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,
  60. };
  61.  
  62.  
  63.  
  64. static GLfloat cores [] = {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, 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, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.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, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.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, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.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, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 1.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,
  65. };
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73. //================================================================================
  74. //=========================================================================== INIT
  75. void inicializa(void)
  76. {
  77.     glClearColor(BLACK);        //………………………………………………………………………………Apagar
  78.     glEnable(GL_DEPTH_TEST);    //………………………………………………………………………………Profundidade
  79.     glShadeModel(GL_SMOOTH);    //………………………………………………………………………………Interpolacao de cores  
  80.  
  81.     //glEnable(GL_CULL_FACE);       //………………………………………………………………………………Faces visiveis
  82.     //glCullFace(GL_BACK);      //………………………………………………………………………………Mostrar so as da frente
  83.        
  84.     glVertexPointer(3, GL_FLOAT, 0, vertices); //………………………………………Vertex arrays
  85.     glEnableClientState(GL_VERTEX_ARRAY);
  86.     glNormalPointer(GL_FLOAT, 0, normais);
  87.     glEnableClientState(GL_NORMAL_ARRAY);
  88.     glColorPointer(3, GL_FLOAT, 0, cores);
  89.     glEnableClientState(GL_COLOR_ARRAY);   
  90. }
  91.  
  92.  
  93.  
  94. void drawEixos()
  95. {  
  96.     //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Eixo X
  97.     glColor4f(RED);
  98.     glBegin(GL_LINES);
  99.         glVertex3i( 0, 0, 0);
  100.         glVertex3i(10, 0, 0);
  101.     glEnd();
  102.     //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Eixo Y
  103.     glColor4f(GREEN);
  104.     glBegin(GL_LINES);
  105.         glVertex3i(0,  0, 0);
  106.         glVertex3i(0, 10, 0);
  107.     glEnd();
  108.     //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Eixo Z
  109.     glColor4f(BLUE);
  110.     glBegin(GL_LINES);
  111.         glVertex3i( 0, 0, 0);
  112.         glVertex3i( 0, 0,10);
  113.     glEnd();
  114.  
  115. }  
  116.  
  117. void drawSala(){
  118.     //PLano z=0
  119.     glBegin(GL_QUADS);
  120.     glColor3f(1,0,1);
  121.     glVertex3f(0,0,0);
  122.     glVertex3f(0,1500,0);
  123.     glVertex3f(1500,1500,0);
  124.     glVertex3f(1500,0,0);
  125.     glEnd();
  126.  
  127.     //Plano x=0
  128.     glBegin(GL_QUADS);
  129.     glColor3f(1,1,0);
  130.     glVertex3f(0,0,0);
  131.     glVertex3f(0,1500,0);
  132.     glVertex3f(0,1500,1500);
  133.     glVertex3f(0,0,1500);
  134.         glEnd();
  135.    
  136.     //Plano y=0
  137.     glBegin(GL_QUADS);
  138.     glColor3f(0,1,1);
  139.     glVertex3f(0,0,0);
  140.     glVertex3f(0,0,1500);
  141.     glVertex3f(1500,0,1500);
  142.     glVertex3f(1500,0,0);
  143.         glEnd();
  144.    
  145.     //Plano z=1500
  146.     glBegin(GL_QUADS);
  147.     glColor3f(1,0,0);
  148.     glVertex3f(0,0,1500);
  149.     glVertex3f(0,1500,1500);
  150.     glVertex3f(1500,1500,1500);
  151.     glVertex3f(1500,0,1500);
  152.     glEnd();
  153.    
  154.    
  155.    
  156.     //Plano x=1500
  157.     glBegin(GL_QUADS);
  158.     glColor3f(1,1,0);
  159.     glVertex3f(1500,0,0);
  160.     glVertex3f(1500,1500,0);
  161.     glVertex3f(1500,1500,1500);
  162.     glVertex3f(1500,0,1500);
  163.     glEnd();
  164.    
  165.    
  166.     //Plano y=1500
  167.     glBegin(GL_QUADS);
  168.     glColor3f(0,1,1);
  169.     glVertex3f(0,1500,0);
  170.     glVertex3f(0,1500,1500);
  171.     glVertex3f(1500,1500,1500);
  172.     glVertex3f(1500,1500,0);
  173.         glEnd();
  174.        
  175.    
  176.     //Plano y=72
  177.     glBegin(GL_QUADS);
  178.     glColor3f(0,1,0);
  179.     glVertex3f(0,72,230);
  180.     glVertex3f(0,72,1500);
  181.     glVertex3f(1500,72,1500);
  182.     glVertex3f(1500,72,230);
  183.     glEnd();
  184. }
  185.  
  186.  
  187. void drawScene(){
  188.    
  189.     //=================================================== Qual o lado ?
  190.     /*if (frenteVisivel)
  191.         glCullFace(GL_BACK);  //glFrontFace(GL_CW);
  192.     else
  193.         glCullFace(GL_FRONT);  //glFrontFace(GL_CCW);
  194.       */  
  195.         drawSala();
  196.        
  197.        
  198.             int acum = 0;
  199.    
  200.     for (int i = 0; i < 48; i++){
  201.        
  202.         vert_ordem[i][0] = faces[acum++];
  203.         vert_ordem[i][1] = faces[acum++];
  204.         vert_ordem[i][2] = faces[acum++];
  205.         vert_ordem[i][3] = faces[acum++];
  206.     }
  207.    
  208.     glPushMatrix();
  209.         //glDrawElements(GL_POLYGON, 4, GL_UNSIGNED_INT, esquerda);
  210.         //glDrawElements(GL_POLYGON, 4, GL_UNSIGNED_INT, direita);
  211.         //glDrawElements(GL_POLYGON, 4, GL_UNSIGNED_INT, cima);
  212.         glTranslatef (100,0,50);
  213.        
  214.        
  215.         for (int i=0; i < 192/4; i++){
  216.             glDrawElements(GL_POLYGON, 4, GL_UNSIGNED_INT, vert_ordem[i]);
  217.         }
  218.        
  219.     glPopMatrix();
  220.        
  221.        
  222.        
  223.        
  224.        
  225.        
  226.        
  227.        
  228.        
  229.        
  230.        
  231.        
  232.        
  233.     //==================================== PAralelipipedo Amarelo
  234.     glColor4f(YELLOW);
  235.     glPushMatrix();
  236.         //?? escala, rotacao, translacao ??
  237.         glutWireTeapot(1);     
  238.     glPopMatrix();
  239.    
  240. }
  241.  
  242. /*void display(void){
  243.    
  244.     //================================================================= APaga ecran/profundidade
  245.      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
  246.  
  247.     //ver de cima
  248.     //================================================================= NAO MOFIFICAR
  249.     glViewport (0, 0, 200, 200);                                // ESQUECER PoR AGORA
  250.     glMatrixMode(GL_PROJECTION);                                        // ESQUECER PoR AGORA
  251.     glLoadIdentity();                                                   // ESQUECER PoR AGORA
  252.     glOrtho(-10, 10, -10, 10, -10, 10);
  253.     //gluPerspective(angZoom, (float)wScreen/hScreen, 0.1, 3*zC);           // ESQUECER PoR AGORA
  254.     glMatrixMode(GL_MODELVIEW);                                         // ESQUECER PoR AGORA  
  255.     glLoadIdentity();
  256.    
  257.     gluLookAt(0.1, 10, 0.1, tx,ty,tz, Upx, Upy, Upz);                                                   // ESQUECER PoR AGORA
  258.    
  259.     drawEixos();
  260.     drawScene();
  261.    
  262.     //ver 3d
  263.     //================================================================= NAO MOFIFICAR
  264.     glViewport (0, 0, wScreen, hScreen);                                // ESQUECER PoR AGORA
  265.     glMatrixMode(GL_PROJECTION);                                        // ESQUECER PoR AGORA
  266.     glLoadIdentity();                                                   // ESQUECER PoR AGORA
  267.     //glOrtho(-30, 30, -30, 30, -30, 30);
  268.     gluPerspective(angZoom, (float)wScreen/hScreen, 0.1, 3*zC);         // ESQUECER PoR AGORA
  269.     glMatrixMode(GL_MODELVIEW);                                         // ESQUECER PoR AGORA  
  270.     glLoadIdentity();                                                   // ESQUECER PoR AGORA
  271.     //-------------------------------------------------------------- observador
  272.     gluLookAt(obsP[0], obsP[1], obsP[2], tx,ty,tz, Upx, Upy, Upz);
  273.  
  274.     //…………………………………………………………………………………………………………………………………………………………Objectos/modelos
  275.     drawEixos();
  276.     drawScene();    
  277.    
  278.     //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Actualizacao
  279.     glutSwapBuffers();
  280. }*/
  281.  
  282.  
  283. //======================================================= EVENTOS
  284. /*void keyboard(unsigned char key, int x, int y){
  285.    
  286.    
  287.     switch (key) {
  288.     case 'f':
  289.     case 'F':
  290.         frenteVisivel=!frenteVisivel;
  291.         glutPostRedisplay();
  292.         break;
  293.  
  294.     case 'A':
  295.     case 'a':
  296.         ty += 1;
  297.        
  298.         glutPostRedisplay();
  299.     break;
  300.  
  301.     case 'S':
  302.     case 's':
  303.         ty -= 1;
  304.         glutPostRedisplay();
  305.     break;
  306.  
  307.     case 'e':
  308.     case 'E':
  309.         tx += 1;
  310.         glutPostRedisplay();
  311.     break;
  312.  
  313.     case 'd':
  314.     case 'D':
  315.         tx -= 1;
  316.         glutPostRedisplay();
  317.     break;
  318.  
  319.  
  320.  
  321.  
  322.    
  323. //--------------------------- Escape
  324.     case 27:
  325.         exit(0);
  326.         break; 
  327.   }
  328.  
  329. }*/
  330.  
  331.  
  332.  
  333. void teclasNotAscii(int key, int x, int y){
  334.  
  335.         if(key == GLUT_KEY_UP)
  336.             obsP[1] = (obsP[1]+ 0.1) ;
  337.         if(key == GLUT_KEY_DOWN)
  338.             obsP[1] = (obsP[1]- 0.1) ;
  339.        
  340.         if (obsP[1]>yC)
  341.             obsP[1]=yC;
  342.         if (obsP[1]<-yC)
  343.             obsP[1]=-yC;
  344.  
  345.         if(key == GLUT_KEY_LEFT)
  346.             aVisao = (aVisao + 0.1) ;
  347.         if(key == GLUT_KEY_RIGHT)
  348.             aVisao = (aVisao - 0.1) ;
  349.  
  350.         obsP[0]=rVisao*cos(aVisao);
  351.         obsP[2]=rVisao*sin(aVisao);
  352.  
  353.  
  354.     glutPostRedisplay();   
  355.  
  356. }
  357. //codigo novo/////////////////////////////////////////////////////////////////////
  358. // angle of rotation for the camera direction
  359. float angle=0.0;
  360. // actual vector representing the camera's direction
  361. float lx=0.0f,ly=1.0f,lz=-1.0f;
  362. // XZ position of the camera
  363. float x=0.0f, y= 1.0f, z=5.0f;
  364.  
  365.  
  366. float aux=0.0f, auy=0.0f, auz=0.0f;
  367. void display(void){
  368.    
  369.     //================================================================= APaga ecran/profundidade
  370.      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
  371.  
  372.     /*//ver de cima
  373.     //================================================================= NAO MOFIFICAR
  374.     glViewport (0, 0, 200, 200);                                // ESQUECER PoR AGORA
  375.     glMatrixMode(GL_PROJECTION);                                        // ESQUECER PoR AGORA
  376.     glLoadIdentity();                                                   // ESQUECER PoR AGORA
  377.     glOrtho(-10, 10, -10, 10, -10, 10);
  378.     //gluPerspective(angZoom, (float)wScreen/hScreen, 0.1, 3*zC);           // ESQUECER PoR AGORA
  379.     glMatrixMode(GL_MODELVIEW);                                         // ESQUECER PoR AGORA  
  380.     glLoadIdentity();
  381.    
  382.     gluLookAt(x, 1.0f, z, x+lx,1.0f,z+lz, 0.0f, 0.1f, 0.0f);                                                    // ESQUECER PoR AGORA
  383.    
  384.     drawEixos();
  385.     drawScene(); */
  386.    
  387.     //ver 3d
  388.     //================================================================= NAO MOFIFICAR
  389.     glViewport (0, 0, wScreen, hScreen);                                // ESQUECER PoR AGORA
  390.     glMatrixMode(GL_PROJECTION);                                        // ESQUECER PoR AGORA
  391.     glLoadIdentity();                                                   // ESQUECER PoR AGORA
  392.     //glOrtho(-30, 30, -30, 30, -30, 30);
  393.     gluPerspective(angZoom, (float)wScreen/hScreen, 0.1, 600*zC);           // ESQUECER PoR AGORA
  394.     glMatrixMode(GL_MODELVIEW);                                         // ESQUECER PoR AGORA  
  395.     glLoadIdentity();                                                   // ESQUECER PoR AGORA
  396.     //-------------------------------------------------------------- observador
  397.     //gluLookAt(obsP[0], obsP[1], obsP[2], tx,ty,tz, Upx, Upy, Upz);
  398.     gluLookAt(obsP[0], obsP[1], obsP[2]+200, lx,ly,lz + 100, 0.0f, 0.1f, 0.0f);
  399.  
  400.     //…………………………………………………………………………………………………………………………………………………………Objectos/modelos
  401.     drawEixos();
  402.     drawScene();    
  403.    
  404.     //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Actualizacao
  405.     glutSwapBuffers();
  406. }
  407.  
  408. float norma(float x, float y, float z){
  409.     return  sqrt(pow(x,2)+pow(y,2)+pow(z,2));
  410. }
  411.  
  412. void keyboard(unsigned char key, int x1, int x2){
  413.    
  414.     float fraction = 2.0f;
  415.     switch (key) {
  416.     case 'w':
  417.     case 'W':
  418.         aux = lx - obsP[0];
  419.         auy = ly - obsP[1];
  420.         auz = lz - obsP[2];
  421.        
  422.        
  423.         obsP[0] += (aux / norma(aux, auy, auz)) * fraction;
  424.         //obsP[1] += (auy / norma(aux, auy, auz)) * fraction;
  425.         obsP[2] += (auz / norma(aux, auy, auz)) * fraction;
  426.  
  427.         lx += (aux / norma(aux, auy, auz)) * fraction;
  428.         ly += (auy / norma(aux, auy, auz)) * fraction;
  429.         lz += (auz/norma(aux, auy, auz)) * fraction;
  430.        
  431.         glutPostRedisplay();
  432.         break;
  433.  
  434.     case 'A':
  435.     case 'a':
  436.         angle -= 0.5f;
  437.  
  438.         lx = lx + (obsP[0] * sin(angle));
  439.         lz = lz + (obsP[2] *cos(angle));
  440.  
  441.         glutPostRedisplay();
  442.         break;
  443.  
  444.     case 'S':
  445.     case 's':
  446.         aux = lx - obsP[0];
  447.         auy = ly - obsP[1];
  448.         auz = lz - obsP[2];
  449.        
  450.         obsP[0] -= (aux /norma(aux, auy, auz)) * fraction;
  451.         //obsP[1] -= (auy / norma(aux, auy, auz)) * fraction;
  452.         obsP[2] -= (auz/norma(aux, auy, auz)) * fraction;
  453.        
  454.         lx -= (aux / norma(aux, auy, auz)) * fraction;
  455.         ly -= (auy / norma(aux, auy, auz)) * fraction;
  456.         lz -= (auz/norma(aux, auy, auz)) * fraction;
  457.  
  458.         glutPostRedisplay();
  459.         break;
  460.     case 'd':
  461.     case 'D':
  462.         angle += 0.5f;
  463.  
  464.         lx = lx + (obsP[0] * cos(angle));
  465.         lz = lz + (obsP[2] *sin(angle));
  466.  
  467.         glutPostRedisplay();
  468.         break; 
  469. //--------------------------- Escape
  470.     case 27:
  471.         exit(0);
  472.         break; 
  473.   }
  474.  
  475. }
  476.  
  477.  
  478. //======================================================= MAIN
  479. //======================================================= MAIN
  480. int main(int argc, char** argv){
  481.  
  482.     glutInit(&argc, argv);
  483.     glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH );
  484.     glutInitWindowSize (wScreen, hScreen);
  485.     glutInitWindowPosition (300, 100);
  486.     glutCreateWindow ("{jh,pjmm}@dei.uc.pt|       |FaceVisivel:'f'|      |Observador:'SETAS'|        |Andar-'a/s'|        |Rodar -'e/d'| ");
  487.  
  488.     inicializa();
  489.    
  490.     glutSpecialFunc(teclasNotAscii);
  491.     glutDisplayFunc(display);
  492.     glutKeyboardFunc(keyboard);
  493.    
  494.     glutMainLoop();
  495.  
  496.     return 0;
  497. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top