Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.37 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <math.h>
  4. #include <GL/glut.h>
  5.  
  6. // Definir cores
  7. #define RED 1.0, 0.0, 0.0, 1.0
  8. #define GREEN 0.0, 1.0, 0.0, 1.0
  9. #define BLUE 0.0, 0.0, 1.0, 1.0
  10. #define YELLOW 1.0, 1.0, 0.0, 1.0
  11. #define WHITE 1.0, 1.0, 1.0, 1.0
  12. #define BLACK 0.0, 0.0, 0.0, 1.0
  13. #define PI 3.14159
  14.  
  15. // Sistema Coordenadas + objectos
  16. GLint wScreen=800, hScreen=600; // janela (pixeis)
  17. GLfloat xC=1000.0, yC=1000.0, zC=1000.0; // Mundo (unidades mundo)
  18.  
  19. //------------------------------------------------------------ Observador
  20. GLfloat rVisao=10, aVisao=0.5*PI, incVisao=0.05;
  21. GLfloat obsP[] ={rVisao*cos(aVisao), 3.0, rVisao*sin(aVisao)};
  22. GLfloat angZoom=90;
  23. GLfloat incZoom=3;
  24.  
  25. GLfloat mov=0;
  26. GLfloat alpha=0;
  27. GLfloat tam=2.0;
  28. GLfloat xx=0;
  29. GLfloat yy=0;
  30. GLfloat zz=0;
  31.  
  32. GLboolean frenteVisivel=1;
  33.  
  34. void inicializa(void){
  35. glClearColor(BLACK); // Apagar
  36. glEnable(GL_DEPTH_TEST); // Profundidade
  37. glShadeModel(GL_SMOOTH); // Interpolacao de cores
  38.  
  39. glEnable(GL_CULL_FACE); // Faces visiveis
  40. glCullFace(GL_BACK); // Mostrar so as da frente
  41.  
  42. glEnableClientState(GL_VERTEX_ARRAY);
  43. glEnableClientState(GL_NORMAL_ARRAY);
  44. glEnableClientState(GL_COLOR_ARRAY);
  45. }
  46.  
  47. void drawParedes(){
  48. // Plano XoY
  49. glColor4f(RED);
  50. glPushMatrix();
  51. //glTranslatef(-10,0,-10);
  52. glBegin(GL_QUADS);
  53. glVertex3f(0,0,0);
  54. glVertex3f(100,0,0);
  55. glVertex3f(100,300,0);
  56. glVertex3f(0,300,0);
  57. glEnd();
  58.  
  59. glBegin(GL_QUADS);
  60. glVertex3f(0,0,100);
  61. glVertex3f(0,300,100);
  62. glVertex3f(100,300,100);
  63. glVertex3f(100,0,100);
  64. glEnd();
  65.  
  66. // Plano YoZ
  67. glColor4f(GREEN);
  68. glBegin(GL_QUADS);
  69. glVertex3f(0,0,0);
  70. glVertex3f(0,300,0);
  71. glVertex3f(0,300,100);
  72. glVertex3f(0,0,100);
  73. glEnd();
  74.  
  75. glBegin(GL_QUADS);
  76. glVertex3f(100,0,0);
  77. glVertex3f(100,0,100);
  78. glVertex3f(100,300,100);
  79. glVertex3f(100,300,0);
  80. glEnd();
  81.  
  82. // Plano XoZ - chao
  83. glColor4f(YELLOW);
  84. glBegin(GL_QUADS);
  85. glVertex3f(0,0,0);
  86. glVertex3f(0,0,100);
  87. glVertex3f(100,0,100);
  88. glVertex3f(100,0,0);
  89. glEnd();
  90. glPopMatrix();
  91. }
  92.  
  93. void display(void){
  94.  
  95. //================================================================= APaga ecran/profundidade
  96. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
  97.  
  98.  
  99. //================================================================= Não modificar
  100. glViewport (0, 0, wScreen, hScreen);
  101. glMatrixMode(GL_PROJECTION);
  102. glLoadIdentity();
  103. //gluPerspective(angZoom, (float)wScreen/hScreen, 0.1, 3*zC);
  104. glMatrixMode(GL_MODELVIEW);
  105. glLoadIdentity();
  106. gluLookAt(obsP[0], obsP[1], obsP[2], xx, yy, zz, 0, 1, 0);
  107. //================================================================= Não modificar
  108.  
  109. //…………………………………………………………………………………………………………………………………………………………Objectos
  110. drawParedes();
  111.  
  112. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Actualizacao
  113. glutSwapBuffers();
  114. }
  115.  
  116.  
  117. int main(int argc, char** argv){
  118.  
  119. glutInit(&argc, argv);
  120. glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH );
  121. glutInitWindowSize (wScreen, hScreen);
  122. glutInitWindowPosition (300, 100);
  123.  
  124. inicializa();
  125.  
  126. //glutSpecialFunc(teclasNotAscii);
  127. glutDisplayFunc(display);
  128. //glutKeyboardFunc(keyboard);
  129.  
  130. glutMainLoop();
  131.  
  132. return 0;
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement