From 831e814ce9bdb84e86c06c4a52008f6bdaaa00d6 Mon Sep 17 00:00:00 2001 From: chai Date: Fri, 16 Nov 2018 00:24:51 +0800 Subject: =?UTF-8?q?*=E5=90=88=E5=B9=B6master=E5=88=B0minimal=E5=88=86?= =?UTF-8?q?=E6=94=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/libjin/Graphics/particles/je_particle.h | 178 ++++++++++++++++++++++++++++ 1 file changed, 178 insertions(+) create mode 100644 src/libjin/Graphics/particles/je_particle.h (limited to 'src/libjin/Graphics/particles/je_particle.h') 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 startFloor; + Math::Vector2 startCeil; + Math::Vector2 endFloor; + Math::Vector2 endCeil; + } random; + struct + { + Math::Vector2 start; + Math::Vector2 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 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 position; + + /// + /// Emitte direction. + /// + float direction = 0; + + Math::Vector2 speed; + Math::Vector2 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 -- cgit v1.1-26-g67d0