From f0f340dec7821cee103ab9267ef941a917ef4dc4 Mon Sep 17 00:00:00 2001 From: chai Date: Sun, 18 Nov 2018 23:31:17 +0800 Subject: =?UTF-8?q?*=E7=9B=AE=E5=BD=95=E6=94=B9=E4=B8=BA=E5=B0=8F=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../graphics/particles/je_particle_emitter.h | 136 +++++++++++++++++++++ 1 file changed, 136 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..44bd1fb --- /dev/null +++ b/src/libjin/graphics/particles/je_particle_emitter.h @@ -0,0 +1,136 @@ +#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; + Struct(position, + struct + { + Math::Vector2 floor; + Math::Vector2 ceil; + } random; + Math::Vector2 position; + ); + }; + + struct DirectionDef + { + bool enableRandom = false; + Struct(direction, + struct + { + float floor = 0; + float ceil = 0; + } random; + float direction = 0; + ); + }; + + /// + /// How many particles emitted per second. + /// + struct EmitRateDef + { + bool enableRandom = false; + Struct(rate, + struct + { + float floor = 1; + float ceil = 1; + } random; + float rate = 1; + ); + }; + + /// + /// Initial speed of particle. + /// + struct ForceDef + { + bool enableRandom = false; + Struct(force, + struct + { + float floor = 1; + float ceil = 1; + } random; + float force = 1; + ); + }; + + /// + /// Definition of particle emitter. + /// + struct ParticleEmitterDef + { + EmitRateDef emitRateDef; ///< Emit rate. + + PositionDef positionDef; ///< Emit position(relativily to the particle system center). + DirectionDef directionDef; ///< Emit direction. + ForceDef forceDef; ///< Emit force. + }; + + class ParticleSystem; + + /// + /// Emit a single particle. + /// + class ParticleEmitter + { + public: + /// + /// + /// + ParticleEmitter(ParticleSystem& ps); + + /// + /// + /// + void update(float dt); + + private: + /// + /// + /// + ParticleSystem& mPS; + + const ParticleEmitterDef& mDef; + + const ParticleDef& mPDef; + + /// + /// Emit 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; + + /// + /// + /// + float mInterval; + + }; + + } // namespace Particles + } // namespace Graphics +} // namespace JinEngine + +#endif \ No newline at end of file -- cgit v1.1-26-g67d0