TDME2  1.9.200
Entity.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <string>
4 
5 #include <tdme/tdme.h>
6 #include <tdme/engine/fwd-tdme.h>
8 #include <tdme/engine/Color4.h>
11 #include <tdme/engine/Transform.h>
12 #include <tdme/math/fwd-tdme.h>
13 
14 using std::string;
15 
24 
25 /**
26  * Engine entity
27  * @author Andreas Drewke
28  */
30 {
31  friend class Engine;
32  friend class EntityHierarchy;
33  friend class OctTreePartition;
34  friend class ObjectRenderGroup;
35  friend class ParticleSystemGroup;
36  friend class SceneConnector;
37 
38 protected:
39  Entity* parentEntity { nullptr };
40 
41  /**
42  * Set parent entity, needs to be called before adding to engine
43  * @param entity entity
44  */
45  inline void setParentEntity(Entity* entity) {
46  this->parentEntity = entity;
47  }
48 
49  /**
50  * @return parent entity
51  */
52  inline Entity* getParentEntity() {
53  return parentEntity;
54  }
55 
56 private:
57  static constexpr int UNIQUEPARTITIONID_NONE { -1 };
58 
60 
61  /**
62  * Set unique partition id
63  * @param uniquePartitionId unique partition id
64  */
66  this->uniquePartitionId = uniquePartitionId;
67  }
68 
69  /**
70  * @return unique partition id
71  */
72  inline int getUniquePartitionId() {
73  return uniquePartitionId;
74  }
75 
76  /**
77  * Set parent transform
78  * @param parentTransform parent transform
79  */
80  virtual void setParentTransform(const Transform& parentTransform) = 0;
81 
82 public:
83  static constexpr int RENDERPASS_MAX { 5 };
84  static constexpr int RENDERPASS_ALL { 1 + 2 + 4 + 8 + 16 + 32 };
86 
87  enum EntityType {
101  };
102 
103  /**
104  * @return entity type
105  */
106  virtual EntityType getEntityType() = 0;
107 
108  /**
109  * Set up engine
110  * @param engine engine
111  */
112  virtual void setEngine(Engine* engine) = 0;
113 
114  /**
115  * Set up renderer
116  * @param renderer renderer
117  */
118  virtual void setRenderer(Renderer* renderer) = 0;
119 
120  /**
121  * @return entity id
122  */
123  virtual const string& getId() = 0;
124 
125  /**
126  * @return true if enabled to be rendered
127  */
128  virtual bool isEnabled() = 0;
129 
130  /**
131  * Enable/disable rendering
132  * @param enabled enabled
133  */
134  virtual void setEnabled(bool enabled) = 0;
135 
136  /**
137  * @return if frustum culling is enabled
138  */
139  virtual bool isFrustumCulling() = 0;
140 
141  /**
142  * Set frustum culling
143  * @param frustumCulling frustum culling
144  */
145  virtual void setFrustumCulling(bool frustumCulling) = 0;
146 
147  /**
148  * @return if entity is pickable
149  */
150  virtual bool isPickable() = 0;
151 
152  /**
153  * Set this entity pickable
154  * @param pickable pickable
155  */
156  virtual void setPickable(bool pickable) = 0;
157 
158  /**
159  * @return if entity contributes to shadows
160  */
161  virtual bool isContributesShadows() = 0;
162 
163  /**
164  * Enable/disable contributes shadows
165  * @param contributesShadows contributes shadows
166  */
167  virtual void setContributesShadows(bool contributesShadows) = 0;
168 
169  /**
170  * @return if entity receives shadows
171  */
172  virtual bool isReceivesShadows() = 0;
173 
174  /**
175  * Enable/disable receives shadows
176  * @param receivesShadows receives shadows
177  */
178  virtual void setReceivesShadows(bool receivesShadows) = 0;
179 
180  /**
181  * The effect color will be multiplied with fragment color
182  * @return effect color
183  */
184  virtual const Color4& getEffectColorMul() const = 0;
185 
186  /**
187  * Set effect color that will be multiplied with fragment color
188  * @param effectColorMul effect color
189  */
190  virtual void setEffectColorMul(const Color4& effectColorMul) = 0;
191 
192  /**
193  * The effect color will be added to fragment color
194  * @return effect color
195  */
196  virtual const Color4& getEffectColorAdd() const = 0;
197 
198  /**
199  * Set effect color that will be added to fragment color
200  * @return effect color
201  */
202  virtual void setEffectColorAdd(const Color4& effectColorAdd) = 0;
203 
204  /**
205  * Initiates this entity
206  */
207  virtual void initialize() = 0;
208 
209  /**
210  * Dispose this entity
211  */
212  virtual void dispose() = 0;
213 
214  /**
215  * @return bounding box / in model coordinate space
216  */
217  virtual BoundingBox* getBoundingBox() = 0;
218 
219  /**
220  * @return world bounding box
221  */
223 
224  /**
225  * @return entity translation
226  */
227  virtual const Vector3& getTranslation() const = 0;
228 
229  /**
230  * Set translation
231  * @param translation translation
232  */
233  virtual void setTranslation(const Vector3& translation) = 0;
234 
235  /**
236  * @return entity scale
237  */
238  virtual const Vector3& getScale() const = 0;
239 
240  /**
241  * Set scale
242  * @param scale scale
243  */
244  virtual void setScale(const Vector3& scale) = 0;
245 
246  /**
247  * @return rotation count
248  */
249  virtual const int getRotationCount() const = 0;
250 
251  /**
252  * Get rotation at given index
253  * @param idx rotation index
254  * @return rotation
255  */
256  virtual Rotation& getRotation(const int idx) = 0;
257 
258  /**
259  * Add rotation
260  * @param axis axis
261  * @param angle angle
262  */
263  virtual void addRotation(const Vector3& axis, const float angle) = 0;
264 
265  /**
266  * Remove rotation
267  * @param idx index
268  */
269  virtual void removeRotation(int idx) = 0;
270 
271  /**
272  * @param idx rotation index
273  * @return rotation axis for rotation with given index
274  */
275  virtual const Vector3& getRotationAxis(const int idx) const = 0;
276 
277  /**
278  * Set rotation axis
279  * @param idx rotation index
280  * @param axis rotation axis
281  */
282  virtual void setRotationAxis(const int idx, const Vector3& axis) = 0;
283 
284  /**
285  * @param idx rotation index
286  * @return rotation angle for rotation with given index
287  */
288  virtual const float getRotationAngle(const int idx) const = 0;
289 
290  /**
291  * @param idx rotation index
292  * @param angle rotation angle
293  * @return rotation angle for rotation with given index
294  */
295  virtual void setRotationAngle(const int idx, const float angle) = 0;
296 
297  /**
298  * @return rotations quaternion
299  */
300  virtual const Quaternion& getRotationsQuaternion() const = 0;
301 
302  /**
303  * @return this transform matrix
304  */
305  virtual const Matrix4x4& getTransformMatrix() const = 0;
306 
307  /**
308  * Update transform
309  */
310  virtual void update() = 0;
311 
312  /**
313  * @return parent transform
314  */
315  virtual const Transform& getParentTransform() const = 0;
316 
317  /**
318  * @return transform
319  */
320  virtual const Transform& getTransform() const = 0;
321 
322  /**
323  * Set transform
324  * @param transform transform
325  */
326  virtual void setTransform(const Transform& transform) = 0;
327 
328  /**
329  * @return render pass
330  */
331  virtual RenderPass getRenderPass() const = 0;
332 
333  /**
334  * Set render pass
335  * @param renderPass render pass
336  */
337  virtual void setRenderPass(RenderPass renderPass) = 0;
338 
339  /**
340  * Destructor
341  */
342  virtual ~Entity() {}
343 };
Color 4 definition class.
Definition: Color4.h:18
Engine main class.
Definition: Engine.h:131
Entity hierarchy to be used with engine class.
Engine entity.
Definition: Entity.h:30
virtual void addRotation(const Vector3 &axis, const float angle)=0
Add rotation.
virtual void setScale(const Vector3 &scale)=0
Set scale.
virtual const float getRotationAngle(const int idx) const =0
@ RENDERPASS_POST_POSTPROCESSING
Definition: Entity.h:85
@ RENDERPASS_NOFRUSTUMCULLING
Definition: Entity.h:85
virtual bool isEnabled()=0
virtual void setRenderer(Renderer *renderer)=0
Set up renderer.
virtual const int getRotationCount() const =0
virtual BoundingBox * getBoundingBox()=0
virtual const string & getId()=0
Entity * getParentEntity()
Definition: Entity.h:52
virtual const Color4 & getEffectColorAdd() const =0
The effect color will be added to fragment color.
virtual void setParentTransform(const Transform &parentTransform)=0
Set parent transform.
virtual void setRenderPass(RenderPass renderPass)=0
Set render pass.
virtual bool isContributesShadows()=0
virtual Rotation & getRotation(const int idx)=0
Get rotation at given index.
virtual void setRotationAxis(const int idx, const Vector3 &axis)=0
Set rotation axis.
void setUniquePartitionId(int uniquePartitionId)
Set unique partition id.
Definition: Entity.h:65
virtual bool isFrustumCulling()=0
virtual void setEngine(Engine *engine)=0
Set up engine.
virtual void setEffectColorMul(const Color4 &effectColorMul)=0
Set effect color that will be multiplied with fragment color.
virtual const Matrix4x4 & getTransformMatrix() const =0
virtual void setTranslation(const Vector3 &translation)=0
Set translation.
virtual EntityType getEntityType()=0
static constexpr int RENDERPASS_ALL
Definition: Entity.h:84
virtual const Transform & getTransform() const =0
Entity * parentEntity
Definition: Entity.h:39
virtual void update()=0
Update transform.
virtual void setRotationAngle(const int idx, const float angle)=0
virtual void setFrustumCulling(bool frustumCulling)=0
Set frustum culling.
virtual void setTransform(const Transform &transform)=0
Set transform.
virtual const Quaternion & getRotationsQuaternion() const =0
virtual void initialize()=0
Initiates this entity.
virtual const Vector3 & getTranslation() const =0
virtual BoundingBox * getWorldBoundingBox()=0
virtual RenderPass getRenderPass() const =0
virtual const Transform & getParentTransform() const =0
virtual const Vector3 & getRotationAxis(const int idx) const =0
static constexpr int RENDERPASS_MAX
Definition: Entity.h:83
virtual void setContributesShadows(bool contributesShadows)=0
Enable/disable contributes shadows.
virtual const Color4 & getEffectColorMul() const =0
The effect color will be multiplied with fragment color.
void setParentEntity(Entity *entity)
Set parent entity, needs to be called before adding to engine.
Definition: Entity.h:45
virtual void dispose()=0
Dispose this entity.
@ ENTITYTYPE_OBJECTRENDERGROUP
Definition: Entity.h:96
@ ENTITYTYPE_OBJECTPARTICLESYSTEM
Definition: Entity.h:98
@ ENTITYTYPE_IMPOSTEROBJECT
Definition: Entity.h:91
@ ENTITYTYPE_FOGPARTICLESYSTEM
Definition: Entity.h:97
@ ENTITYTYPE_POINTSPARTICLESYSTEM
Definition: Entity.h:100
@ ENTITYTYPE_ENVIRONMENTMAPPING
Definition: Entity.h:90
@ ENTITYTYPE_PARTICLESYSTEMGROUP
Definition: Entity.h:99
@ ENTITYTYPE_LODOBJECTIMPOSTER
Definition: Entity.h:94
@ ENTITYTYPE_ENTITYHIERARCHY
Definition: Entity.h:89
virtual ~Entity()
Destructor.
Definition: Entity.h:342
static constexpr int UNIQUEPARTITIONID_NONE
Definition: Entity.h:57
virtual void setPickable(bool pickable)=0
Set this entity pickable.
virtual void setReceivesShadows(bool receivesShadows)=0
Enable/disable receives shadows.
virtual bool isPickable()=0
int getUniquePartitionId()
Definition: Entity.h:72
virtual void setEffectColorAdd(const Color4 &effectColorAdd)=0
Set effect color that will be added to fragment color.
virtual void setEnabled(bool enabled)=0
Enable/disable rendering.
virtual bool isReceivesShadows()=0
virtual void removeRotation(int idx)=0
Remove rotation.
virtual const Vector3 & getScale() const =0
Object render group for static objects that might be animated by shaders.
Oct tree partition implementation.
Particle system group, which combines several particle systems into a group, to be used with engine c...
Rotation representation.
Definition: Rotation.h:18
Scene engine/physics connector.
Transform which contain scale, rotations and translation.
Definition: Transform.h:29
Axis aligned bounding box used for frustum, this is not directly connectable with physics engine.
Definition: BoundingBox.h:26
Matrix4x4 class representing matrix4x4 mathematical structure and operations for 3d space.
Definition: Matrix4x4.h:23
Quaternion class representing quaternion mathematical structure and operations with x,...
Definition: Quaternion.h:24
Vector3 class representing vector3 mathematical structure and operations with x, y,...
Definition: Vector3.h:20