Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SFML/Graphics.hpp>
- #include <cmath>
- #include <math.h>
- #include <time.h>
- #define W 800 //szerokosc okna
- #define H 600 //wysokosc okna
- #define D 10 //odleglosc szerokosci okna od obszaru matematycznego z kazdej strony
- int main()
- {
- float R; //Range - odleglosc od (0,0) do celu pocisku
- float T; //Travel time - czas lotu
- float y, x; // Wysokosc, szerokosc ukladu matematycznego
- float ym, xm; // -||- maksymalne
- float ax, ay, bx, by;
- float t=0;
- float phi;
- float v;
- float g=9.81;
- phi=45*M_PI/180; //kat w radianach
- R=(pow(v,2)*sin(2*phi))/g;
- T=(2*v*sin(phi))/g;
- xm=R;
- ym=R;
- bx=D;
- by=H-D;
- ax=(W-D-bx)/xm;
- ay=(D-by)/ym;
- sf::VertexArray punkty(sf::Points);
- // Create the main window
- sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
- sf::VertexArray lines(sf::LinesStrip,5);
- lines[0].position = sf::Vector2f(D, D);
- lines[1].position = sf::Vector2f(W-D, D);
- lines[2].position = sf::Vector2f(W-D, H-D);
- lines[3].position = sf::Vector2f(D, H-D);
- lines[4].position = sf::Vector2f(D, D);
- //float g=9.81;
- // Start the game loop#include <SFML/Graphics.hpp>
- #include <cmath>
- #include <math.h>
- #include <time.h>
- #define W 800 //szerokosc okna
- #define H 600 //wysokosc okna
- #define D 10 //odleglosc szerokosci okna od obszaru matematycznego z kazdej strony
- float R; //Range - odleglosc od (0,0) do celu pocisku
- float T; //Travel time - czas lotu
- float y, x; // Wysokosc, szerokosc ukladu matematycznego
- float ym, xm; // -||- maksymalne
- float ax, ay, bx, by;
- float t=0;
- float phi;
- float v;
- float g=9.81;
- int main()
- {
- phi=45*M_PI/180; //kat w radianach
- R=(pow(v,2)*sin(2*phi))/g;
- T=(2*v*sin(phi))/g;
- xm=R;
- ym=R;
- bx=D;
- by=H-D;
- ax=(W-D-bx)/xm;
- ay=(D-by)/ym;
- sf::VertexArray punkty(sf::Points);
- // Create the main window
- sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
- sf::VertexArray lines(sf::LinesStrip,5);
- lines[0].position = sf::Vector2f(D, D);
- lines[1].position = sf::Vector2f(W-D, D);
- lines[2].position = sf::Vector2f(W-D, H-D);
- lines[3].position = sf::Vector2f(D, H-D);
- lines[4].position = sf::Vector2f(D, D);
- float g=9.81;
- // Start the game loop
- while (window.isOpen())
- {
- if(t<=T){
- x=v*t*cos(phi);
- y=v*t*sin(phi)-(0.5*g*pow(t,2));
- punkty.append(sf::Vector2f(ax*x+bx,ay*y+by));
- }
- // Process events
- sf::Event event;
- while (window.pollEvent(event))
- {
- // Close window : exit
- if (event.type == sf::Event::Closed)
- window.close();
- }
- // Clear screen
- window.clear();
- window.draw(lines);
- window.draw(punkty);
- // Update the window
- window.display();
- t+=0.05;
- }
- return EXIT_SUCCESS;
- }
Add Comment
Please, Sign In to add comment