Advertisement
SIKER_98

123123

Feb 3rd, 2020
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. #include <glut.h>
  2.  
  3. GLfloat rotObsY = 20.0;
  4. GLfloat rotObsX = 20.0;
  5.  
  6.  
  7. void rys() {
  8. glScalef(10, 10, 10);
  9. glBegin(GL_QUADS);
  10.  
  11. glColor3f(0, 0, 0);
  12. glVertex3f(0, 0, 0);
  13. glColor3f(1, 0, 0);
  14. glVertex3f(1, 0, 0);
  15. glColor3f(1, 1, 0);
  16. glVertex3f(1, 1, 0);
  17. glColor3f(0, 1, 0);
  18. glVertex3f(0, 1, 0);
  19.  
  20. glColor3f(0, 0, 0);
  21. glVertex3f(0, 0, 0);
  22. glColor3f(1, 0, 0);
  23. glVertex3f(1, 0, 0);
  24. glColor3f(1, 0, 1);
  25. glVertex3f(1, 0, 1);
  26. glColor3f(0, 0, 1);
  27. glVertex3f(0, 0, 1);
  28.  
  29. glColor3f(0, 0, 0);
  30. glVertex3f(0, 0, 0);
  31. glColor3f(0, 1, 0);
  32. glVertex3f(0, 1, 0);
  33. glColor3f(0, 1, 1);
  34. glVertex3f(0, 1, 1);
  35. glColor3f(0, 0, 1);
  36. glVertex3f(0, 0, 1);
  37.  
  38. glColor3f(1, 1, 1);
  39. glVertex3f(1, 1, 1);
  40. glColor3f(1, 1, 0);
  41. glVertex3f(1, 1, 0);
  42. glColor3f(0, 1, 0);
  43. glVertex3f(0, 1, 0);
  44. glColor3f(0, 1, 1);
  45. glVertex3f(0, 1, 1);
  46.  
  47. glColor3f(1, 1, 1);
  48. glVertex3f(1, 1, 1);
  49. glColor3f(1, 0, 1);
  50. glVertex3f(1, 0, 1);
  51. glColor3f(1, 0, 0);
  52. glVertex3f(1, 0, 0);
  53. glColor3f(1, 1, 0);
  54. glVertex3f(1, 1, 0);
  55.  
  56. glColor3f(1, 1, 1);
  57. glVertex3f(1, 1, 1);
  58. glColor3f(1, 0, 1);
  59. glVertex3f(1, 0, 1);
  60. glColor3f(0, 0, 1);
  61. glVertex3f(0, 0, 1);
  62. glColor3f(0, 1, 1);
  63. glVertex3f(0, 1, 1);
  64. glEnd();
  65. }
  66.  
  67. void WyswietlObraz(void)
  68. {
  69.  
  70. glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
  71. glPushMatrix();
  72. glTranslatef(0, 0, -40);
  73. glRotatef(rotObsX, 1, 0, 0);
  74. glRotatef(rotObsY,0,1,0);
  75.  
  76. rys();
  77.  
  78. glPopMatrix();
  79. glutSwapBuffers();
  80. }
  81.  
  82.  
  83. void UstawParametryWidoku(int szerokosc, int wysokosc)
  84. {
  85. glViewport(0, 0, szerokosc, wysokosc);
  86. glMatrixMode(GL_PROJECTION);
  87. glLoadIdentity();
  88. gluPerspective(40.0, (float)szerokosc/(float)wysokosc, 1.0, 1000.0);
  89. glMatrixMode(GL_MODELVIEW);
  90. glLoadIdentity();
  91. }
  92.  
  93. void ObslugaKlawiszySpecjalnych(int klawisz, int x, int y)
  94. {
  95. switch(klawisz)
  96. {
  97. case GLUT_KEY_UP:
  98. rotObsX = rotObsX + 1.0;
  99. break;
  100.  
  101. case GLUT_KEY_DOWN:
  102. rotObsX =rotObsX - 1.0;
  103. break;
  104.  
  105. case GLUT_KEY_LEFT:
  106. rotObsY = rotObsY - 1.0;
  107. break;
  108.  
  109. case GLUT_KEY_RIGHT:
  110. rotObsY = rotObsY + 1.0 ;
  111. break;
  112. }
  113. }
  114.  
  115. int main(int argc, char **argv)
  116. {
  117. glutInit(&argc, argv);
  118. glutInitDisplayMode (GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH);
  119. glutInitWindowPosition(100, 100);
  120. glutInitWindowSize(1000, 900);
  121. glutCreateWindow("Robot");
  122. glEnable(GL_DEPTH_TEST);
  123. glDepthFunc(GL_LEQUAL);
  124. glClearDepth(1000.0);
  125.  
  126. glClearColor (0.0, 0.5, 0.5, 0.5);
  127.  
  128. glutDisplayFunc(WyswietlObraz);
  129. glutReshapeFunc(UstawParametryWidoku);
  130. glutIdleFunc(WyswietlObraz);
  131. glutSpecialFunc(ObslugaKlawiszySpecjalnych);
  132. glutMainLoop();
  133.  
  134. return 0;
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement