diff options
Diffstat (limited to 'src/libjin/Graphics/particles/je_particle.h')
-rw-r--r-- | src/libjin/Graphics/particles/je_particle.h | 178 |
1 files changed, 178 insertions, 0 deletions
diff --git a/src/libjin/Graphics/particles/je_particle.h b/src/libjin/Graphics/particles/je_particle.h new file mode 100644 index 0000000..2d112d1 --- /dev/null +++ b/src/libjin/Graphics/particles/je_particle.h @@ -0,0 +1,178 @@ +#ifndef __JE_PARTICLE_H__ +#define __JE_PARTICLE_H__ + +#include "../../math/je_vector2.hpp" +#include "../je_color.h" + +namespace JinEngine +{ + namespace Graphics + { + namespace Particles + { + + class ParticleEmitter; + + /// + /// + /// + struct LifeTimeDef + { + bool enableRandom = false; + union + { + struct + { + float min, max; + } random; + float life; + } life; + }; + + /// + /// + /// + struct SpeedOverTimeDef + { + bool enable = false; + bool enableRandom = false; + union + { + struct + { + Math::Vector2<float> startFloor; + Math::Vector2<float> startCeil; + Math::Vector2<float> endFloor; + Math::Vector2<float> endCeil; + } random; + struct + { + Math::Vector2<float> start; + Math::Vector2<float> end; + } speed; + } speed; + }; + + struct SizeOverTimeDef + { + bool enable = false; + bool enableRandom = false; + union { + struct { + float startFloor = 1; + float startCeil = 1; + float endFloor = 1; + float endCeil = 1; + } random; + struct { + float start = 1; + float end = 1; + } size; + } size; + }; + + struct ColorOverTimeDef + { + bool enable = false; + Color colorStart = Color::WHITE; + Color colorEnd = Color::WHITE; + }; + + struct linearAccelarationDef + { + Math::Vector2<float> linearAccelaration; + }; + + struct RadialAccelarationDef + { + float radialAccelaration; + }; + + /// + /// + /// + struct ParticleDef + { + private: + friend class ParticleEmitter; + + public: + // Basic definitions. + LifeTimeDef lifeTimeDef; ///< + linearAccelarationDef linearAccelarationDef; ///< + RadialAccelarationDef radialAccelarationDef; ///< + // Optional definitions. + SpeedOverTimeDef speedOverTimeDef; ///< + SizeOverTimeDef sizeOverTimeDef; ///< + ColorOverTimeDef colorOverTimeDef; ///< + }; + + /// + /// A single particle contains various properties of particle, such as position, accelaration, color and + /// other attributes changed over time. + /// + struct Particle + { + /// + /// Default constructor. + /// + Particle() {}; + + /// + /// Reset to default. + /// + void reset(); + + /// + /// Whole life time. + /// + float lifeTime = 0.0f; + + /// + /// Current life time. + /// + float life = 0.0f; + + /// + /// Current position. + /// + Math::Vector2<float> position; + + /// + /// Emitte direction. + /// + float direction = 0; + + Math::Vector2<float> speed; + Math::Vector2<float> linearAcceleration; + float radialAcceleration = 0; + + /// + /// Size over lifetime. + /// + float size = 1; + float sizeBegin = 1; + float sizeEnd = 1; + + float rotation = 0; + float angle = 0; + + /// + /// Color over lifetime. + /// + Color color = Color::WHITE; + Color colorStart = Color::WHITE; + Color colorEnd = Color::WHITE; + + /// + /// Is particle still alive? Alive is equivalent to NOT available in particle pool. + /// + bool alive = true; + + }; + + } // namespace Particles + } // namespace Graphics +} // namespace JinEngine + +#endif
\ No newline at end of file |