Guest User

Untitled

a guest
Oct 29th, 2016
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.15 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5. #if defined (__APPLE__) || defined(MACOSX)
  6. #include <GLUT/glut.h>
  7. #else
  8. #include <GL/glut.h>
  9. #endif
  10.  
  11. #include "EstruturasDeDados.h"
  12. #include "winGL.h"
  13. #include "trabalho.h"
  14.  
  15. extern GLint wLargura,
  16. wAltura;
  17.  
  18. extern int xRes,
  19. yRes;
  20.  
  21. float Cores[8][3] = { {0.0, 0.0, 0.0},
  22. {1.0, 0.0, 0.0},
  23. {0.0, 1.0, 0.0},
  24. {0.0, 0.0, 1.0},
  25. {1.0, 0.0, 1.0},
  26. {0.0, 1.0, 1.0},
  27. {1.0, 1.0, 0.0},
  28. {0.5, 0.5, 0.5} };
  29.  
  30. /// ***********************************************************************
  31. /// **
  32. /// ***********************************************************************
  33.  
  34. void desenhaLinha(tPonto P0, tPonto P1, eCor c) {
  35.  
  36. glBegin(GL_LINES);
  37. glColor3fv(Cores[c]);
  38. glVertex2f(P0.x, P0.y);
  39. glVertex2f(P1.x, P1.y);
  40. glEnd();
  41. }
  42.  
  43. /// ***********************************************************************
  44. /// **
  45. /// ***********************************************************************
  46.  
  47. void desenhaPonto(tPonto P, eCor c) {
  48.  
  49. glColor3fv(Cores[c]);
  50.  
  51. glBegin(GL_POINTS);
  52. glVertex2f(P.x, P.y);
  53. glEnd();
  54. }
  55.  
  56. /// ***********************************************************************
  57. /// **
  58. /// ***********************************************************************
  59.  
  60. void desenhaQuadrante(tPonto P0, tPonto P1, eCor c) {
  61.  
  62. glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
  63. glColor3fv(Cores[c]);
  64.  
  65. glBegin(GL_QUADS);
  66. glVertex2f(P0.x, P0.y);
  67. glVertex2f(P0.x, P1.y);
  68. glVertex2f(P1.x, P1.y);
  69. glVertex2f(P1.x, P0.y);
  70. glEnd();
  71. glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
  72. }
  73.  
  74. /// ***********************************************************************
  75. /// **
  76. /// ***********************************************************************
  77.  
  78. void desenhaAsteroide(tPonto P0, float raio, eCor c) {
  79.  
  80. #define GRAD2RAD(a) (a) * M_PI / 180.0
  81.  
  82. int i;
  83. tPonto p;
  84.  
  85. glColor3fv(Cores[c]);
  86.  
  87. glBegin(GL_TRIANGLE_FAN);
  88. glVertex2f(P0.x, P0.y);
  89. for (i = 0.0 ; i <= 360.0 ; i += 10.0) {
  90. p.x = P0.x + raio * cos(GRAD2RAD(i));
  91. p.y = P0.y + raio * sin(GRAD2RAD(i));
  92. glVertex2f(p.x, p.y);
  93. }
  94. glEnd();
  95. }
  96.  
  97. /// ***********************************************************************
  98. /// **
  99. /// ***********************************************************************
  100.  
  101. void desenhaNave(tPonto P0, eCor c) {
  102.  
  103. int i;
  104. tPonto p;
  105. float raio = 10.0;
  106.  
  107. glColor3fv(Cores[c]);
  108.  
  109. glBegin(GL_TRIANGLES);
  110. for (i = 0 ; i < 360 ; i += 120) {
  111. p.x = P0.x + raio * cos(GRAD2RAD(i));
  112. p.y = P0.y + raio * sin(GRAD2RAD(i));
  113. glVertex2f(p.x, p.y);
  114. }
  115. glEnd();
  116. }
  117.  
  118. /// ***********************************************************************
  119. /// **
  120. /// ***********************************************************************
  121.  
  122. void initOpenGL () {
  123. glClearColor(0.0, 0.0, 0.0, 0.0);
  124. glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
  125. }
  126.  
  127. /// ***********************************************************************
  128. /// **
  129. /// ***********************************************************************
  130.  
  131. void reshape (int w, int h) {
  132. glViewport(0, 0, (GLsizei) w, (GLsizei) h);
  133. glMatrixMode(GL_PROJECTION);
  134. glLoadIdentity();
  135. glMatrixMode(GL_MODELVIEW);
  136. glLoadIdentity();
  137. gluOrtho2D(0.0, w, 0.0, h);
  138. }
  139.  
  140. /// ***********************************************************************
  141. /// **
  142. /// ***********************************************************************
  143.  
  144. void criaJanela(int argc, char** argv) {
  145.  
  146. glutInit(&argc, argv);
  147. glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);
  148. glutInitWindowSize (wAltura, wLargura);
  149. glutInitWindowPosition (100, 100);
  150. glutCreateWindow ("Jogo Asteroides - Estrutura de Dados");
  151. }
  152.  
  153.  
  154. /// ***********************************************************************
  155. /// **
  156. /// ***********************************************************************
  157.  
  158. void initEventos() {
  159.  
  160. glutDisplayFunc(desenho);
  161. glutKeyboardFunc(teclado);
  162. glutSpecialFunc(tecladoEspecial);
  163. glutReshapeFunc(reshape);
  164. glutMouseFunc(mouse);
  165. glutIdleFunc(idle);
  166.  
  167. glutMainLoop();
  168.  
  169. }
Add Comment
Please, Sign In to add comment