Engine
Frameworkcreatedbymeusableforthecreationofsimplegames.CurrentlysupportsOpenGL(Verysimple)andVulkan.
Particle.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <ThirdParty/glm/glm/glm.hpp>
4 
5 #include "Engine/Mesh/Mesh.hpp"
8 
9 #include <ThirdParty/EASTL-master/include/EASTL/map.h>
10 #include <ThirdParty/EASTL-master/include/EASTL/shared_ptr.h>
11 
12 namespace Engine {
13 
14  class Particle
15  {
16  public:
17  Particle();
18  ~Particle();
19 
20  enum class ParticleType {
21  LINE = 0,
22  BILLBOARD,
23  MESH
24  };
25 
26  enum class InterpolateType {
27  START = 0,
28  END,
29  LINEAR,
30  QUADRATIC
31  };
32 
33  enum class BlendMode {
34  ALPHA = 0,
35  ADDATIVE,
36  SOLID
37  };
38 
39  enum class LineEndAction {
40  STOP = 0,
41  REMOVE_FIRST,
42  REMOVE_SECOND,
43  REMOVE_LAST,
44  DESTROY
45  };
46 
51  void SetParticleType(ParticleType type);
52 
58 
63  void SetBlendMode(BlendMode mode);
64 
70 
76  void SetStartColor(glm::vec4 colorMin, glm::vec4 colorMax);
77 
82  eastl::pair<glm::vec4, glm::vec4> GetStartColor();
83 
89  void SetEndColor(glm::vec4 colorMin, glm::vec4 colorMax);
90 
95  eastl::pair<glm::vec4, glm::vec4> GetEndColor();
96 
102 
108 
114  void SetForce(glm::vec3 forceMin, glm::vec3 forceMax);
115 
120  eastl::pair<glm::vec3, glm::vec3> GetForce();
121 
127  void SetLifetime(float lifetimeMin, float lifetimeMax);
128 
133  eastl::pair<float, float> GetLifetime();
134 
140  void SetSpeed(float speedMin, float speedMax);
141 
146  eastl::pair<float, float> GetSpeed();
147 
155  void SetMass(float massMin, float massMax);
156 
161  eastl::pair<float, float> GetMass();
162 
167  void SetGravityEnabled(bool gravity);
168 
173  bool IsGravityEnabled() const;
174 
179  void SetTexture(eastl::weak_ptr<Texture> texture);
180 
185  eastl::weak_ptr<Texture> GetTexture() const;
186 
191  bool HasTexture() const;
192 
197  void SetLineMaxSegments(int segments);
198 
203  int GetLineMaxSegments() const;
204 
209  void SetNewSegmentsPerFrame(int segments);
210 
215  int GetNewSegmentsPerFrame() const;
216 
221  void SetLineEndAction(LineEndAction action);
222 
228 
234  void SetLineStartThickness(float thicknessMin, float thicknessMax);
235 
240  eastl::pair<float, float> GetLineStartThickness();
241 
247  void SetLineEndthickness(float thicknessMin, float thicknessMax);
248 
253  eastl::pair<float, float> GetLineEndThickness();
254 
260 
266 
272  void SetBillboardSizeStart(glm::vec2 sizeMin, glm::vec2 sizeMax);
273 
278  eastl::pair<glm::vec2, glm::vec2> GetBillboardSizeStart();
279 
285  void SetBillboardSizeEnd(glm::vec2 sizeMin, glm::vec2 sizeMax);
286 
291  eastl::pair<glm::vec2, glm::vec2> GetBillboardSizeEnd();
292 
298 
304 
310  void SetBillboardRollSpeedStart(float speedMin, float speedMax);
311 
316  eastl::pair<float, float> GetBillboardRollSpeedStart();
317 
323  void SetBillboardRollSpeedEnd(float speedMin, float speedMax);
324 
329  eastl::pair<float, float> GetBillboardRollSpeedEnd();
330 
336  void SetBillboardRoll(float rollMin, float rollMax);
337 
342  eastl::pair<float, float> GetBillboardRoll();
343 
349 
355 
360  void SetMesh(eastl::weak_ptr<Mesh> mesh);
361 
366  eastl::weak_ptr<Mesh> GetMesh() const;
367 
372  void SetMaterial(eastl::weak_ptr<Material> material);
373 
378  eastl::weak_ptr<Material> GetMaterial() const;
379 
385  void SetMeshScaleStart(glm::vec3 scaleMin, glm::vec3 scaleMax);
386 
391  eastl::pair<glm::vec3, glm::vec3> GetMeshScaleStart();
392 
398  void SetMeshScaleEnd(glm::vec3 scaleMin, glm::vec3 scaleMax);
399 
404  eastl::pair<glm::vec3, glm::vec3> GetMeshScaleEnd();
405 
411 
417 
423  void SetMeshRotationSpeedStart(glm::vec3 speedMin, glm::vec3 speedMax);
424 
429  eastl::pair<glm::vec3, glm::vec3> GetMeshRotationSpeedStart();
430 
436  void SetMeshRotationSpeedEnd(glm::vec3 speedMin, glm::vec3 speedMax);
437 
442  eastl::pair<glm::vec3, glm::vec3> GetMeshRotationSpeedEnd();
443 
449  void SetMeshRotation(glm::vec3 rotationMin, glm::vec3 rotationMax);
450 
455  eastl::pair<glm::vec3, glm::vec3> GetMeshRotation();
456 
462 
468 
473  void SetMeshLit(bool lit);
474 
479  bool IsMeshLit() const;
480 
486  void SetCastsShadows(bool castShadows);
487 
492  bool CanCastShadows() const;
493 
494  protected:
495 
496  friend class Emitter;
497 
498  struct ParticleData {
499  glm::vec4 position;
500  glm::vec4 direction;
501  glm::vec4 force;
502  glm::vec4 startColor;
503  glm::vec4 endColor;
504  glm::vec4 currentColor;
505  float lifetime;
507  float speed;
508  float mass;
509  };
510 
511  struct LineData {
516  };
517 
518  struct BillboardData {
519  glm::vec2 startSize;
520  glm::vec2 endSize;
521  glm::vec2 currentSize;
522  glm::vec2 padding;
527  };
528 
529  struct MeshData {
530  glm::vec4 startScale;
531  glm::vec4 endScale;
532  glm::vec4 currentScale;
534  glm::vec4 endRotationSpeed;
536  glm::vec4 currentRotation;
537  };
538 
539  ParticleData CreateParticle(glm::vec4 position, glm::vec4 direction) const;
540 
542 
544 
546 
547  float RandomFloatLinear(float min, float max) const;
548 
551 
555 
556  glm::vec4 forceMin, forceMax;
557 
560  float massMin, massMax;
561 
562  bool gravity = false;
563 
564  eastl::weak_ptr<Texture> texture;
565 
566  bool textured = false;
567 
570 
572 
576 
578  glm::vec2 endSizeMin, endSizeMax;
580 
584 
585  float rollMin, rollMax;
586 
587  eastl::weak_ptr<Mesh> mesh;
588  eastl::weak_ptr<Material> material;
589 
593 
597 
599 
600  bool meshLit;
602  };
603 
604 }
BillboardData CreateParticleBillboardData() const
Definition: Particle.cpp:434
ParticleType GetParticleType() const
Returns the type of the particle.
Definition: Particle.cpp:29
LineEndAction lineEndAction
Definition: Particle.hpp:571
void SetMeshRotation(glm::vec3 rotationMin, glm::vec3 rotationMax)
Sets the range of rotations in euler angles the mesh can start with.
Definition: Particle.cpp:360
void SetStartColor(glm::vec4 colorMin, glm::vec4 colorMax)
Sets the range of possible start colors of the particle.
Definition: Particle.cpp:44
void SetBillboardSizeInterpolateType(InterpolateType type)
Sets the interpolation type for the billboard size.
Definition: Particle.cpp:233
void SetMeshScaleEnd(glm::vec3 scaleMin, glm::vec3 scaleMax)
Sets the range for the end scale of the mesh.
Definition: Particle.cpp:317
void SetForce(glm::vec3 forceMin, glm::vec3 forceMax)
Sets the min and max for the range of forces that can be applied on the particle. ...
Definition: Particle.cpp:76
void SetMeshLit(bool lit)
Sets whether or not the lightning calculations will be done when rendering the mesh. NOTE: Only works for mesh particles.
Definition: Particle.cpp:381
void SetBillboardRoll(float rollMin, float rollMax)
Sets the range of roll rotations the billboard can start with.
Definition: Particle.cpp:265
float startLineThicknessMin
Definition: Particle.hpp:573
ParticleType particleType
Definition: Particle.hpp:549
eastl::weak_ptr< Material > GetMaterial() const
Returns the material used for the mesh.
Definition: Particle.cpp:301
void SetMaterial(eastl::weak_ptr< Material > material)
Sets the material used for the mesh. Material color is overriden by the particle color.
Definition: Particle.cpp:296
void SetMass(float massMin, float massMax)
Sets the range of masses a particle can be created with. NOTE: If the mass is zero forces won&#39;t inter...
Definition: Particle.cpp:109
void SetLineThicknessInterpolateType(InterpolateType type)
Sets the interpolation type of the line thickness.
Definition: Particle.cpp:201
eastl::pair< float, float > GetLineEndThickness()
Returns the range of thicknesses a line can end with.
Definition: Particle.cpp:196
InterpolateType GetBillboardSizeInterpolateType() const
Returns the interpolation type for the billboard size.
Definition: Particle.cpp:238
void SetBillboardSizeStart(glm::vec2 sizeMin, glm::vec2 sizeMax)
Sets the range for start size of the billboard.
Definition: Particle.cpp:211
bool IsMeshLit() const
Returns whether or not the lightning calculations will be done when rendering the mesh...
Definition: Particle.cpp:386
float endRollSpeedMin
Definition: Particle.hpp:582
float startRollSpeedMax
Definition: Particle.hpp:581
float startRollSpeedMin
Definition: Particle.hpp:581
glm::vec4 forceMax
Definition: Particle.hpp:556
InterpolateType sizeInterpolateType
Definition: Particle.hpp:579
bool IsGravityEnabled() const
Returns whether or not gravity is enabled for the particle.
Definition: Particle.cpp:125
glm::vec4 endRotationSpeedMax
Definition: Particle.hpp:595
glm::vec4 endScaleMax
Definition: Particle.hpp:591
void SetBillboardSizeEnd(glm::vec2 sizeMin, glm::vec2 sizeMax)
Sets the range for the end size of the billboard.
Definition: Particle.cpp:222
void SetMeshRotationSpeedStart(glm::vec3 speedMin, glm::vec3 speedMax)
Sets the range of rotation speeds in euler angles the mesh can start with.
Definition: Particle.cpp:338
eastl::pair< glm::vec4, glm::vec4 > GetStartColor()
Returns a pair containing the range of possible start colors of the particle.
Definition: Particle.cpp:50
eastl::pair< glm::vec3, glm::vec3 > GetMeshRotation()
Returns the range of rotations in euler angles the mesh can start with.
Definition: Particle.cpp:366
glm::vec2 endSizeMin
Definition: Particle.hpp:578
glm::vec2 startSizeMax
Definition: Particle.hpp:577
glm::vec4 startScaleMin
Definition: Particle.hpp:590
void SetEndColor(glm::vec4 colorMin, glm::vec4 colorMax)
Sets the range of possible end colors of the particle.
Definition: Particle.cpp:55
glm::vec4 endColorMin
Definition: Particle.hpp:553
InterpolateType GetColorInterpolateType() const
Returns the interpolation type used for the color.
Definition: Particle.cpp:71
eastl::pair< glm::vec4, glm::vec4 > GetEndColor()
Returns a pair containing the range of possible end colors of the particle.
Definition: Particle.cpp:61
InterpolateType scaleInterpolateType
Definition: Particle.hpp:592
InterpolateType colorInterpolateType
Definition: Particle.hpp:554
InterpolateType GetBillboardRollSpeedInterpolateType() const
Returns the interpolation type for the roll speed.
Definition: Particle.cpp:281
glm::vec4 rotationMax
Definition: Particle.hpp:598
glm::vec4 startRotationSpeedMax
Definition: Particle.hpp:594
InterpolateType GetMeshRotationSpeedInterpolateType() const
Returns the interpolation type for the rotation speed.
Definition: Particle.cpp:376
ParticleData CreateParticle(glm::vec4 position, glm::vec4 direction) const
Definition: Particle.cpp:401
eastl::weak_ptr< Texture > texture
Definition: Particle.hpp:564
void SetLineStartThickness(float thicknessMin, float thicknessMax)
Sets the range of thicknesses a line can start with (interpolation is based on lifetime, not segment count).
Definition: Particle.cpp:179
eastl::pair< glm::vec3, glm::vec3 > GetMeshRotationSpeedStart()
Returns the rotation speeds in euler angles the mesh can start with.
Definition: Particle.cpp:344
void SetMeshScaleInterpolateType(InterpolateType type)
Sets the interpolation type for the mesh scale.
Definition: Particle.cpp:328
void SetLineEndAction(LineEndAction action)
Sets the action that should be taken when trying to create segments after having reached the maximum ...
Definition: Particle.cpp:169
void SetLineEndthickness(float thicknessMin, float thicknessMax)
Sets the range of thicknesses a line can end with (interpolation is based on lifetime, not segment count).
Definition: Particle.cpp:190
eastl::weak_ptr< Texture > GetTexture() const
Returns the texture used by the particle.
Definition: Particle.cpp:139
glm::vec4 endColorMax
Definition: Particle.hpp:553
glm::vec4 startRotationSpeedMin
Definition: Particle.hpp:594
eastl::pair< glm::vec2, glm::vec2 > GetBillboardSizeStart()
Returns the range of start sizes for the billboard.
Definition: Particle.cpp:217
eastl::weak_ptr< Mesh > GetMesh() const
Returns the mesh used for mesh particles.
Definition: Particle.cpp:291
bool CanCastShadows() const
Returns whether or not the particle can cast shadows.
Definition: Particle.cpp:396
InterpolateType rollSpeedInterpolateType
Definition: Particle.hpp:583
void SetBlendMode(BlendMode mode)
Sets the blend mode of the particle.
Definition: Particle.cpp:34
eastl::pair< glm::vec3, glm::vec3 > GetMeshRotationSpeedEnd()
Returns the rotation speeds in euler angles the mesh can end with.
Definition: Particle.cpp:355
InterpolateType GetLineThicknessInterpolateType() const
Returns the interpolation type of the line thickness.
Definition: Particle.cpp:206
InterpolateType rotationSpeedInterpolateType
Definition: Particle.hpp:596
void SetMeshScaleStart(glm::vec3 scaleMin, glm::vec3 scaleMax)
Sets the range for start scale of the mesh.
Definition: Particle.cpp:306
int GetNewSegmentsPerFrame() const
Returns the ammount of new segments that get created each frame.
Definition: Particle.cpp:164
void SetCastsShadows(bool castShadows)
Sets whether or not the particle can cast shadows. NOTE: This only works for mesh particles...
Definition: Particle.cpp:391
glm::vec2 endSizeMax
Definition: Particle.hpp:578
eastl::pair< float, float > GetBillboardRoll()
Returns the range of roll rotations the billboard can start with.
Definition: Particle.cpp:271
eastl::weak_ptr< Material > material
Definition: Particle.hpp:588
glm::vec4 forceMin
Definition: Particle.hpp:556
float endRollSpeedMax
Definition: Particle.hpp:582
void SetBillboardRollSpeedEnd(float speedMin, float speedMax)
Sets the range of roll rotation speeds the billboard can end with.
Definition: Particle.cpp:254
InterpolateType GetMeshScaleInterpolateType() const
Returns the interpolation type for the mesh scale.
Definition: Particle.cpp:333
BlendMode particleBlendMode
Definition: Particle.hpp:550
glm::vec4 endScaleMin
Definition: Particle.hpp:591
BlendMode GetParticleBlendMode() const
Returns the blend mode of the particle.
Definition: Particle.cpp:39
glm::vec4 rotationMin
Definition: Particle.hpp:598
LineEndAction GetLineEndAction() const
Returns the action that should be taken when trying to create segments after having reached the maxim...
Definition: Particle.cpp:174
float endLineThicknessMin
Definition: Particle.hpp:574
LineData CreateParticleLineData() const
Definition: Particle.cpp:421
eastl::weak_ptr< Mesh > mesh
Definition: Particle.hpp:587
eastl::pair< float, float > GetBillboardRollSpeedStart()
Returns the angle of roll rotation speeds the billboard can start with.
Definition: Particle.cpp:249
float startLineThicknessMax
Definition: Particle.hpp:573
glm::vec4 startColorMax
Definition: Particle.hpp:552
void SetMeshRotationSpeedInterpolateType(InterpolateType type)
Sets the interpolation type for the rotation speed.
Definition: Particle.cpp:371
void SetColorInterpolateType(InterpolateType type)
Sets the interpolation type used for the color.
Definition: Particle.cpp:66
glm::vec2 startSizeMin
Definition: Particle.hpp:577
void SetLifetime(float lifetimeMin, float lifetimeMax)
Sets the range of possible lifetimes the particle can have.
Definition: Particle.cpp:87
void SetSpeed(float speedMin, float speedMax)
Sets the range of possible speeds the particle can be created with.
Definition: Particle.cpp:98
eastl::pair< float, float > GetLineStartThickness()
Returns the range of thicknesses a line can start with.
Definition: Particle.cpp:185
float RandomFloatLinear(float min, float max) const
Definition: Particle.cpp:474
void SetGravityEnabled(bool gravity)
Turns gravity on and off for the particle. Gravitic constant will be 9.81. If you want different grav...
Definition: Particle.cpp:120
eastl::pair< float, float > GetBillboardRollSpeedEnd()
Returns the angle of roll rotation speeds the billboard can end with.
Definition: Particle.cpp:260
void SetMesh(eastl::weak_ptr< Mesh > mesh)
Sets the mesh used for mesh particles.
Definition: Particle.cpp:286
void SetMeshRotationSpeedEnd(glm::vec3 speedMin, glm::vec3 speedMax)
Sets the range of rotation speeds in euler angles the mesh can end with.
Definition: Particle.cpp:349
void SetLineMaxSegments(int segments)
Sets the maximum amount of segments a line particle can have.
Definition: Particle.cpp:149
glm::vec4 endRotationSpeedMin
Definition: Particle.hpp:595
eastl::pair< float, float > GetSpeed()
Returns the range of possible speeds the particle can be created with.
Definition: Particle.cpp:104
void SetBillboardRollSpeedInterpolateType(InterpolateType type)
Sets the interpolation type for the roll speed.
Definition: Particle.cpp:276
eastl::pair< glm::vec3, glm::vec3 > GetMeshScaleEnd()
Returns the range of end scales for the mesh.
Definition: Particle.cpp:323
void SetTexture(eastl::weak_ptr< Texture > texture)
Sets the texture of the particle. Only applies to lines and billboards. Can be left empty to use just...
Definition: Particle.cpp:130
void SetParticleType(ParticleType type)
Sets the type of the particle.
Definition: Particle.cpp:24
void SetNewSegmentsPerFrame(int segments)
Sets the amount of new segments that get created each frame.
Definition: Particle.cpp:159
eastl::pair< glm::vec3, glm::vec3 > GetMeshScaleStart()
Returns the range of start scales for the mesh.
Definition: Particle.cpp:312
eastl::pair< glm::vec3, glm::vec3 > GetForce()
Returns a pair containing the range of possible forces that can be applied on the particle...
Definition: Particle.cpp:82
bool HasTexture() const
Returns whether or not the particle has a texture.
Definition: Particle.cpp:144
float endLineThicknessMax
Definition: Particle.hpp:574
eastl::pair< float, float > GetMass()
Returns the range of possible masses the particle can be created with.
Definition: Particle.cpp:115
glm::vec4 startColorMin
Definition: Particle.hpp:552
eastl::pair< float, float > GetLifetime()
Returns the range of possible lifetimes the particle can have.
Definition: Particle.cpp:93
InterpolateType lineThicknessInterpolateType
Definition: Particle.hpp:575
int GetLineMaxSegments() const
Returns the maximum number of segments a line particle can have.
Definition: Particle.cpp:154
glm::vec4 startScaleMax
Definition: Particle.hpp:590
MeshData CreateParticleMeshData() const
Definition: Particle.cpp:454
eastl::pair< glm::vec2, glm::vec2 > GetBillboardSizeEnd()
Returns the range of end sizes for the billboard.
Definition: Particle.cpp:228
void SetBillboardRollSpeedStart(float speedMin, float speedMax)
Sets the range of roll rotation speeds the billboard can start with.
Definition: Particle.cpp:243