aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/graphics/particles/particle_emitter.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/libjin/graphics/particles/particle_emitter.h')
-rw-r--r--src/libjin/graphics/particles/particle_emitter.h136
1 files changed, 136 insertions, 0 deletions
diff --git a/src/libjin/graphics/particles/particle_emitter.h b/src/libjin/graphics/particles/particle_emitter.h
new file mode 100644
index 0000000..9f9465a
--- /dev/null
+++ b/src/libjin/graphics/particles/particle_emitter.h
@@ -0,0 +1,136 @@
+#ifndef __JE_PARTICLE_EMITTER_H__
+#define __JE_PARTICLE_EMITTER_H__
+
+#include "../../common/temporary.h"
+#include "../../math/vector2.hpp"
+
+#include "particle.h"
+
+namespace JinEngine
+{
+ namespace Graphics
+ {
+ namespace Particles
+ {
+
+ struct PositionDef
+ {
+ bool enableRandom = false;
+ Struct(position,
+ struct
+ {
+ Math::Vector2<float> floor;
+ Math::Vector2<float> ceil;
+ } random;
+ Math::Vector2<float> 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;
+
+ ParticleEmitterDef& mDef;
+
+ 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