Advertisement
sazzad15

ship.CG

Nov 21st, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.67 KB | None | 0 0
  1. #include <iostream>
  2. #include<GL/gl.h>
  3. #include <GL/glut.h>
  4. using namespace std;
  5.  
  6. float _move = 0.0f;
  7. void drawScene() {
  8. glClear(GL_COLOR_BUFFER_BIT);
  9.  
  10. glLoadIdentity(); //Reset the drawing perspective
  11. glMatrixMode(GL_MODELVIEW);
  12.  
  13. glColor3d(1,0,0);
  14. glPushMatrix();
  15. glTranslatef(_move, 0.0f, 0.0f);
  16. glBegin(GL_QUADS);
  17. glVertex3f(-.80f, -0.1f, 0.0f);
  18. glVertex3f(-.30f, -0.1f, 0.0f);
  19. glVertex3f(-.10f, 0.2f, 0.0f);
  20. glVertex3f(-1.0f, 0.2f, 0.0f);
  21. glEnd();
  22.  
  23. glPopMatrix();
  24.  
  25.  
  26. glColor3d(.87,0.749,0.38);
  27. glPushMatrix();
  28. glTranslatef(_move, 0.0f, 0.0f);
  29. glBegin(GL_QUADS);
  30. glVertex3f(-.50f, 0.2f, 0.0f);
  31. glVertex3f(-.40f, 0.2f, 0.0f);
  32. glVertex3f(-.40f, 0.4f, 0.0f);
  33. glVertex3f(-.50f, 0.4f, 0.0f);
  34. glEnd();
  35.  
  36. glPopMatrix();
  37.  
  38. glColor3d(.87,0.749,0.38);
  39. glPushMatrix();
  40. glTranslatef(_move, 0.0f, 0.0f);
  41. glBegin(GL_QUADS);
  42. glVertex3f(-.70f, 0.2f, 0.0f);
  43. glVertex3f(-.60f, 0.2f, 0.0f);
  44. glVertex3f(-.60f, 0.6f, 0.0f);
  45. glVertex3f(-.70f, 0.6f, 0.0f);
  46. glEnd();
  47.  
  48. glPopMatrix();
  49.  
  50.  
  51.  
  52. glColor3d(.87,0.749,0.38);
  53. glPushMatrix();
  54. glTranslatef(_move, 0.0f, 0.0f);
  55. glBegin(GL_QUADS);
  56. glVertex3f(-.30f, 0.2f, 0.0f);
  57. glVertex3f(-.20f, 0.2f, 0.0f);
  58. glVertex3f(-.20f, 0.3f, 0.0f);
  59. glVertex3f(-.30f, 0.3f, 0.0f);
  60. glEnd();
  61.  
  62. glPopMatrix();
  63.  
  64. glBegin(GL_POLYGON);
  65. glColor3f(0,0,1);
  66. glVertex2i(-1.0f,-1.0f);
  67. glVertex2i(1.0f,-1.0f);
  68. glVertex2i(1.0f,-.50f);
  69. glVertex2i(-1.0f,-.50f);
  70. glEnd();
  71.  
  72.  
  73. glPushMatrix();
  74. glColor3d(.894,.91,.93);
  75. glTranslatef(-0.45f+_move, .45, 0.0);
  76. glutSolidSphere(.01,50,50);
  77. glEnd();
  78. glPopMatrix();
  79.  
  80. glPushMatrix();
  81. glColor3d(.894,.91,.93);
  82. glTranslatef(-0.48f+_move, .52, 0.0);
  83. glutSolidSphere(.015,50,50);
  84. glEnd();
  85. glPopMatrix();
  86.  
  87. glPushMatrix();
  88. glColor3d(.894,.91,.93);
  89. glTranslatef(-0.51f+_move, .59, 0.0);
  90. glutSolidSphere(.02,50,50);
  91. glEnd();
  92. glPopMatrix();
  93.  
  94.  
  95.  
  96. glPushMatrix();
  97. glColor3d(.894,.91,.93);
  98. glTranslatef(-0.65f+_move, .64, 0.0);
  99. glutSolidSphere(.01,50,50);
  100. glEnd();
  101. glPopMatrix();
  102.  
  103. glPushMatrix();
  104. glColor3d(.894,.91,.93);
  105. glTranslatef(-0.68f+_move, .72, 0.0);
  106. glutSolidSphere(.015,50,50);
  107. glEnd();
  108. glPopMatrix();
  109.  
  110. glPushMatrix();
  111. glColor3d(.894,.91,.93);
  112. glTranslatef(-0.7f+_move, .79, 0.0);
  113. glutSolidSphere(.02,50,50);
  114. glEnd();
  115. glPopMatrix();
  116.  
  117.  
  118. glPushMatrix();
  119. glColor3d(.894,.91,.93);
  120. glTranslatef(-0.25f+_move, .35, 0.0);
  121. glutSolidSphere(.01,50,50);
  122. glEnd();
  123. glPopMatrix();
  124.  
  125. glPushMatrix();
  126. glColor3d(.894,.91,.93);
  127. glTranslatef(-0.28f+_move, .42, 0.0);
  128. glutSolidSphere(.015,50,50);
  129. glEnd();
  130. glPopMatrix();
  131.  
  132. glPushMatrix();
  133. glColor3d(.894,.91,.93);
  134. glTranslatef(-0.31f+_move, .49, 0.0);
  135. glutSolidSphere(.02,50,50);
  136. glEnd();
  137. glPopMatrix();
  138.  
  139.  
  140.  
  141. //glFlush(); //Works only on single buffer
  142. glutSwapBuffers();
  143. }
  144.  
  145. void update(int value) {
  146.  
  147. _move += .02;
  148. if(_move-1.3 > 1.0)
  149. {
  150. _move = -1.0;
  151. }
  152. glutPostRedisplay(); //Notify GLUT that the display has changed
  153.  
  154. glutTimerFunc(20, update, 0); //Notify GLUT to call update again in 20 milliseconds
  155. }
  156.  
  157. int main(int argc, char** argv) {
  158. glutInit(&argc, argv);
  159. glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
  160. glutInitWindowSize(800, 800);
  161. glutCreateWindow("Transformation");
  162. glutDisplayFunc(drawScene);
  163. glutTimerFunc(20, update, 0); //Add a timer
  164. glutMainLoop();
  165. return 0;
  166. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement