Guest User

Untitled

a guest
Jul 21st, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.64 KB | None | 0 0
  1. #include <GL/gl.h>
  2. #include <GL/glu.h>
  3. #include <GL/glut.h>
  4. #include <stdlib.h>
  5. #include <unistd.h>
  6.  
  7. GLfloat PI = 3.1416;
  8.  
  9. GLfloat position = 0.0f;
  10. GLfloat positiony = 0.0f;
  11. GLfloat positionx = 0.0f;
  12. GLfloat speed = 0.1f;
  13.  
  14. void update(int value) {
  15.  
  16. if(position < -14.0)
  17. position = 1.2f;
  18.  
  19. position -= speed;
  20.  
  21. glutPostRedisplay();
  22.  
  23.  
  24. glutTimerFunc(100, update, 0);
  25. }
  26.  
  27. void init()
  28. {
  29. glClearColor(1, 1, 1, 0.0);
  30. // glMatrixMode(GL_PROJECTION | GL_MODELVIEW);
  31. glLoadIdentity();
  32. // glOrtho(-10, 10, -10, 10, -10, 10);
  33. // glOrtho(-14, 14, -17, 17, -10, 10);
  34. gluOrtho2D(-14, 14, -17, 17);
  35. }
  36.  
  37.  
  38. void processSpecialKeys (int key, int mx, int my) {
  39. switch(key){
  40. case GLUT_KEY_LEFT :
  41. positionx-=2.0;
  42. glutPostRedisplay();
  43. break;
  44. case GLUT_KEY_RIGHT :
  45. positionx+=2.0;
  46. glutPostRedisplay();
  47. break;
  48. case GLUT_KEY_UP :
  49. positiony+=2;
  50. glutPostRedisplay();
  51. break;
  52. case GLUT_KEY_DOWN :
  53. positiony-=2;
  54. glutPostRedisplay();
  55. break;
  56. default:
  57. break;
  58. }
  59. }
  60.  
  61. void allQuads()
  62. {
  63. glPushMatrix();
  64. glTranslatef(position,0.0f, 0.0f);
  65. glColor3f(0, 0, 0);
  66. glBegin(GL_QUADS);
  67. glVertex3d(8, 9, 0);
  68. glVertex3d(11, 9, 0);
  69. glVertex3d(11, 0, 0);
  70. glVertex3d(8, 0, 0);
  71. glEnd();
  72.  
  73. glColor3f(0, 0, 0);
  74. glBegin(GL_QUADS);
  75. glVertex3d(5, -7, 0);
  76. glVertex3d(8, -7, 0);
  77. glVertex3d(8, -15, 0);
  78. glVertex3d(5, -15, 0);
  79. glEnd();
  80.  
  81. glColor3f(0, 0, 0);
  82. glBegin(GL_QUADS);
  83. glVertex3d(5, -7, 0);
  84. glVertex3d(8, -7, 0);
  85. glVertex3d(8, -15, 0);
  86. glVertex3d(5, -15, 0);
  87. glEnd();
  88.  
  89. glColor3f(0, 0, 0);
  90. glBegin(GL_QUADS);
  91. glVertex3d(2, 5, 0);
  92. glVertex3d(5, 5, 0);
  93. glVertex3d(5, -5, 0);
  94. glVertex3d(2, -5, 0);
  95. glEnd();
  96.  
  97. glColor3f(0, 0, 0);
  98. glBegin(GL_QUADS);
  99. glVertex3d(-4, -2, 0);
  100. glVertex3d(-1, -2, 0);
  101. glVertex3d(-1, -11, 0);
  102. glVertex3d(-4, -11, 0);
  103. glEnd();
  104.  
  105. glColor3f(0, 0, 0);
  106. glBegin(GL_QUADS);
  107. glVertex3d(-8, 11, 0);
  108. glVertex3d(-5, 11, 0);
  109. glVertex3d(-5, 2, 0);
  110. glVertex3d(-8, 2, 0);
  111. glEnd();
  112. glPopMatrix();
  113.  
  114. }
  115.  
  116. void human()
  117. {
  118. // Body
  119. glPushMatrix();
  120. glTranslatef(positionx, positiony, 0.0f);
  121. glColor3f(1, 0, 0);
  122. glBegin(GL_QUADS);
  123. glVertex3d(-12, -9, 0);
  124. glVertex3d(-9, -9, 0);
  125. glVertex3d(-9, -12, 0);
  126. glVertex3d(-12,-12, 0);
  127. glEnd();
  128.  
  129. // LEG
  130. glColor3f(0, 1, 0);
  131. glBegin(GL_QUADS);
  132. glVertex3d(-10,-12, 0);
  133. glVertex3d(-9, -12, 0);
  134. glVertex3d(-9, -15, 0);
  135. glVertex3d(-10, -15, 0);
  136. glEnd();
  137.  
  138. glColor3f(0, 1, 0);
  139. glBegin(GL_QUADS);
  140. glVertex3d(-12,-12, 0);
  141. glVertex3d(-11, -12, 0);
  142. glVertex3d(-11, -15, 0);
  143. glVertex3d(-12, -15, 0);
  144. glEnd();
  145.  
  146. // Square face
  147. glColor3f(0, 0, 1);
  148. glBegin(GL_QUADS);
  149. glVertex3d(-11,-8, 0);
  150. glVertex3d(-10, -8, 0);
  151. glVertex3d(-10, -9, 0);
  152. glVertex3d(-11, -9, 0);
  153. glEnd();
  154.  
  155. glColor3f(1, 1, 1);
  156. glBegin(GL_LINES);
  157. glVertex3d(-10.3, -8.5, 0);
  158. glVertex3d(-10.6, -8.5, 0);
  159. glEnd();
  160.  
  161. glPopMatrix();
  162. }
  163.  
  164. void display()
  165. {
  166. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  167.  
  168. glPushMatrix();
  169. allQuads();
  170. glPopMatrix();
  171. human();
  172.  
  173. glutSwapBuffers();
  174. // glutPostRedisplay();
  175. glFlush();
  176. }
  177.  
  178. int main(int argc, char** argv)
  179. {
  180. glutInit(&argc, argv);
  181. glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
  182. glutInitWindowSize(3*280, 3*340);
  183. glutCreateWindow("Batman");
  184. init();
  185. glutDisplayFunc(display);
  186. glutTimerFunc(1000, update, 0);
  187. glutSpecialFunc(processSpecialKeys);
  188. glutMainLoop();
  189. return 0;
  190. }
Add Comment
Please, Sign In to add comment