TDME2  1.9.200
ObjectParticleSystemInternal.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <memory>
4 #include <string>
5 #include <vector>
6 
7 #include <tdme/tdme.h>
8 #include <tdme/engine/fwd-tdme.h>
10 #include <tdme/engine/Color4.h>
19 #include <tdme/engine/Object.h>
20 #include <tdme/engine/Transform.h>
21 #include <tdme/math/Matrix4x4.h>
22 #include <tdme/math/Vector3.h>
24 
25 using std::string;
26 using std::unique_ptr;
27 using std::vector;
28 
44 
45 /**
46  * Particle system which displays objects as particles
47  * @author Andreas Drewke
48  */
50  : public Transform
51  , public virtual ParticleSystemInternal
52 {
53 protected:
54  Engine* engine { nullptr };
55  Renderer* renderer { nullptr };
56  string id;
57  bool enabled;
58  Model* model { nullptr };
60  bool autoEmit;
63  vector<Particle> particles;
64  vector<Object*> objects;
65  vector<Object*> enabledObjects;
69  unique_ptr<ParticleEmitter> emitter;
70  bool pickable;
74 
78 
79  /**
80  * Update internal
81  */
82  inline void updateInternal() {
83  Vector3 scale;
87  for (auto object: objects) {
88  object->setScale(scale);
89  object->update();
90  }
93  }
94 
95 public:
96  // forbid class copy
98 
99  /**
100  * Public constructor
101  * @param id id
102  * @param model model
103  * @param scale scale
104  * @param autoEmit auto emit
105  * @param contributesShadows enable contributes shadows
106  * @param receivesShadows enable receives shadows
107  * @param maxCount maxCount
108  * @param emitter emitter
109  */
110  ObjectParticleSystemInternal(const string& id, Model* model, const Vector3& scale, bool autoEmit, bool contributesShadows, bool receivesShadows, int32_t maxCount, ParticleEmitter* emitter);
111 
112  /**
113  * Destructor
114  */
116 
117  // overridden methods
118  inline ParticleEmitter* getEmitter() override {
119  return emitter.get();
120  }
121 
122  const string& getId() override;
123  void setEngine(Engine* engine);
125  inline bool isEnabled() override {
126  return enabled;
127  }
128  inline bool isActive() override {
129  return enabledObjects.size() > 0;
130  }
131  inline void setEnabled(bool enabled) override {
132  this->enabled = enabled;
133  }
134  inline const Color4& getEffectColorMul() const override {
135  return effectColorMul;
136  }
137  inline void setEffectColorMul(const Color4& effectColorMul) override {
138  this->effectColorMul = effectColorMul;
139  }
140  inline const Color4& getEffectColorAdd() const override {
141  return effectColorAdd;
142  }
143  inline void setEffectColorAdd(const Color4& effectColorAdd) override {
144  this->effectColorAdd = effectColorAdd;
145  }
146  inline bool isPickable() override {
147  return pickable;
148  }
149  inline void setPickable(bool pickable) override {
150  this->pickable = pickable;
151  }
152  inline bool isAutoEmit() override {
153  return autoEmit;
154  }
155  inline void setAutoEmit(bool autoEmit) override {
156  this->autoEmit = autoEmit;
157  }
158 
159  /**
160  * @return if entity contributes to shadows
161  */
162  inline bool isContributesShadows() {
163  return contributesShadows;
164  }
165 
166  /**
167  * Enable/disable contributes shadows
168  * @param contributesShadows contributes shadows
169  */
171  this->contributesShadows = contributesShadows;
172  for (auto i = 0; i < objects.size(); i++) objects[i]->setContributesShadows(contributesShadows);
173  }
174 
175  /**
176  * @return if entity receives shadows
177  */
178  inline bool isReceivesShadows() {
179  return receivesShadows;
180  }
181 
182  /**
183  * Enable/disable receives shadows
184  * @param receivesShadows receives shadows
185  */
187  this->receivesShadows = receivesShadows;
188  for (auto i = 0; i < objects.size(); i++) objects[i]->setReceivesShadows(receivesShadows);
189  }
190 
191  /**
192  * Update transform
193  */
194  void update() override;
195  void setTransform(const Transform& transform) override;
196  int emitParticles() override;
197  void updateParticles() override;
198  void dispose();
199  inline const Transform& getParentTransform() {
200  return parentTransform;
201  }
202  inline void setParentTransform(const Transform& transform) {
203  parentTransform = transform;
204  auto entityTransform = parentTransform * (*this);
205  entityTransformMatrix = entityTransform.getTransformMatrix();
206  //
207  updateInternal();
208  }
209  inline const Transform& getLocalTransform() override {
210  return localTransform;
211  }
212  inline void setLocalTransform(const Transform& transform) override {
213  this->localTransform = transform;
214  updateInternal();
215  }
216 
217 };
Color 4 definition class.
Definition: Color4.h:18
Engine main class.
Definition: Engine.h:131
Engine entity.
Definition: Entity.h:30
Object to be used with engine class.
Definition: Object.h:60
Transform which contain scale, rotations and translation.
Definition: Transform.h:29
const Vector3 & getScale() const
Definition: Transform.h:71
Representation of a 3D model.
Definition: Model.h:35
Axis aligned bounding box used for frustum, this is not directly connectable with physics engine.
Definition: BoundingBox.h:26
void setContributesShadows(bool contributesShadows)
Enable/disable contributes shadows.
void setLocalTransform(const Transform &transform) override
Set local transform.
void setEffectColorMul(const Color4 &effectColorMul) override
Set the effect color that will be multiplied with fragment color.
void setTransform(const Transform &transform) override
Set transform.
ObjectParticleSystemInternal(const string &id, Model *model, const Vector3 &scale, bool autoEmit, bool contributesShadows, bool receivesShadows, int32_t maxCount, ParticleEmitter *emitter)
Public constructor.
const Color4 & getEffectColorMul() const override
The effect color will be multiplied with fragment color.
int emitParticles() override
Adds particles to this particle entity at given position.
void setReceivesShadows(bool receivesShadows)
Enable/disable receives shadows.
void setEffectColorAdd(const Color4 &effectColorAdd) override
Set the effect color that will be added to fragment color.
const Color4 & getEffectColorAdd() const override
The effect color will be added to fragment color.
Matrix4x4 class representing matrix4x4 mathematical structure and operations for 3d space.
Definition: Matrix4x4.h:23
Matrix4x4 & invert()
Inverts this matrix.
Definition: Matrix4x4.h:479
void getScale(Vector3 &scale) const
Get scale.
Definition: Matrix4x4.h:388
Vector3 class representing vector3 mathematical structure and operations with x, y,...
Definition: Vector3.h:20
Vector3 & scale(float scalar)
Scales by scalar.
Definition: Vector3.h:201
#define FORBID_CLASS_COPY(CLASS)
Definition: tdme.h:6