aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/graphics/particles/je_particle.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/libjin/graphics/particles/je_particle.h')
-rw-r--r--src/libjin/graphics/particles/je_particle.h136
1 files changed, 91 insertions, 45 deletions
diff --git a/src/libjin/graphics/particles/je_particle.h b/src/libjin/graphics/particles/je_particle.h
index 8012024..1efdc11 100644
--- a/src/libjin/graphics/particles/je_particle.h
+++ b/src/libjin/graphics/particles/je_particle.h
@@ -1,8 +1,12 @@
#ifndef __JE_PARTICLE_H__
#define __JE_PARTICLE_H__
+#include "../../game/je_gameobject.h"
+#include "../../math/je_ranged_value.h"
#include "../../math/je_transform.h"
#include "../../math/je_vector2.hpp"
+#include "../../math/je_percentage.h"
+
#include "../je_color.h"
#include "../je_sprite.h"
@@ -15,8 +19,34 @@ namespace JinEngine
class ParticleEmitter;
+ class ScaledRangedValue : public Math::RangedValue
+ {
+ public:
+ ScaledRangedValue() {};
+ ScaledRangedValue(Math::Percentage* points, uint n);
+ void set(Math::Percentage* points, uint n);
+
+ };
+
+ class GradientColorValue
+ {
+ public:
+ GradientColorValue();
+
+ void addColor(Color col, Math::Percentage time);
+ Color getColor(Math::Percentage time);
+ void insertColor(uint i, Color col, Math::Percentage time);
+ void removeColor(uint i);
+
+ private:
+ std::vector<Color> mColors;
+ std::vector<Math::Percentage> mTimeline;
+ uint mCount;
+
+ };
+
///
- ///
+ ///
///
struct LifeTimeDef
{
@@ -30,18 +60,22 @@ namespace JinEngine
);
};
- struct ScaleOverTimeDef
+ struct ScaleDef
{
- bool enable = false;
- float start = 1;
- float end = 1;
+ float scale = 1;
+ Struct(overTime,
+ bool enable = false;
+ ScaledRangedValue value;
+ );
};
- struct ColorOverTimeDef
+ struct ColorDef
{
- bool enable = false;
- Color colorStart = Color::WHITE;
- Color colorEnd = Color::WHITE;
+ Color color = Color::WHITE;
+ Struct(overTime,
+ bool enable = false;
+ GradientColorValue value;
+ );
};
struct linearAccelarationDef
@@ -67,35 +101,68 @@ namespace JinEngine
);
};
+ enum SpriteMode
+ {
+ SINGLE = 1,
+ RANDOM = 2,
+ ANIMATED = 3,
+ };
+
+ struct SpritesDef
+ {
+ SpriteMode mode = SpriteMode::SINGLE;
+ std::vector<const Sprite*> sprites;
+ };
+
+ struct BlendDef
+ {
+ bool additive = false;
+ };
+
///
- ///
+ ///
///
struct ParticleDef
{
- private:
- friend class ParticleEmitter;
-
public:
// Basic definitions.
LifeTimeDef lifeTimeDef; ///<
linearAccelarationDef linearAccelarationDef; ///<
RadialAccelarationDef radialAccelarationDef; ///<
AngularSpeedDef angularSpeedDef; ///<
+ SpritesDef spritesDef; ///<
+ BlendDef blendDef; ///<
// Optional definitions.
- ScaleOverTimeDef sizeOverTimeDef; ///<
- ColorOverTimeDef colorOverTimeDef; ///<
+ ScaleDef scaleDef; ///<
+ ColorDef colorDef; ///<
+
+ private:
+ friend class ParticleEmitter;
+
};
///
/// A single particle contains various properties of particle, such as position, accelaration, color
/// and other attributes changed over time.
///
- struct Particle : public IRenderable
+ class Particle : public IRenderable, public Game::GameObject
{
+ public:
+ enum ParticleUpdateMask
+ {
+ NONE = 0,
+ UPDATE_COLOR = 1 << 0,
+ UPDATE_SCALE = 1 << 1,
+ UPDATE_POSITION = 1 << 2,
+ UPDATE_ROTATION = 1 << 3,
+ UPDATE_SPRITE = 1 << 4,
+ UPDATE_VELOCITY = 1 << 5,
+ };
+
///
/// Default constructor.
///
- Particle(const Sprite* sprite);
+ Particle();
///
/// Reset to default.
@@ -114,47 +181,26 @@ namespace JinEngine
//////////////////////////////////////////////////////////////////////////////////////////////////
- ///
- /// Whole life time.
- ///
+ ParticleDef* def;
+
+ uint updateFlags = ParticleUpdateMask::NONE;
+
float lifeTime = 1.0f;
- ///
- /// Current life time.
- ///
float life = 0.0f;
- const Sprite* sprite;
+ int spriteIndex = 0;
- ///
- /// Color over lifetime.
- ///
Color color = Color::WHITE;
- Color colorStart = Color::WHITE;
- Color colorEnd = Color::WHITE;
- ///
- /// Position scale rotation origin.
- ///
Math::Transform transform;
- ///
- /// Speeds.
- ///
- Math::Vector2<float> speed;
+ Math::Vector2<float> velocity;
Math::Vector2<float> linearAcceleration;
+
float angularSpeed;
float radialAcceleration = 0;
- ///
- /// Size over lifetime.
- ///
- float scaleBegin = 1;
- float scaleEnd = 1;
-
- ///
- /// Is particle still alive? Alive is equivalent to NOT available in particle pool.
- ///
bool alive = true;
};