TDME2  1.9.200
FogParticleSystemInternal.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>
9 #include <tdme/engine/fwd-tdme.h>
11 #include <tdme/engine/Color4.h>
19 #include <tdme/engine/Transform.h>
20 #include <tdme/math/Matrix4x4.h>
21 #include <tdme/math/Vector3.h>
22 
23 using std::string;
24 using std::unique_ptr;
25 using std::vector;
26 
39 
40 /**
41  * Fog particle system
42  * @author Andreas Drewke
43  */
45  : public Transform
46  , public virtual ParticleSystemInternal
47 {
48 protected:
49  string id;
50  Engine* engine { nullptr };
51  Renderer* renderer { nullptr };
52  bool enabled;
53  bool active;
54  unique_ptr<ParticleEmitter> emitter;
55  vector<Particle> particles;
56  int32_t maxPoints;
57  float pointSize;
59  Texture* texture { nullptr };
62  float fps;
63  unique_ptr<TransparentRenderPointsPool> pointsRenderPool;
64 
69  bool pickable;
70 
74 
75  /**
76  * Update bounding volume
77  */
78  inline void updateInternal() {
79  Vector3 scale;
81  pointSizeScale = Math::max(scale.getX(), Math::max(scale.getY(), scale.getZ()));
84  worldBoundingBox.getMin().sub(0.05f); // scale a bit up to make picking work better
85  worldBoundingBox.getMax().add(0.05f); // same here
87  }
88 
89 public:
90  // forbid class copy
92 
93  /**
94  * Public constructor
95  * @param id id
96  * @param emitter emitter
97  * @param maxPoints max points
98  * @param pointSize point size
99  * @param texture texture
100  * @param textureHorizontalSprites texture horizonal sprites
101  * @param textureVerticalSprites texture vertical sprites
102  * @param fps frames per seconds
103  */
104  FogParticleSystemInternal(const string& id, ParticleEmitter* emitter, int32_t maxPoints, float pointSize, Texture* texture = nullptr, int32_t textureHorizontalSprites = 1, int32_t textureVerticalSprites = 1, float fps = 10.0f);
105 
106  /**
107  * Destructor
108  */
109  virtual ~FogParticleSystemInternal();
110 
111  /**
112  * Initialize
113  */
114  void initialize();
115 
116  inline ParticleEmitter* getEmitter() override {
117  return emitter.get();
118  }
119 
120  inline const string& getId() override {
121  return id;
122  }
123 
124  /**
125  * Set renderer
126  * @param renderer renderer
127  */
128  inline void setRenderer(Renderer* renderer) {
129  this->renderer = renderer;
130  }
131 
132  /**
133  * Set engine
134  * @param engine engine
135  */
136  inline void setEngine(Engine* engine) {
137  this->engine = engine;
138  }
139 
140  inline bool isEnabled() override {
141  return enabled;
142  }
143 
144  inline bool isActive() override {
145  return active;
146  }
147 
148  inline void setEnabled(bool enabled) override {
149  this->enabled = enabled;
150  }
151 
152  inline const Color4& getEffectColorMul() const override {
153  return effectColorMul;
154  }
155 
156  inline void setEffectColorMul(const Color4& effectColorMul) override {
157  this->effectColorMul = effectColorMul;
158  }
159 
160  inline const Color4& getEffectColorAdd() const override {
161  return effectColorAdd;
162  }
163 
164  inline void setEffectColorAdd(const Color4& effectColorAdd) override {
165  this->effectColorAdd = effectColorAdd;
166  }
167 
168  inline bool isPickable() override {
169  return pickable;
170  }
171 
172  inline void setPickable(bool pickable) override {
173  this->pickable = pickable;
174  }
175 
176  inline bool isAutoEmit() override {
177  return true;
178  }
179 
180  inline void setAutoEmit(bool autoEmit) override {
181  // no op
182  }
183 
184  /**
185  * @return if entity contributes to shadows
186  */
187  inline bool isContributesShadows() {
188  return false;
189  }
190 
191  /**
192  * Enable/disable contributes shadows
193  * @param contributesShadows contributes shadows
194  */
195  inline void setContributesShadows(bool contributesShadows) {
196  //
197  }
198 
199  /**
200  * @return if entity receives shadows
201  */
202  inline bool isReceivesShadows() {
203  return false;
204  }
205 
206  /**
207  * Enable/disable receives shadows
208  * @param receivesShadows receives shadows
209  */
210  inline void setReceivesShadows(bool receivesShadows) {
211  //
212  }
213 
214  /**
215  * @return point size
216  */
217  inline float getPointSize() {
218  return pointSize * pointSizeScale;
219  }
220 
221  /**
222  * @return texture
223  */
224  inline Texture* getTexture() {
225  return texture;
226  }
227 
228  /**
229  * @return texture horizontal sprites
230  */
231  inline int32_t getTextureHorizontalSprites(){
233  }
234 
235  /**
236  * @return texture vertical sprites
237  */
238  inline int32_t getTextureVerticalSprites(){
239  return textureVerticalSprites;
240  }
241 
242  // overridden methods
243  void update() override;
244  void setTransform(const Transform& transform) override;
245  void updateParticles() override;
246  void dispose();
247  inline int emitParticles() override {
248  return 0;
249  }
250  inline const Transform& getParentTransform() {
251  return parentTransform;
252  }
253  inline void setParentTransform(const Transform& transform) {
254  parentTransform = transform;
255  auto entityTransform = parentTransform * (*this);
256  entityTransformMatrix = entityTransform.getTransformMatrix();
257  //
258  updateInternal();
259  }
260  inline const Transform& getLocalTransform() override {
261  return localTransform;
262  }
263  inline void setLocalTransform(const Transform& transform) override {
264  this->localTransform = transform;
265  updateInternal();
266  }
267 
268  /**
269  * @return render points pool
270  */
272  return pointsRenderPool.get();
273  }
274 
275 };
Color 4 definition class.
Definition: Color4.h:18
Engine main class.
Definition: Engine.h:131
Texture entity.
Definition: Texture.h:24
Transform which contain scale, rotations and translation.
Definition: Transform.h:29
const Vector3 & getScale() const
Definition: Transform.h:71
Axis aligned bounding box used for frustum, this is not directly connectable with physics engine.
Definition: BoundingBox.h:26
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.
void setContributesShadows(bool contributesShadows)
Enable/disable contributes shadows.
void setLocalTransform(const Transform &transform) override
Set local transform.
void setPickable(bool pickable) override
Set this object pickable.
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.
FogParticleSystemInternal(const string &id, ParticleEmitter *emitter, int32_t maxPoints, float pointSize, Texture *texture=nullptr, int32_t textureHorizontalSprites=1, int32_t textureVerticalSprites=1, float fps=10.0f)
Public constructor.
const Color4 & getEffectColorMul() const override
The effect color will be multiplied with fragment color.
void setEnabled(bool enabled) override
Enable/disable rendering.
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
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
float getY() const
Definition: Vector3.h:117
float getX() const
Definition: Vector3.h:100
float getZ() const
Definition: Vector3.h:134
Vector3 & add(float scalar)
Adds a scalar.
Definition: Vector3.h:153
Vector3 & sub(float scalar)
Subtracts a scalar.
Definition: Vector3.h:177
#define FORBID_CLASS_COPY(CLASS)
Definition: tdme.h:6