-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
81 lines (63 loc) · 1.85 KB
/
main.cpp
File metadata and controls
81 lines (63 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <iostream>
#include <SFML/Graphics.hpp>
#include "Body.h"
#include "RungeeKutta4.h"
using namespace std;
int main() {
sf::RenderWindow window(sf::VideoMode(800, 600), "Springs =_=");
sf::View view = window.getDefaultView();
view.setSize(800, -600);
window.setView(view);
const float h = 0.05;
State state;
state.pos = Vector2f(400, 200);
state.sp1Length = 80;
state.sp2Length = 80;
Body body;
RungeeKutta4 rg4;
window.setFramerateLimit(144);
while (window.isOpen())
{
// Process events
sf::Event event;
while (window.pollEvent(event))
{
// Close window: exit
if (event.type == sf::Event::Closed)
window.close();
if (event.type == sf::Event::KeyPressed)
{
if (event.key.code == sf::Keyboard::A)
{
state.w += 0.01;
}
if (event.key.code == sf::Keyboard::D)
{
state.w += -0.01;
}
if (event.key.code == sf::Keyboard::W)
{
state.speed.x += 5;
}
if (event.key.code == sf::Keyboard::S)
{
state.speed.x -= 5;
}
if (event.key.code == sf::Keyboard::Space)
{
state.speed.x = 0;
}
}
}
State dx;
dx = rg4.solve(body, state, h); // body - это объект содержащий функцию f(), state - состояние системы и h шаг.
state.add(dx);
// Clear screen
window.clear();
// Draw the sprite
window.draw(state);
// Update the window
window.display();
}
return 0;
}