This repository has been archived by the owner on Oct 5, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
object3d.cpp
152 lines (137 loc) · 2.76 KB
/
object3d.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
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
141
142
143
144
145
146
147
148
149
150
151
152
#include "object3d.h"
Object3D::Object3D ()
: parent (nullptr)
, x (0), y (0), z (0)
, rotationX (0), rotationY (0), rotationZ (0)
, scaleX (1), scaleY (1), scaleZ (1)
, userData (nullptr)
{
}
float Object3D::getGlobalX ()
{
float globalX = x;
Object3D * curr = this;
while (curr -> parent)
{
curr = curr -> parent;
globalX += curr -> x;
}
return globalX;
}
float Object3D::getGlobalY ()
{
float globalY = y;
Object3D * curr = this;
while (curr -> parent)
{
curr = curr -> parent;
globalY += curr -> y;
}
return globalY;
}
float Object3D::getGlobalZ ()
{
float globalZ = z;
Object3D * curr = this;
while (curr -> parent)
{
curr = curr -> parent;
globalZ += curr -> z;
}
return globalZ;
}
float Object3D::getGlobalRotationX ()
{
float globalRotationX = rotationX;
Object3D * curr = this;
while (curr -> parent)
{
curr = curr -> parent;
globalRotationX += curr -> rotationX;
}
return globalRotationX;
}
float Object3D::getGlobalRotationY ()
{
float globalRotationY = rotationY;
Object3D * curr = this;
while (curr -> parent)
{
curr = curr -> parent;
globalRotationY += curr -> rotationY;
}
return globalRotationY;
}
float Object3D::getGlobalRotationZ ()
{
float globalRotationZ = rotationZ;
Object3D * curr = this;
while (curr -> parent)
{
curr = curr -> parent;
globalRotationZ += curr -> rotationZ;
}
return globalRotationZ;
}
float Object3D::getGlobalScaleX ()
{
float globalScaleX = scaleX;
Object3D * curr = this;
while (curr -> parent)
{
curr = curr -> parent;
globalScaleX *= curr -> scaleX;
}
return globalScaleX;
}
float Object3D::getGlobalScaleY ()
{
float globalScaleY = scaleY;
Object3D * curr = this;
while (curr -> parent)
{
curr = curr -> parent;
globalScaleY *= curr -> scaleY;
}
return globalScaleY;
}
float Object3D::getGlobalScaleZ ()
{
float globalScaleZ = scaleZ;
Object3D * curr = this;
while (curr -> parent)
{
curr = curr -> parent;
globalScaleZ *= curr -> scaleZ;
}
return globalScaleZ;
}
void Object3D::addChild (Object3D * obj)
{
obj -> parent = this;
children.push_back (obj);
}
void Object3D::addChildAt (Object3D * obj, ulong i)
{
obj -> parent = this;
children.insert (children.begin () + i, obj);
}
void Object3D::removeChild (Object3D * obj)
{
for (ulong i = 0; i < children.size (); i++)
if (children [i] == obj)
{
children [i] -> parent = nullptr;
children.erase (children.begin () + i);
break;
}
}
void Object3D::removeChildAt (ulong i)
{
children [i] -> parent = nullptr;
children.erase (children.begin () + i);
}
ulong Object3D::numChildren ()
{
return children.size ();
}