Advertisement
Guest User

Untitled

a guest
Dec 17th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.53 KB | None | 0 0
  1. #include <iostream>
  2. #include <GL/glut.h>
  3.  
  4. static int year = 0, day = 0;
  5.  
  6. // Inicializa parâmetros de rendering
  7. void init(){
  8. glClearColor(0.0, 0.0, 0.0, 0.0);
  9. }
  10.  
  11. //Função Callback chamada para fazer o desenho
  12. void display(){
  13. glClear(GL_COLOR_BUFFER_BIT);
  14. glColor3f(1.0, 1.0, 1.0);
  15.  
  16. glBegin(GL_TRIANGLE_STRIP);
  17. glVertex2f(0.0, 0.0);
  18. glVertex2f(-0.5, 1.);
  19. glVertex2f(0.5, 1.);
  20. glEnd();
  21.  
  22. glBegin(GL_TRIANGLE_STRIP);
  23. glVertex2f(0.0, 0.0);
  24. glVertex2f(-0.5, -1.);
  25. glVertex2f(0.5, -1.);
  26. glEnd();
  27.  
  28. glBegin(GL_TRIANGLE_STRIP);
  29. glVertex2f(0.0, 0.0);
  30. glVertex2f(1, -0.5);
  31. glVertex2f(1, 0.5);
  32. glEnd();
  33.  
  34. glBegin(GL_TRIANGLE_STRIP);
  35. glTranslatef((GLfloat) day, 0,0);
  36. glRotatef((GLfloat) day, .0, 0.0, 1.0);
  37. glVertex2f(0.0, 0.0);
  38. glVertex2f(-1, -0.5);
  39. glVertex2f(-1, 0.5);
  40. glEnd();
  41.  
  42. glLineWidth(3.);
  43. glBegin(GL_LINE_STRIP);
  44. glVertex2f(.0, .0);
  45. glVertex2f(.0, -2.0);
  46. glEnd();
  47.  
  48. // glPushMatrix();
  49. // glRotatef((GLfloat) year, 1.0, 0.0, 0.0);
  50. // glRotatef((GLfloat) day, 0.0, 0.0, 1.0);
  51. // glutWireSphere(1.0, 20, 16); /* Desenha o Sol */
  52. // glPopMatrix();
  53. //
  54. // glPushMatrix();
  55. // glRotatef((GLfloat) year, 0.0, 1.0, 0.0);
  56. // glTranslatef(2.0, -1.0, 0.0); /* Translada a partir do novo sistema de coordenadas resultante da rotação */
  57. // glRotatef((GLfloat) day, 0.0, 1.0, 0.0);
  58. // glutWireSphere(0.2, 10, 8); /* Desenha um planeta */
  59. // glPopMatrix();
  60. //
  61. // /* Criar segundo planeta */
  62. // glPushMatrix();
  63. // glRotatef((GLfloat) year, 0.0, -1.0, 0.0);
  64. // glTranslatef(-2.0, 1.0, 0.0); /* Translada a partir do novo sistema de coordenadas resultante da rotação */
  65. // glRotatef((GLfloat) day, 0.0, 1.0, 0.0);
  66. // glutWireSphere(0.2, 10, 8); /* Desenha um planeta */
  67. // glPopMatrix();
  68.  
  69. glutSwapBuffers();
  70. }
  71.  
  72. void reshape(int w, int h){
  73.  
  74. glViewport(0, 0, (GLsizei) w, (GLsizei) h);
  75.  
  76. glMatrixMode(GL_MODELVIEW);
  77. glLoadIdentity();
  78.  
  79. gluPerspective(60.0, (GLfloat) w/(GLfloat) h, 1.0, 20.0);
  80. gluLookAt(0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); //Posição da Câmera
  81.  
  82. }
  83.  
  84. void keyboard(unsigned char key, int x, int y){
  85.  
  86. switch (key){
  87. case 'd':
  88. day = (day + 10) % 360; //% valor do resto
  89. glutPostRedisplay(); // Redesenha a cena com novas coordenadas, é executado no glutMainLoop;
  90. break;
  91.  
  92. case 'D':
  93. day = (day - 10) % 360;
  94. glutPostRedisplay();
  95. break;
  96.  
  97. case 'y':
  98. year = (year + 5) % 360;
  99. glutPostRedisplay();
  100. break;
  101.  
  102. case 'Y':
  103. year = (year - 5) % 360;
  104. glutPostRedisplay();
  105. break;
  106.  
  107. case 27:
  108. exit(0);
  109. break;
  110.  
  111. default:
  112. break;
  113. }
  114. }
  115.  
  116.  
  117. int main(int argc, char *argv[]) {
  118.  
  119. /* inicializa o sitema GLUT */
  120. glutInit(&argc, argv);
  121.  
  122. glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
  123. glutInitWindowSize(500,500);
  124. glutInitWindowPosition(100,100);
  125. glutCreateWindow("Rotação de planetas");
  126.  
  127. //chama a funcao init e inicia as propriedades View Port
  128. init();
  129. /* Callback para mostrar objetos na tela */
  130. glutDisplayFunc(display);
  131.  
  132. glutReshapeFunc(reshape);
  133.  
  134. glutKeyboardFunc(keyboard);
  135.  
  136. glutMainLoop();
  137.  
  138. return 0;
  139.  
  140. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement