TDME2  1.9.200
ParticleSystemGroup.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <string>
4 #include <vector>
5 
6 #include <tdme/tdme.h>
7 #include <tdme/engine/fwd-tdme.h>
10 #include <tdme/engine/Entity.h>
13 #include <tdme/engine/Transform.h>
14 #include <tdme/math/fwd-tdme.h>
15 #include <tdme/math/Math.h>
16 #include <tdme/math/Matrix4x4.h>
17 #include <tdme/math/Vector3.h>
18 
19 using std::string;
20 using std::to_string;
21 using std::vector;
22 
30 using tdme::math::Math;
33 
34 /**
35  * Particle system group, which combines several particle systems into a group, to be used with engine class
36  * @author Andreas Drewke
37  */
39  : public Transform
40  , public ParticleSystem
41 {
42 private:
43  Engine* engine { nullptr };
44  bool frustumCulling { true };
46 
47  string id;
50  bool enabled;
51  bool pickable;
52  bool autoEmit;
57  vector<ParticleSystem*> particleSystems;
59 
62 
63  // overridden methods
64  inline void setParentTransform(const Transform& parentTransform) override {
65  //
66  this->parentTransform = parentTransform;
67  auto entityTransform = parentTransform * (*this);
68  entityTransformMatrix = entityTransform.getTransformMatrix();
69  //
70  for (auto particleSystem: particleSystems) particleSystem->setParentTransform(entityTransform);
71  }
72 
73 public:
74  // forbid class copy
76 
77  /**
78  * Public constructor
79  * @param id id
80  * @param autoEmit auto emit
81  * @param contributesShadows contributes shadows
82  * @param receivesShadows receives shadows
83  * @param particleSystems particle systems
84  */
85  ParticleSystemGroup(const string& id, bool autoEmit, bool contributesShadows, bool receivesShadows, const vector<ParticleSystem*>& particleSystems);
86 
87  /**
88  * Destructor
89  */
91 
92  // overridden method
93  inline EntityType getEntityType() override {
95  }
96 
97  /**
98  * @return particle systems
99  */
100  inline const vector<ParticleSystem*>& getParticleSystems() {
101  return particleSystems;
102  }
103 
104  // overridden methods
105  void setEngine(Engine* engine) override;
106  void setRenderer(Renderer* renderer) override;
107  void initialize() override;
108  void dispose() override;
109 
110  inline bool isEnabled() override {
111  return enabled;
112  }
113 
114  void setEnabled(bool enabled) override;
115 
116  inline bool isFrustumCulling() override {
117  return frustumCulling;
118  }
119 
120  void setFrustumCulling(bool frustumCulling) override;
121  void update() override;
122 
123  inline BoundingBox* getBoundingBox() override {
124  if (particleSystems.empty() == false) {
125  // compute new bounding box
127  for (auto i = 1; i < particleSystems.size(); i++) {
128  boundingBox.extend(dynamic_cast<Entity*>(particleSystems[i])->getBoundingBox());
129  }
131  }
132 
133  //
134  return &boundingBox;
135  }
136 
137  inline BoundingBox* getWorldBoundingBox() override {
138  // update world bounding box
140 
141  //
142  return &worldBoundingBox;
143  }
144 
145  inline ParticleEmitter* getEmitter() override {
146  return nullptr;
147  }
148 
149  inline const Color4& getEffectColorAdd() const override {
150  return effectColorAdd;
151  }
152 
153  inline void setEffectColorAdd(const Color4& effectColorAdd) override {
154  for (auto particleSystem: particleSystems) particleSystem->setEffectColorAdd(effectColorAdd);
155  this->effectColorAdd = effectColorAdd;
156  }
157 
158  inline const Color4& getEffectColorMul() const override {
159  return effectColorMul;
160  }
161 
162  inline void setEffectColorMul(const Color4& effectColorMul) override {
163  for (auto particleSystem: particleSystems) particleSystem->setEffectColorMul(effectColorMul);
164  this->effectColorMul = effectColorMul;
165  }
166 
167  inline const string& getId() override {
168  return id;
169  }
170 
171  inline bool isContributesShadows() override {
172  return contributesShadows;
173  }
174 
175  inline void setContributesShadows(bool contributesShadows) override {
176  this->contributesShadows = contributesShadows;
177  for (auto particleSystem: particleSystems) {
178  auto ops = dynamic_cast<ObjectParticleSystem*>(particleSystem);
179  if (ops != nullptr) ops->setContributesShadows(contributesShadows);
180  }
181  }
182 
183  inline bool isReceivesShadows() override {
184  return receivesShadows;
185  }
186 
187  inline void setReceivesShadows(bool receivesShadows) override {
188  this->receivesShadows = receivesShadows;
189  for (auto particleSystem: particleSystems) {
190  auto ops = dynamic_cast<ObjectParticleSystem*>(particleSystem);
191  if (ops != nullptr) ops->setReceivesShadows(receivesShadows);
192  }
193  }
194 
195  inline bool isPickable() override {
196  return pickable;
197  }
198 
199  inline void setPickable(bool pickable) override {
200  this->pickable = true;
201  }
202 
203  inline const Vector3& getTranslation() const override {
204  return Transform::getTranslation();
205  }
206 
207  inline void setTranslation(const Vector3& translation) override {
209  }
210 
211  inline const Vector3& getScale() const override {
212  return Transform::getScale();
213  }
214 
215  inline void setScale(const Vector3& scale) override {
217  }
218 
219  inline const int getRotationCount() const override {
221  }
222 
223  inline Rotation& getRotation(const int idx) override {
224  return Transform::getRotation(idx);
225  }
226 
227  inline void addRotation(const Vector3& axis, const float angle) override {
228  Transform::addRotation(axis, angle);
229  }
230 
231  inline void removeRotation(const int idx) override {
233  }
234 
235  inline const Vector3& getRotationAxis(const int idx) const override {
236  return Transform::getRotationAxis(idx);
237  }
238 
239  inline void setRotationAxis(const int idx, const Vector3& axis) override {
240  Transform::setRotationAxis(idx, axis);
241  }
242 
243  inline const float getRotationAngle(const int idx) const override {
244  return Transform::getRotationAngle(idx);
245  }
246 
247  inline void setRotationAngle(const int idx, const float angle) override {
248  Transform::setRotationAngle(idx, angle);
249  }
250 
251  inline const Quaternion& getRotationsQuaternion() const override {
253  }
254 
255  inline const Matrix4x4& getTransformMatrix() const override {
256  return entityTransformMatrix;
257  }
258 
259  inline const Transform& getParentTransform() const override {
260  return parentTransform;
261  }
262 
263  inline const Transform& getTransform() const override {
264  return *this;
265  }
266 
267  void setTransform(const Transform& transform) override;
268 
269  inline RenderPass getRenderPass() const override {
270  return renderPass;
271  }
272 
273  inline void setRenderPass(RenderPass renderPass) override {
274  this->renderPass = renderPass;
275  }
276 
277  inline bool isActive() override {
278  for (auto particleSystem: particleSystems) {
279  if (particleSystem->isActive() == true) return true;
280  }
281  return false;
282  }
283 
284  inline bool isAutoEmit() override {
285  return autoEmit;
286  }
287 
288  inline int emitParticles() override {
289  auto emittedParticles = 0;
290  for (auto particleSystem: particleSystems) emittedParticles+= particleSystem->emitParticles();
291  return emittedParticles;
292  }
293 
294  void setAutoEmit(bool autoEmit) override;
295  void updateParticles() override;
296 
297  inline const Transform& getLocalTransform() override {
298  return localTransform;
299  }
300 
301  inline void setLocalTransform(const Transform& transform) override {
302  localTransform = transform;
303  for (auto particleSystem: particleSystems) particleSystem->setLocalTransform(localTransform);
304  }
305 
306 };
Color 4 definition class.
Definition: Color4.h:18
Engine main class.
Definition: Engine.h:131
Engine entity.
Definition: Entity.h:30
friend class ParticleSystemGroup
Definition: Entity.h:35
@ ENTITYTYPE_PARTICLESYSTEMGROUP
Definition: Entity.h:99
Object particle system entity to be used with engine class.
void setReceivesShadows(bool receivesShadows) override
Enable/disable receives shadows.
void setContributesShadows(bool contributesShadows) override
Enable/disable contributes shadows.
Particle system group, which combines several particle systems into a group, to be used with engine c...
BoundingBox * getBoundingBox() override
const Vector3 & getTranslation() const override
void updateParticles() override
Updates the particle entity.
const Transform & getTransform() const override
void setLocalTransform(const Transform &transform) override
Set local transform.
RenderPass getRenderPass() const override
void dispose() override
Dispose this entity.
vector< ParticleSystem * > particleSystems
void setTranslation(const Vector3 &translation) override
Set translation.
void removeRotation(const int idx) override
Remove rotation.
Rotation & getRotation(const int idx) override
Get rotation at given index.
const int getRotationCount() const override
const Vector3 & getRotationAxis(const int idx) const override
void initialize() override
Initiates this entity.
void setRenderPass(RenderPass renderPass) override
Set render pass.
void setReceivesShadows(bool receivesShadows) override
Enable/disable receives shadows.
void addRotation(const Vector3 &axis, const float angle) override
Add rotation.
void update() override
Computes transform matrix.
void setPickable(bool pickable) override
Set this entity pickable.
void setEffectColorMul(const Color4 &effectColorMul) override
Set effect color that will be multiplied with fragment color.
ParticleEmitter * getEmitter() override
void setTransform(const Transform &transform) override
Set transform.
const Quaternion & getRotationsQuaternion() const override
void setScale(const Vector3 &scale) override
Set scale.
const vector< ParticleSystem * > & getParticleSystems()
const Vector3 & getScale() const override
const float getRotationAngle(const int idx) const override
BoundingBox * getWorldBoundingBox() override
const Color4 & getEffectColorMul() const override
The effect color will be multiplied with fragment color.
void setFrustumCulling(bool frustumCulling) override
Set frustum culling.
void setAutoEmit(bool autoEmit) override
Set auto emit.
void setEngine(Engine *engine) override
Set up engine.
void setEnabled(bool enabled) override
Enable/disable rendering.
const Transform & getParentTransform() const override
const Matrix4x4 & getTransformMatrix() const override
int emitParticles() override
Adds particles to this particle entity at given position.
void setContributesShadows(bool contributesShadows) override
Enable/disable contributes shadows.
void setRotationAxis(const int idx, const Vector3 &axis) override
Set rotation axis.
void setEffectColorAdd(const Color4 &effectColorAdd) override
Set effect color that will be added to fragment color.
const Color4 & getEffectColorAdd() const override
The effect color will be added to fragment color.
void setParentTransform(const Transform &parentTransform) override
Set parent transform.
const Transform & getLocalTransform() override
void setRenderer(Renderer *renderer) override
Set up renderer.
void setRotationAngle(const int idx, const float angle) override
Rotation representation.
Definition: Rotation.h:18
Transform which contain scale, rotations and translation.
Definition: Transform.h:29
void setRotationAngle(const int idx, const float angle)
Definition: Transform.h:155
void setRotationAxis(const int idx, const Vector3 &axis)
Set rotation axis.
Definition: Transform.h:138
void setTranslation(const Vector3 &translation)
Set translation.
Definition: Transform.h:64
void removeRotation(const int idx)
Remove rotation.
Definition: Transform.h:121
const Vector3 & getScale() const
Definition: Transform.h:71
Rotation & getRotation(const int idx)
Get rotation at given index.
Definition: Transform.h:95
void setScale(const Vector3 &scale)
Set scale.
Definition: Transform.h:79
const int getRotationCount() const
Definition: Transform.h:86
const Vector3 & getRotationAxis(const int idx) const
Definition: Transform.h:129
const Quaternion & getRotationsQuaternion() const
Definition: Transform.h:162
const Vector3 & getTranslation() const
Definition: Transform.h:56
void addRotation(const Vector3 &axis, const float angle)
Add rotation.
Definition: Transform.h:113
const float getRotationAngle(const int idx) const
Definition: Transform.h:146
Axis aligned bounding box used for frustum, this is not directly connectable with physics engine.
Definition: BoundingBox.h:26
void fromBoundingVolume(BoundingBox *original)
Set up this bounding volume from given bounding volume.
Definition: BoundingBox.cpp:70
void extend(BoundingBox *boundingBox)
Extend bounding box with given bounding box.
Definition: BoundingBox.h:158
void fromBoundingVolumeWithTransformMatrix(BoundingBox *original, const Matrix4x4 &transformMatrix)
Create bounding volume from given original(of same type) with applied transform matrix.
Definition: BoundingBox.cpp:79
void update()
Updates this bounding box.
Standard math functions.
Definition: Math.h:19
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
Particle system entity interface.
#define FORBID_CLASS_COPY(CLASS)
Definition: tdme.h:6