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