-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathObject.cpp
More file actions
82 lines (71 loc) · 1.62 KB
/
Object.cpp
File metadata and controls
82 lines (71 loc) · 1.62 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
#include "Object.h"
#include <iostream>
using namespace std;
Object::Object(Mesh* mesh, vec3 position, mat4 rotation)
{
this->mesh = mesh;
this->position = position;
this->rotation = rotation;
}
Object::~Object()
{
for (vector<Object*>::iterator it = children.begin(); it!=children.end(); ++it)
{
delete (*it);
}
}
void Object::render(mat4 model)
{
model = model * translate(position) * rotation;
if(mesh)
mesh->render(model);
for (vector<Object*>::iterator it = children.begin(); it!=children.end(); ++it)
{
(*it)->render(model);
}
}
void Object::setParent(Object* parent)
{
if(parent == NULL) return;
if(this->parent == parent) return;
this->parent = parent;
parent->addChild(this);
}
void Object::addChild(Object* child)
{
vector<Object*>::iterator it;
it = std::find(children.begin(), children.end(), child);
if(it == children.end())
{
children.push_back(child);
child->setParent(this);
}
}
void Object::unsetParent()
{
if(parent == NULL) return;
Object* p = parent;
parent = NULL;
p->removeChild(this);
}
void Object::removeChild(Object* child)
{
vector<Object*>::iterator it;
it = find(children.begin(), children.end(), child);
if(it != children.end())
{
Object* found = *it;
children.erase(it);
found->unsetParent();
}
}
vector<Object*> Object::getChildren()
{
//return vector<Object*>(children);
return children;
}
vec3 Object::getPosition() { return position; }
mat4 Object::getRotation() { return rotation; }
void Object::setPosition(vec3 position) {this->position = position;}
void Object::setRotation(mat4 rotation) {this->rotation = rotation;}
Mesh* Object::getMesh() { return mesh; }