-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstateVisualizer.cpp
More file actions
67 lines (49 loc) · 2.01 KB
/
stateVisualizer.cpp
File metadata and controls
67 lines (49 loc) · 2.01 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
#include "Body.h"
#include "array"
#include <cmath>
#include "iostream"
using namespace sf;
using namespace std;
void State::draw(RenderTarget &target, sf::RenderStates states) const {
const float BODY_SIZEX = 256, BODY_SIZEY = 128,spOffset = 110;
array<Vector2f, 6> rectCoords = {Vector2f(-spOffset, -BODY_SIZEY/2), Vector2f(spOffset, -BODY_SIZEY/2),
Vector2f(-BODY_SIZEX/2, BODY_SIZEY/2),
Vector2f(BODY_SIZEX/2, BODY_SIZEY/2),
Vector2f(-BODY_SIZEX/2, -BODY_SIZEY/2),
Vector2f(BODY_SIZEX/2, -BODY_SIZEY/2)};
for (auto &el: rectCoords) {
float tx = el.x;
float ty = el.y;
el.x = tx * cos(angle) - ty * sin(angle);// x*cos(angle) - y*sin(angle)
el.y = tx * sin(angle) + ty * cos(angle);
}
// array<vector>spCoords = {Vector2f(-spOffset, -sp1Length), Vector2f(spOffset, -sp2Length)};
sf::ConvexShape rect;
rect.setPointCount(4);
rect.setPoint(0,rectCoords[2] + pos);
rect.setPoint(1,rectCoords[3]+ pos);
rect.setPoint(2,rectCoords[5]+ pos);
rect.setPoint(3,rectCoords[4]+pos);
// rect.setPosition(pos);
rect.setFillColor(Color::Yellow);
RectangleShape line1, line2; //springs
// line1.setSize(Vector2f(20, sp1Length));
line1.setSize(Vector2f(20, -sp1Length));
line1.setFillColor(sf::Color::Green);
line1.setPosition(pos+rectCoords[0]);
line1.setRotation(angle * 180.0f/M_PI);
// line2.setSize(Vector2f(20, sp2Length));
line2.setSize(Vector2f(-20, -sp2Length));
line2.setFillColor(sf::Color::Green);
line2.setPosition(pos+rectCoords[1]);
line2.setRotation(angle * 180.0f/M_PI);
// floor
RectangleShape floor;
floor.setSize(Vector2f(10000, -50));
floor.setFillColor(sf::Color::Magenta);
floor.setPosition(Vector2f(-500, 50));
target.draw(rect, states);
target.draw(line1, states);
target.draw(line2, states);
target.draw(floor,states);
}