-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharrow.cpp
More file actions
59 lines (51 loc) · 1.17 KB
/
arrow.cpp
File metadata and controls
59 lines (51 loc) · 1.17 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
#include "arrow.hpp"
arrow::arrow(
glm::vec3 src,
glm::vec3 dst,
float width,
glm::vec4 color
) : line(src, dst, width, color) {
init_buffers();
}
arrow::arrow(
glm::vec2 src,
glm::vec2 dst,
float width
) : arrow(glm::vec3(src, 0.0f), glm::vec3(dst, 0.0f), width, BLACK) { }
arrow::arrow(const arrow & a) : line(a) {
init_buffers();
}
std::shared_ptr<component> arrow::copy() {
return std::make_shared<arrow>(*this);
}
void arrow::calc_vertices() {
float dist = glm::length(dst() - src());
glm::vec3 v = glm::normalize(dst() - src());
if (dist == 0) v = ZERO3;
glm::vec3 perp(v.y, -v.x, 0.0f);
glm::vec3 end = dst() - v * (2 * width());
glm::vec3 bgn;
if (dist <= 2 * width()) {
bgn = end;
} else {
bgn = src();
}
vertices = {
bgn + perp * (width() / 2),
bgn - perp * (width() / 2),
end - perp * (width() / 2),
end - perp * width(),
dst(),
end + perp * width(),
end + perp * (width() / 2),
};
}
void arrow::calc_indices() {
indices = {
0, 1, 2,
2, 6, 0,
2, 3, 4,
2, 4, 6,
4, 5, 6,
};
}