-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEntity.cpp
More file actions
83 lines (66 loc) · 1.87 KB
/
Copy pathEntity.cpp
File metadata and controls
83 lines (66 loc) · 1.87 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
82
83
#include "Entity.h"
using namespace _Entity;
Entity::Entity(const char* id, glm::vec3 pos) {
this->id = id;
this->position = pos;
matrix = glm::translate(glm::mat4(1.0f), pos);
}
bool Entity::isEqual(Entity e) {
return strcmp(this->id, e.id) == 0;
}
void Entity::add_child(Entity child) {
child.child = true;
children.push_back(child);
// TODO: match up vectors, parent to child
}
// Remove all children matching the given child
void Entity::remove_child(Entity child, bool deep) {
std::vector<Entity>::iterator it;
it = children.begin();
for(int i = 0; i < children.size(); i++) {
if(deep) { children.at(i).remove_child(child, deep); }
if(children.at(i).isEqual(child)) { children.erase(it); }
it++;
}
}
// Removes all children in all current and child nodes
void Entity::remove_children() {
for(Entity e : children) {
e.remove_children();
}
children.clear();
}
glm::mat4 Entity::get_matrix() {
return this->matrix;
}
const glm::vec3 Entity::get_position() const {
return glm::vec3(matrix[3][0], matrix[3][1], matrix[3][2]);
}
void Entity::set_position(glm::vec3 pos) {
this->position = pos;
matrix[3][0] = position.x;
matrix[3][1] = position.y;
matrix[3][2] = position.z;
}
void Entity::transform(glm::mat4 trans) {
matrix *= trans;
for(Entity e : children) { e.transform(trans); }
}
void Entity::translate(glm::vec3 trans) {
matrix = glm::translate(matrix, trans);
for(Entity e : children) { e.translate(trans); }
}
void Entity::rotate(float degrees, glm::vec3 axis) {
matrix = glm::rotate(matrix, glm::radians(degrees), axis);
for(Entity e : children) { e.rotate(degrees, axis); }
}
void Entity::scale(float scale) {
matrix = glm::scale(matrix, glm::vec3(scale));
for(Entity e : children) { e.scale(scale); }
}
void Entity::scale(glm::vec3 scale) {
matrix = glm::scale(matrix, scale);
for(Entity e : children) { e.scale(scale); }
}
Entity::~Entity() {
}