-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathObject.h
More file actions
141 lines (122 loc) · 2.89 KB
/
Copy pathObject.h
File metadata and controls
141 lines (122 loc) · 2.89 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#pragma once
#include "auxiliary.h"
#include "Mesh.h"
#include "Component.h"
using namespace glm;
namespace violet {
/*Objects are the fundamental objects in Violet that represent a node in scene.
They do not accomplish much in themselves but they act as containers for Components,
which implement the real functionality.
For example, You can control a Object with keyboard by add a control component to the Object.*/
class Object;
typedef shared_ptr<Object> ObjPtr;
typedef list<ObjPtr> ObjList;
class Object:public enable_shared_from_this<Object> {
friend class Scene;
protected:
//The relative information to father
strList _tags;
string _name;
ComList _coms;
vec3 _posi;
vec3 _scaler;
vec3 _rotate;
vec3 _forward;
vec3 _up;
vec3 _right;
list<ObjPtr> _childs;
ObjPtr _parent;
MeshPtr _mesh;
bool _dirty;
bool _visible;
bool _shadow;
mat4 localToParent();
virtual void setParent(const ObjPtr&obj) {
_parent = obj;
}
virtual void insertChild(const ObjPtr&obj) {
_childs.push_back(obj);
obj->setParent(shared_from_this());
}
public:
virtual void update() {
for (auto &com : _coms) {
com->update();
}
}
virtual void addComponent(ComPtr&com) {
com->_owner = shared_from_this();
_coms.push_back(std::move(com));
}
virtual vec3 getForward();
virtual vec3 getUp();
virtual vec3 getRight();
virtual void setMesh(const MeshPtr&mesh) {
_mesh = mesh;
}
virtual MeshPtr getMesh() {
return _mesh;
}
virtual void loadMesh(const string&file) {
if (_mesh.get())_mesh->clear();
else _mesh = MeshPtr(new Mesh());
_mesh->loadMesh(file);
}
virtual vec3 getPosition() {
return _posi;
}
virtual void reset() {
_posi = { 0,0,0 };
_rotate = { 0,0,0 };
_scaler = { 1,1,1 };
for (auto &child : _childs) {
child->reset();
}
}
virtual void scale(const vec3&factor) {
_scaler += factor;
for (auto &child : _childs) {
child->scale(factor);
}
}
//TODO:Get the cpu side euler angle.
virtual void rotate(float deg, const vec3&axis) {
//_rotate
for (auto &child : _childs) {
child->rotate(deg, axis);
}
}
virtual void rotate(const vec3&eulerAngle) {
_rotate += eulerAngle;
}
virtual void move(const vec3&step) {
_posi += step;
for (auto &child : _childs) {
child->move(step);
}
}
SubMeshVec getSubMesh() {
return _mesh->getSubMesh();
}
virtual mat4 getToWorldMat();
//virtual void update();
Object(
const vec3&posi = { 0,0,0 },
const vec3&rotate = {0,0,0},
const vec3&scaler = {1.f,1.f,1.f},
Object *parent = nullptr,
Mesh *mesh = nullptr,
bool dirty = true,
bool visible = true,
bool throwshadow = true
) :
_posi{ posi },
_rotate{rotate},
_scaler{scaler},
_parent{ parent },
_mesh{ mesh },
_dirty{ dirty },
_visible{ visible },
_shadow{ throwshadow } {};
};
}