-
Notifications
You must be signed in to change notification settings - Fork 0
/
Line.cpp
61 lines (50 loc) · 1.34 KB
/
Line.cpp
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
#include "Line.h"
Line::Line() {
vertexArray.setPrimitiveType(sf::TrianglesStrip);
lineVertexArray.setPrimitiveType(sf::LinesStrip);
thicc = 3;
color = sf::Color::Red;
}
Line::Line(float thicc, sf::Color color) {
vertexArray.setPrimitiveType(sf::TrianglesStrip);
lineVertexArray.setPrimitiveType(sf::LinesStrip);
this->thicc = thicc;
this->color = color;
}
void Line::addPoint(sf::Vector2f point) {
line.push_back(point);
lineVertexArray.append(sf::Vertex(point,color));
int size = line.size();
if (size > 1) {
sf::Vector2f n = line[size - 1] - line[size - 2];
n /= Norm(n);
sf::Vector2f u = sf::Vector2f(n.y, -n.x);
vertexArray.append(sf::Vertex(u * thicc + line[size - 1], color));
vertexArray.append(sf::Vertex(-u * thicc + line[size - 1], color));
vertexArray.append(sf::Vertex(u * thicc + line[size - 2], color));
vertexArray.append(sf::Vertex(-u * thicc + line[size - 2], color));
}
}
void Line::setThicc(float thicc) {
this->thicc = thicc;
}
void Line::clear() {
line.clear();
vertexArray.clear();
lineVertexArray.clear();
}
std::vector<sf::Vector2f> Line::getLine() {
return line;
}
int Line::getSize() {
return line.size();
}
void Line::draw(sf::RenderWindow &window) {
window.draw(vertexArray);
}
void Line::drawLine(sf::RenderWindow &window) {
window.draw(vertexArray);
}
float Line::getThicc() {
return thicc;
}