Advertisement
Guest User

Untitled

a guest
Dec 1st, 2015
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.89 KB | None | 0 0
  1. #include <GL/glut.h> /*??? Linux ? Windows*/
  2. #include <stdio.h>
  3. #include <math.h>
  4. float a = 0;
  5.  
  6.  
  7. void reshape(int w, int h)
  8. {
  9. glViewport(0, 0, w, h);
  10.  
  11. glMatrixMode(GL_PROJECTION);
  12. glLoadIdentity();
  13. gluOrtho2D(0, w, 0, h);
  14.  
  15. glMatrixMode(GL_MODELVIEW);
  16. glLoadIdentity();
  17. }
  18.  
  19. float xi0 = 20, xi = 0;
  20. float yi0 = 4, yi = 0;
  21. float vx0 = 0, vy0 =40;
  22. float t = 0;
  23. float ax[2][2]={{0, 10},{10, 10}};
  24. float ay[2][2]={{0,-5},{10, -30}};
  25. int akold = 0;
  26. int abold = 0;
  27. void display()
  28. {
  29. //glClear(GL_COLOR_BUFFER_BIT);
  30. glLoadIdentity();
  31.  
  32. glTranslatef(400, 400, 0);
  33. glPointSize(1);
  34. glLineWidth(1);
  35. int ak1 = xi/100;
  36. int ab1 = yi/100;
  37.  
  38. if((ak1 != akold) || (ab1 != abold)){
  39. xi0 = xi;
  40. yi0 = yi;
  41. vx0 = vx0 + ax[ak1][ab1]*t;
  42. vy0 = vy0 + ay[ak1][ab1]*t;
  43. t = 0;
  44. akold = ak1;
  45. abold = ab1;
  46. }
  47. printf("%d %d\n", ak1,ab1);
  48.  
  49. xi = xi0 + vx0*t + ax[ak1][ab1]*t*t/2.0;
  50. yi = yi0 + vy0*t + ay[ak1][ab1]*t*t/2.0;
  51. glBegin(GL_POINTS);
  52. glColor3d(1,1,0);
  53. glVertex3d(xi,yi,0);
  54. glEnd();
  55. glBegin(GL_LINES);
  56. glColor3d(0,1,0);
  57.  
  58.  
  59. glVertex3d(0,0,0);
  60. glVertex3d(200,0,0);
  61.  
  62. glColor3d(0,1,0);
  63.  
  64. glVertex3d(0,100,0);
  65. glVertex3d(200,100,0);
  66.  
  67. glColor3d(0,1,0);
  68.  
  69.  
  70. glVertex3d(0,200,0);
  71. glVertex3d(200,200,0);
  72.  
  73. glColor3d(0,1,0);
  74. glVertex3d(0,0,0);
  75. glVertex3d(0,200,0);
  76. glColor3d(0,1,0);
  77.  
  78.  
  79. glVertex3d(100,0,0);
  80. glVertex3d(100,200,0);
  81.  
  82. glColor3d(0,1,0);
  83.  
  84. glVertex3d(200,0,0);
  85. glVertex3d(200,200,0);
  86.  
  87.  
  88.  
  89.  
  90. glEnd();
  91. t+=0.01;
  92. glutSwapBuffers();
  93.  
  94. }
  95.  
  96. int main (int argc, char * argv[])
  97. {
  98.  
  99. glutInit(&argc, argv);
  100. glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA);
  101.  
  102. glutInitWindowSize(800, 600);
  103. glutCreateWindow("OpenGL lesson 1");
  104.  
  105. glutReshapeFunc(reshape);
  106. glutDisplayFunc(display);
  107.  
  108. glutIdleFunc(display);
  109.  
  110. glutMainLoop();
  111.  
  112. return 0;
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement