ezEngine  Milestone 7
GameObject_inl.h
1 
2 EZ_FORCE_INLINE ezGameObject::ConstChildIterator::ConstChildIterator(ezGameObject* pObject) :
3  m_pObject(pObject)
4 {
5 }
6 
7 EZ_FORCE_INLINE const ezGameObject& ezGameObject::ConstChildIterator::operator*() const
8 {
9  return *m_pObject;
10 }
11 
12 EZ_FORCE_INLINE const ezGameObject* ezGameObject::ConstChildIterator::operator->() const
13 {
14  return m_pObject;
15 }
16 
17 EZ_FORCE_INLINE ezGameObject::ConstChildIterator::operator const ezGameObject*() const
18 {
19  return m_pObject;
20 }
21 
22 EZ_FORCE_INLINE bool ezGameObject::ConstChildIterator::IsValid() const
23 {
24  return m_pObject != nullptr;
25 }
26 
28 {
29  Next();
30 }
31 
33 
34 EZ_FORCE_INLINE ezGameObject::ChildIterator::ChildIterator(ezGameObject* pObject) :
35  ConstChildIterator(pObject)
36 {
37 }
38 
39 EZ_FORCE_INLINE ezGameObject& ezGameObject::ChildIterator::operator*()
40 {
41  return *m_pObject;
42 }
43 
44 EZ_FORCE_INLINE ezGameObject* ezGameObject::ChildIterator::operator->()
45 {
46  return m_pObject;
47 }
48 
49 EZ_FORCE_INLINE ezGameObject::ChildIterator::operator ezGameObject*()
50 {
51  return m_pObject;
52 }
53 
55 
56 EZ_FORCE_INLINE ezGameObject::ezGameObject()
57 {
58  m_ParentIndex = 0;
59  m_FirstChildIndex = 0;
60  m_LastChildIndex = 0;
61 
62  m_NextSiblingIndex = 0;
63  m_PrevSiblingIndex = 0;
64  m_ChildCount = 0;
65 
66  m_uiHierarchyLevel = 0;
67  m_uiTransformationDataIndex = 0;
68 
69  m_pTransformationData = nullptr;
70  m_pWorld = nullptr;
71 }
72 
73 EZ_FORCE_INLINE ezGameObject::ezGameObject(const ezGameObject& other)
74 {
75  *this = other;
76 }
77 
78 EZ_FORCE_INLINE ezGameObject::~ezGameObject()
79 {
80 }
81 
83 {
84  return ezGameObjectHandle(m_InternalId);
85 }
86 
87 EZ_FORCE_INLINE bool ezGameObject::IsDynamic() const
88 {
89  return m_Flags.IsSet(ezObjectFlags::Dynamic);
90 }
91 
92 EZ_FORCE_INLINE bool ezGameObject::IsStatic() const
93 {
94  return !m_Flags.IsSet(ezObjectFlags::Dynamic);
95 }
96 
97 EZ_FORCE_INLINE bool ezGameObject::IsActive() const
98 {
99  return m_Flags.IsSet(ezObjectFlags::Active);
100 }
101 
102 EZ_FORCE_INLINE void ezGameObject::SetName(const char* szName)
103 {
104  m_sName.Assign(szName);
105 }
106 
107 EZ_FORCE_INLINE const char* ezGameObject::GetName() const
108 {
109  return m_sName.GetString().GetData();
110 }
111 
113 {
114  for (ezUInt32 i = 0; i < children.GetCount(); ++i)
115  {
116  AddChild(children[i]);
117  }
118 }
119 
121 {
122  for (ezUInt32 i = 0; i < children.GetCount(); ++i)
123  {
124  DetachChild(children[i]);
125  }
126 }
127 
128 EZ_FORCE_INLINE ezUInt32 ezGameObject::GetChildCount() const
129 {
130  return m_ChildCount;
131 }
132 
133 EZ_FORCE_INLINE ezWorld* ezGameObject::GetWorld()
134 {
135  return m_pWorld;
136 }
137 
138 EZ_FORCE_INLINE const ezWorld* ezGameObject::GetWorld() const
139 {
140  return m_pWorld;
141 }
142 
143 EZ_FORCE_INLINE void ezGameObject::SetLocalPosition(const ezVec3& position)
144 {
145  m_pTransformationData->m_localPosition = position.GetAsPositionVec4();
146 }
147 
148 EZ_FORCE_INLINE const ezVec3& ezGameObject::GetLocalPosition() const
149 {
150  return *reinterpret_cast<const ezVec3*>(&m_pTransformationData->m_localPosition);
151 }
152 
153 EZ_FORCE_INLINE void ezGameObject::SetLocalRotation(const ezQuat& rotation)
154 {
155  m_pTransformationData->m_localRotation = rotation;
156 }
157 
158 EZ_FORCE_INLINE const ezQuat& ezGameObject::GetLocalRotation() const
159 {
160  return m_pTransformationData->m_localRotation;
161 }
162 
163 EZ_FORCE_INLINE void ezGameObject::SetLocalScaling(const ezVec3& scaling)
164 {
165  m_pTransformationData->m_localScaling = scaling.GetAsDirectionVec4();
166 }
167 
168 EZ_FORCE_INLINE const ezVec3& ezGameObject::GetLocalScaling() const
169 {
170  return *reinterpret_cast<const ezVec3*>(&m_pTransformationData->m_localScaling);
171 }
172 
173 EZ_FORCE_INLINE const ezVec3& ezGameObject::GetGlobalPosition() const
174 {
175  return m_pTransformationData->m_globalTransform.m_vPosition;
176 }
177 
178 EZ_FORCE_INLINE const ezQuat ezGameObject::GetGlobalRotation() const
179 {
180  ezMat3 mat = m_pTransformationData->m_globalTransform.m_Rotation;
181  mat.SetScalingFactors(ezVec3(1.0f));
182 
183  ezQuat q; q.SetFromMat3(mat);
184  return q;
185 }
186 
187 EZ_FORCE_INLINE const ezVec3 ezGameObject::GetGlobalScaling() const
188 {
189  return m_pTransformationData->m_globalTransform.m_Rotation.GetScalingFactors();
190 }
191 
192 EZ_FORCE_INLINE const ezTransform& ezGameObject::GetGlobalTransform() const
193 {
194  return m_pTransformationData->m_globalTransform;
195 }
196 
197 EZ_FORCE_INLINE void ezGameObject::SetVelocity(const ezVec3& vVelocity)
198 {
199  *reinterpret_cast<ezVec3*>(&m_pTransformationData->m_velocity) = vVelocity;
200 }
201 
202 EZ_FORCE_INLINE const ezVec3& ezGameObject::GetVelocity() const
203 {
204  return *reinterpret_cast<ezVec3*>(&m_pTransformationData->m_velocity);
205 }
206 
208 {
209  m_pTransformationData->ConditionalUpdateGlobalTransform();
210 }
211 
212 EZ_FORCE_INLINE const ezBoundingBoxSphere& ezGameObject::GetLocalBounds() const
213 {
214  return m_pTransformationData->m_localBounds;
215 }
216 
217 EZ_FORCE_INLINE const ezBoundingBoxSphere& ezGameObject::GetGlobalBounds() const
218 {
219  return m_pTransformationData->m_globalBounds;
220 }
221 
223 {
224  m_pTransformationData->ConditionalUpdateGlobalBounds();
225 }
226 
227 template <typename T>
228 bool ezGameObject::TryGetComponentOfBaseType(T*& out_pComponent) const
229 {
230  for (ezUInt32 i = 0; i < m_Components.GetCount(); ++i)
231  {
232  ezComponent* pComponent = m_Components[i];
233  if (pComponent->IsInstanceOf<T>())
234  {
235  out_pComponent = static_cast<T*>(pComponent);
236  return true;
237  }
238  }
239 
240  return false;
241 }
242 
243 template <typename T>
245 {
246  out_components.Clear();
247 
248  for (ezUInt32 i = 0; i < m_Components.GetCount(); ++i)
249  {
250  ezComponent* pComponent = m_Components[i];
251  if (pComponent->IsInstanceOf<T>())
252  {
253  out_components.PushBack(static_cast<T*>(pComponent));
254  }
255  }
256 }
257 
259 {
260  return m_Components;
261 }
262 
264 {
265  return ezMakeArrayPtr(const_cast<const ezComponent*const*>(m_Components.GetData()), m_Components.GetCount());
266 }
267 
268 EZ_FORCE_INLINE ezTagSet& ezGameObject::GetTags()
269 {
270  return m_Tags;
271 }
272 
273 EZ_FORCE_INLINE const ezTagSet& ezGameObject::GetTags() const
274 {
275  return m_Tags;
276 }
277 
278 
279 EZ_FORCE_INLINE void ezGameObject::TransformationData::UpdateGlobalTransform()
280 {
281  const ezVec3 vPos = *reinterpret_cast<const ezVec3*>(&m_localPosition);
282  const ezQuat qRot = m_localRotation;
283  const ezVec3 vScale = *reinterpret_cast<const ezVec3*>(&m_localScaling);
284  m_globalTransform = ezTransform(vPos, qRot, vScale);
285 }
286 
287 EZ_FORCE_INLINE void ezGameObject::TransformationData::UpdateGlobalTransformWithParent()
288 {
289  const ezVec3 vPos = *reinterpret_cast<const ezVec3*>(&m_localPosition);
290  const ezQuat qRot = m_localRotation;
291  const ezVec3 vScale = *reinterpret_cast<const ezVec3*>(&m_localScaling);
292  const ezTransform localTransform(vPos, qRot, vScale);
293  m_globalTransform.SetGlobalTransform(m_pParentData->m_globalTransform, localTransform);
294 }
295 
296 EZ_FORCE_INLINE void ezGameObject::TransformationData::UpdateGlobalBounds()
297 {
298  m_globalBounds = m_localBounds;
299  m_globalBounds.Transform(m_globalTransform.GetAsMat4());
300 }
301 
302