-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathActor.cpp
98 lines (74 loc) · 2.16 KB
/
Actor.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
92
93
94
95
96
97
98
#include "Actor.h"
#include "MatrixFactory.h"
Actor & Actor::getParent() {
if (this->isRoot()) {
return *this;
}
return *this->parent;
}
bool Actor::isRoot() const {
return nullptr == this->parent;
}
std::shared_ptr<Actor> Actor::operator[](const size_t i) {
if (i >= this->children.size()) {
return nullptr;
}
return this->children[i];
}
Actor::Iterator Actor::begin() {
return this->children.begin();
}
Actor::Iterator Actor::end() {
return this->children.end();
}
Actor::ConstIterator Actor::begin() const {
return this->children.begin();
}
Actor::ConstIterator Actor::end() const {
return this->children.end();
}
Actor & Actor::setTransform(const Transform & transform) {
this->transform = transform;
return *this;
}
const Transform & Actor::getTransform() const {
return this->transform;
}
const Transform Actor::getWorldTransform() const {
if (this->isRoot()) {
return this->transform;
}
return Transform(this->parent->getWorldTransform()).pushPre(this->transform);
}
const Matrix4f Actor::getWorldMatrix() const {
if (this->isRoot()) {
return this->transform.getMatrix();
}
return this->parent->getWorldMatrix() * this->transform.getMatrix();
}
const Matrix4f Actor::getInvWorldMatrix() const {
if (this->isRoot()) {
return this->transform.getInvMatrix();
}
return this->transform.getInvMatrix() * this->parent->getInvWorldMatrix();
}
const Vector3f Actor::transformPointToWorld(const Vector3f & point) const {
return (this->getWorldMatrix() * Vector4f(point, 1)).xyz();
}
const Vector3f Actor::invTransformPointToWorld(const Vector3f & point) const {
return (this->getInvWorldMatrix() * Vector4f(point, 1)).xyz();
}
const Vector3f Actor::transformDirectionToWorld(const Vector3f & direction) const {
return (this->getWorldMatrix() * Vector4f(direction, 0)).xyz();
}
const Vector3f Actor::invTransformDirectionToWorld(const Vector3f & direction) const {
return (this->getInvWorldMatrix() * Vector4f(direction, 0)).xyz();
}
const Vector3f Actor::getWorldPosition() const {
return this->transformPointToWorld(Vector3f::zeroVector());
}
Actor::Component::~Component() {
}
Actor & Actor::Component::getOwner() const {
return *this->owner;
}