Guest User

trabalho.c

a guest
Oct 29th, 2016
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.23 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <stdbool.h>
  4. #include <time.h>
  5. #include <math.h>
  6.  
  7. #if defined (__APPLE__) || defined(MACOSX)
  8. #include <GLUT/glut.h>
  9. #else
  10. #include <GL/glut.h>
  11. #endif
  12.  
  13. #include "EstruturasDeDados.h"
  14. #include "winGL.h"
  15.  
  16. int wLargura = 500,
  17. wAltura = 500;
  18.  
  19. tPonto nuvemAsteroides[10];
  20. tPonto navePos;
  21. bool mostraNave = true,
  22. animacao = false,
  23. linha = false,
  24. desenhaQuad = false;
  25.  
  26. /// ***********************************************************************
  27. /// **
  28. /// ***********************************************************************
  29.  
  30. void temporizar(int v) {
  31.  
  32. navePos.x -= 5;
  33. if (navePos.x < 0)
  34. navePos.x = wLargura;
  35.  
  36. navePos.y -= 2;
  37. if (navePos.y < 0 )
  38. navePos.y = wAltura;
  39.  
  40. glutPostRedisplay();
  41. }
  42.  
  43. /// ***********************************************************************
  44. /// **
  45. /// ***********************************************************************
  46.  
  47. void idle() {
  48.  
  49. if (animacao) {
  50.  
  51. navePos.x += 3;
  52. if (navePos.x > wLargura)
  53. navePos.x = 0;
  54.  
  55. navePos.y += 1;
  56. if (navePos.y > wAltura)
  57. navePos.y = 0;
  58.  
  59. glutPostRedisplay();
  60. }
  61. }
  62.  
  63. /// ***********************************************************************
  64. /// **
  65. /// ***********************************************************************
  66.  
  67. void tecladoEspecial(int key, int x, int y) {
  68. switch (key) {
  69. case GLUT_KEY_UP : // setas do teclado
  70. break;
  71. case GLUT_KEY_DOWN : // setas do teclado
  72. break;
  73. case GLUT_KEY_LEFT : // setas do teclado
  74. break;
  75. case GLUT_KEY_RIGHT : // setas do teclado
  76. break;
  77. }
  78. glutPostRedisplay();
  79. }
  80.  
  81. /// ***********************************************************************
  82. /// **
  83. /// ***********************************************************************
  84.  
  85. void teclado(unsigned char key, int x, int y) {
  86. switch (key) {
  87. case 27 : exit(0);
  88. break;
  89.  
  90. case 'l' :
  91. case 'L' : linha = !linha;
  92. break;
  93.  
  94. case 'q' :
  95. case 'Q' : desenhaQuad = !desenhaQuad;
  96. break;
  97.  
  98. case 'n' :
  99. case 'N' : mostraNave = !mostraNave;
  100. break;
  101.  
  102. case 'R' :
  103. case 'r' : animacao = !animacao;
  104. break;
  105.  
  106. case 't' :
  107. case 'T' : glutTimerFunc( 500, temporizar, 1);
  108. break;
  109. }
  110. glutPostRedisplay();
  111. }
  112.  
  113. /// ***********************************************************************
  114. /// **
  115. /// ***********************************************************************
  116.  
  117. void mouse(int button, int button_state, int x, int y ) {
  118.  
  119. if (button_state == GLUT_DOWN ) {
  120. switch (button) {
  121.  
  122. case GLUT_LEFT_BUTTON : printf("LEFT\n"); // faz alguma coisa quando o botao esquerdo for pressionado
  123. break;
  124.  
  125. case GLUT_RIGHT_BUTTON : printf("RIGHT\n"); // faz alguma coisa quando o botao direito for pressionado
  126. break;
  127. }
  128. glutPostRedisplay();
  129. }
  130. }
  131.  
  132. /// ***********************************************************************
  133. /// **
  134. /// ***********************************************************************
  135.  
  136. void desenho(void) {
  137.  
  138. int i;
  139. tPonto max = { wLargura, wLargura };
  140. tPonto min = { 0, 0 };
  141. tPonto medio = { wLargura/2.0 , wLargura/2.0 };
  142. tPonto medio2 = { 0.0 , wLargura/2.0 };
  143.  
  144. glClear(GL_COLOR_BUFFER_BIT);
  145.  
  146. if (mostraNave)
  147. desenhaNave(navePos, RED);
  148.  
  149. if (linha) {
  150. desenhaLinha(min, medio, BLUE);
  151. desenhaLinha(medio2, max, BLUE);
  152. }
  153.  
  154. for (i = 0 ; i < 10 ; i++)
  155. desenhaAsteroide(nuvemAsteroides[i], 10.0, RED);
  156.  
  157. if (desenhaQuad) {
  158. desenhaQuadrante(min, medio, GRAY);
  159. desenhaQuadrante(medio, max, GRAY);
  160. }
  161.  
  162. glutSwapBuffers();
  163. }
  164.  
  165. /// ***********************************************************************
  166. /// **
  167. /// ***********************************************************************
  168.  
  169. int main(int argc, char** argv) {
  170.  
  171. int i;
  172.  
  173. srand ( time(NULL) );
  174.  
  175. for (i = 0 ; i < 10 ; i++) {
  176. nuvemAsteroides[i].x = rand() % wLargura;
  177. nuvemAsteroides[i].y = rand() % wAltura;
  178. }
  179. navePos.x = wLargura / 2.0;
  180. navePos.y = wAltura / 2.0;
  181.  
  182. criaJanela(argc, argv);
  183.  
  184. initOpenGL();
  185.  
  186. initEventos();
  187.  
  188. return 0;
  189. }
Add Comment
Please, Sign In to add comment