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 --- .../Graphics/particles/je_particle_emitter.h | 112 +++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 src/libjin/Graphics/particles/je_particle_emitter.h (limited to 'src/libjin/Graphics/particles/je_particle_emitter.h') diff --git a/src/libjin/Graphics/particles/je_particle_emitter.h b/src/libjin/Graphics/particles/je_particle_emitter.h new file mode 100644 index 0000000..9200532 --- /dev/null +++ b/src/libjin/Graphics/particles/je_particle_emitter.h @@ -0,0 +1,112 @@ +#ifndef __JE_PARTICLE_EMITTER_H__ +#define __JE_PARTICLE_EMITTER_H__ + +#include "../../common/je_temporary.h" +#include "../../math/je_vector2.hpp" + +#include "je_particle.h" + +namespace JinEngine +{ + namespace Graphics + { + namespace Particles + { + + struct PositionDef + { + bool enableRandom = false; + union + { + struct + { + Math::Vector2 min; + Math::Vector2 max; + } random; + Math::Vector2 position; + } position; + }; + + struct DirectionDef + { + bool enableRandom = false; + union + { + struct + { + float min = 0; + float max = 0; + } random; + float direction = 0; + } direction; + }; + + /// + /// How many particles emitted per second. + /// + struct EmitRateDef + { + bool enableRandom = false; + union + { + struct + { + float min = 1; + float max = 1; + } random; + float rate = 1; + } rate; + }; + + /// + /// Definition of particle emitter. + /// + struct ParticleEmitterDef : public Temporary + { + PositionDef positionDef; ///< Emit position(relativily to the particle system center). + DirectionDef directionDef; ///< Emit direction. + EmitRateDef emitRateDef; ///< Emit rate. + }; + + class ParticleSystem; + + /// + /// Emit a single particle. + /// + class ParticleEmitter + { + public: + /// + /// + /// + ParticleEmitter(ParticleSystem& ps); + + /// + /// + /// + void update(float dt); + + private: + /// + /// + /// + ParticleSystem& mParticleSystem; + + /// + /// Emit a particle according to emitter definition and particle definition, particle system should + /// assign particle value to the particle in particle pool, but not use this return particle. + /// + void emit(); + + /// + /// + /// + float mTime; + + }; + + } // namespace Particles + } // namespace Graphics +} // namespace JinEngine + +#endif \ No newline at end of file -- cgit v1.1-26-g67d0