Advertisement
Guest User

Untitled

a guest
Dec 10th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. /*
  2. * Desafio: verificar o modelview
  3. */
  4.  
  5. #include <iostream>
  6. #include <GL/freeglut.h>
  7.  
  8. static int year = 0, day = 0;
  9.  
  10. void init (void)
  11. {
  12. /* selecionar cor de fundo (preto) */
  13. glClearColor(0.0, 0.0, 0.0, 0.0);
  14. //Definindo os limites da Porta de Visao (ViewPort)
  15.  
  16. }
  17.  
  18. //desenha as transformacoes
  19. void display(void){
  20. glClear(GL_COLOR_BUFFER_BIT);
  21. glColor3f(1.0, 1.0, 1.0);
  22.  
  23. glPushMatrix(); //Sun
  24. glRotatef(year, 1.0, 0.0, 0.0);
  25. glRotatef(day, 0.0, 0.0, 1.0);
  26. glutWireSphere(1.0, 20, 16);
  27. glPopMatrix();
  28.  
  29. glPushMatrix();// Planet 1
  30. glRotatef(year, 0.0, 1.0, 0.0);
  31. glTranslatef(2.0, 0.0, 0.0);
  32. glRotatef(day, 0.0, 1.0, 0.0);
  33. glutWireSphere(0.2, 10, 8);
  34. glPopMatrix();
  35.  
  36. glPushMatrix(); // Planet 2
  37. glRotatef(year, 0.0, 1.0, 0.0);
  38. glTranslatef(4.0, 0.0, 0.0);
  39. glRotatef(day, 0.0, 1.0, 0.0);
  40. glutWireSphere(0.2, 10, 8);
  41. glPopMatrix();
  42.  
  43. glPushMatrix(); // Moon 1
  44. glRotatef(year, 0.0, 1.0, 0.0);
  45. glTranslatef(4.0, 0.0, 0.0);
  46. glRotatef(day*0.1, 0.0, 1.0, 0.0);
  47. glTranslatef(0.5, 0.0, 0.0);
  48. glutWireSphere(0.1, 10, 8);
  49. glPopMatrix();
  50.  
  51. glPushMatrix(); // Moon 2
  52. glRotatef(year, 0.0, 1.0, 0.0);
  53. glTranslatef(4.0, 0.0, 0.0);
  54. glRotatef(day*0.1, 0.0, 0, 1.0);
  55. glTranslatef(0.5, 0.0, 0.0);
  56. glutWireSphere(0.1, 10, 8);
  57. glPopMatrix();
  58.  
  59.  
  60. glutSwapBuffers();
  61. }
  62.  
  63. void keyboard(unsigned char key, int x, int y) {
  64. switch (key) {
  65. case 'd':
  66. day = (day + 10) % 360;
  67. glutPostRedisplay();
  68. break;
  69. case 'D':
  70. day = (day - 10) % 360;
  71. glutPostRedisplay();
  72. break;
  73. case 'y':
  74. year = (year + 5) % 360;
  75. glutPostRedisplay();
  76. break;
  77. case 'Y':
  78. year = (year - 5) % 360;
  79. glutPostRedisplay();
  80. break;
  81. case 27:
  82. exit(0);
  83. break;
  84. default:
  85. break;
  86.  
  87. }
  88. }
  89.  
  90. void reshape(int w, int h){
  91. glViewport (0, 0, w, h);
  92. glMatrixMode(GL_MODELVIEW);
  93. glLoadIdentity();
  94. gluPerspective(120.0, w/h, 1.0, 20.0);
  95. gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
  96. }
  97.  
  98. void update(int value){
  99. glutTimerFunc(10, update, 1);
  100. day += year++;
  101. glutPostRedisplay();
  102. }
  103.  
  104.  
  105. int main(int argc, char** argv) {
  106.  
  107. /* inicializa o sitema GLUT */
  108. glutInit(&argc, argv);
  109.  
  110. glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
  111. glutInitWindowSize(1000,1000);
  112. glutInitWindowPosition(100, 100);
  113. glutCreateWindow("Rotação de Planetas");
  114.  
  115. //chama a funcao init e inicia as propriedades View Port
  116. init();
  117. glutDisplayFunc(display);
  118. glutTimerFunc(10, update, 1);
  119. glutReshapeFunc(reshape);
  120. glutKeyboardFunc(keyboard);
  121. glutMainLoop();
  122.  
  123. return 0;
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement