-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcircle.cpp
91 lines (74 loc) · 2.14 KB
/
circle.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include "circle.hpp"
circle::circle(
glm::vec3 position,
float radius,
glm::vec3 rotation,
glm::vec3 scale,
glm::vec3 offset,
glm::vec4 color
) : node_component(position, rotation, scale, offset, color), radius(radius) {
init_buffers();
}
circle::circle(
glm::vec2 pos,
float radius
) : circle(glm::vec3(pos, 0.0f), radius, ZERO3, ONE3, ZERO3, BLACK) { }
circle::circle(const circle & c) : node_component(c), radius(c.radius) {
init_buffers();
}
std::shared_ptr<component> circle::copy() {
return std::make_shared<circle>(*this);
}
glm::vec3 circle::get_center() {
return this->position();
}
glm::vec3 circle::get_border(glm::vec3 direction) {
if (direction == ZERO3) {
return this->position();
}
return this->position() + glm::normalize(direction) * (this->radius - 3.0f);
}
float circle::get_radius() {
return radius;
}
void circle::set_radius(float radius) {
this->radius = radius;
}
bool circle::hit(glm::vec2 pt) {
return glm::length2(position() - glm::vec3(pt, 0.0f)) <= radius * radius;
}
void circle::drag(glm::vec2 d) {
this->position = this->position() + glm::vec3(d, 0.0f);
}
void circle::apply(std::shared_ptr<circle> animation) {
this->node_component::apply(animation);
for (int chan : animation->radius.get_channels()) {
if (animation->radius[chan]->active) {
this->radius[chan] = animation->radius[chan]->copy();
}
}
}
void circle::calc_vertices() {
vertices = {
{-this->radius, -this->radius, 0.0f},
{ this->radius, -this->radius, 0.0f},
{ this->radius, this->radius, 0.0f},
{-this->radius, this->radius, 0.0f},
};
}
void circle::calc_indices() {
indices = {
0, 1, 2,
2, 3, 0,
};
}
std::shared_ptr<shader> circle::_shader = nullptr;
std::shared_ptr<shader> circle::get_shader() {
return _shader;
}
void circle::bind_uniforms() {
this->get_shader()->set_mat4("model", this->get_model_matrix());
this->get_shader()->set_vec2("center", ZERO2);
this->get_shader()->set_float("radius", this->radius);
this->get_shader()->set_vec4("color", this->color);
}