Strzyk

Pocisk

Jan 25th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 KB | None | 0 0
  1. #include <SFML/Graphics.hpp>
  2. #include <cmath>
  3. #include <math.h>
  4. #include <time.h>
  5. #define W 800 //szerokosc okna
  6. #define H 600 //wysokosc okna
  7. #define D 10 //odleglosc szerokosci okna od obszaru matematycznego z kazdej strony
  8.  
  9. int main()
  10. {
  11.  
  12.  
  13. float R; //Range - odleglosc od (0,0) do celu pocisku
  14. float T; //Travel time - czas lotu
  15.  
  16. float y, x; // Wysokosc, szerokosc ukladu matematycznego
  17. float ym, xm; // -||- maksymalne
  18. float ax, ay, bx, by;
  19. float t=0;
  20.  
  21. float phi;
  22. float v;
  23. float g=9.81;
  24.  
  25.  
  26.  
  27. phi=45*M_PI/180; //kat w radianach
  28. R=(pow(v,2)*sin(2*phi))/g;
  29. T=(2*v*sin(phi))/g;
  30. xm=R;
  31. ym=R;
  32. bx=D;
  33. by=H-D;
  34. ax=(W-D-bx)/xm;
  35. ay=(D-by)/ym;
  36.  
  37.  
  38. sf::VertexArray punkty(sf::Points);
  39.  
  40.  
  41. // Create the main window
  42. sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
  43.  
  44. sf::VertexArray lines(sf::LinesStrip,5);
  45. lines[0].position = sf::Vector2f(D, D);
  46. lines[1].position = sf::Vector2f(W-D, D);
  47. lines[2].position = sf::Vector2f(W-D, H-D);
  48. lines[3].position = sf::Vector2f(D, H-D);
  49. lines[4].position = sf::Vector2f(D, D);
  50.  
  51. //float g=9.81;
  52.  
  53. // Start the game loop#include <SFML/Graphics.hpp>
  54. #include <cmath>
  55. #include <math.h>
  56. #include <time.h>
  57. #define W 800 //szerokosc okna
  58. #define H 600 //wysokosc okna
  59. #define D 10 //odleglosc szerokosci okna od obszaru matematycznego z kazdej strony
  60.  
  61. float R; //Range - odleglosc od (0,0) do celu pocisku
  62. float T; //Travel time - czas lotu
  63.  
  64. float y, x; // Wysokosc, szerokosc ukladu matematycznego
  65. float ym, xm; // -||- maksymalne
  66. float ax, ay, bx, by;
  67. float t=0;
  68.  
  69. float phi;
  70. float v;
  71. float g=9.81;
  72.  
  73.  
  74. int main()
  75. {
  76.  
  77. phi=45*M_PI/180; //kat w radianach
  78. R=(pow(v,2)*sin(2*phi))/g;
  79. T=(2*v*sin(phi))/g;
  80. xm=R;
  81. ym=R;
  82. bx=D;
  83. by=H-D;
  84. ax=(W-D-bx)/xm;
  85. ay=(D-by)/ym;
  86.  
  87.  
  88. sf::VertexArray punkty(sf::Points);
  89.  
  90.  
  91. // Create the main window
  92. sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
  93.  
  94. sf::VertexArray lines(sf::LinesStrip,5);
  95. lines[0].position = sf::Vector2f(D, D);
  96. lines[1].position = sf::Vector2f(W-D, D);
  97. lines[2].position = sf::Vector2f(W-D, H-D);
  98. lines[3].position = sf::Vector2f(D, H-D);
  99. lines[4].position = sf::Vector2f(D, D);
  100.  
  101. float g=9.81;
  102.  
  103. // Start the game loop
  104. while (window.isOpen())
  105. {
  106.  
  107. if(t<=T){
  108. x=v*t*cos(phi);
  109. y=v*t*sin(phi)-(0.5*g*pow(t,2));
  110. punkty.append(sf::Vector2f(ax*x+bx,ay*y+by));
  111.  
  112. }
  113.  
  114.  
  115.  
  116. // Process events
  117. sf::Event event;
  118. while (window.pollEvent(event))
  119. {
  120. // Close window : exit
  121. if (event.type == sf::Event::Closed)
  122. window.close();
  123. }
  124.  
  125. // Clear screen
  126. window.clear();
  127.  
  128. window.draw(lines);
  129. window.draw(punkty);
  130.  
  131. // Update the window
  132. window.display();
  133. t+=0.05;
  134. }
  135.  
  136. return EXIT_SUCCESS;
  137. }
Add Comment
Please, Sign In to add comment