From 2e93e755a4f4631419ba0eee26660a5638a7a7c6 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 23 Nov 2008 22:13:40 +0000 Subject: particle systems --- src/render/particles.h | 144 +++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 122 insertions(+), 22 deletions(-) (limited to 'src/render/particles.h') diff --git a/src/render/particles.h b/src/render/particles.h index 400971c..e74c3d8 100644 --- a/src/render/particles.h +++ b/src/render/particles.h @@ -9,64 +9,164 @@ #include +#include "math/axis.h" #include "math/color.h" #include "math/vector3f.h" #include "core/entity.h" namespace render { +/* ---- class Particle --------------------------------------------- */ + +/// one particle class Particle { public: Particle(const math::Vector3f &location, float time); - Particle(const math::Vector3f &location, const math::Vector3f &up, const math::Vector3f &left, float time); - - inline const math::Vector3f &location() const { return particle_location; } + Particle(const math::Vector3f &location, const math::Axis &axis, float time); - inline const math::Vector3f &up() const { return particle_up; } + /// location of the particle, in world coordinates + inline math::Vector3f &location() { return particle_location; } - inline const math::Vector3f &left() const { return particle_left; } + inline math::Axis &axis() { return particle_axis; } inline const float time() const { return particle_time; } protected: math::Vector3f particle_location; - math::Vector3f particle_up; - math::Vector3f particle_left; + math::Axis particle_axis; float particle_time; }; +/* ---- class ParticleScript --------------------------------------- */ -class ParticleStream { +/// class to hold particle scripts +class ParticleScript { public: - ParticleStream(const math::Vector3f &location, const math::Color &color, float radius, size_t texture, core::EntityControlable *entity = 0, bool oriented = false); - ~ParticleStream(); - void draw(); + enum Type {Jet=0, Trail=1, Flame=2 }; - inline const size_t texture() const { return particles_texture; } + inline const Type type() const { return particles_type; } - inline const math::Vector3f &location() const { return particles_location; } + inline const std::string &label() const { return particles_label; } -protected: - typedef std::deque Particles; + inline const std::string &texture() const { return particles_texture; } + + inline const math::Color &color() const { return particles_color; } + + inline float radius() const { return particles_radius; } + + inline float timeout() const { return particles_timeout; } + + inline float eject() const { return particles_eject; } + + inline float speed() const { return particles_speed; } + + inline float alpha() const { return particles_alpha; } + + static ParticleScript *find(const std::string &label); + + static void init(); - math::Vector3f particles_location; - math::Color particles_color; - size_t particles_texture; - bool particles_oriented; + static void clear(); + +private: + ParticleScript(); + ~ParticleScript(); + + std::string particles_label; + std::string particles_texture; + Type particles_type; + math::Color particles_color; float particles_radius; float particles_timeout; float particles_eject; + float particles_speed; + float particles_alpha; + + typedef std::map Registry; + + static Registry particles_registry; +}; + +/* ---- class ParticleSystem --------------------------------------- */ + +/// abstract base class for a particle system attached to an entity +class ParticleSystem { +public: + ParticleSystem(ParticleScript *script, core::Entity *entity, const math::Vector3f &location); + virtual ~ParticleSystem(); + + /// index of the texture to use + inline const size_t texture() const { return particlesystem_texture; } + + /// location of the particle system within the entity + inline const math::Vector3f &location() const { return particlesystem_location; } + + /// axis of the particle system within the entity + inline const math::Axis &axis() const { return particlesystem_axis; } - float particles_last_eject; + virtual void draw(float elapsed); - core::EntityControlable *particles_entity; + void set_timeout(float timeout); - Particles particles_stream; + void set_eject(float eject); + +protected: + core::Entity *particlesystem_entity; + + typedef std::deque Stream; + + inline Stream & stream() { return particlesystem_stream; } + + size_t particlesystem_texture; + + math::Axis particlesystem_axis; + math::Vector3f particlesystem_location; + + float particlesystem_last_eject; + + ParticleScript *particlesystem_script; + + Stream particlesystem_stream; + + math::Vector3f ejector_location; + bool ejector_active; + float now; + math::Color color; +}; + +/* ---- class Flame ------------------------------------------------ */ + +/// flame style particles, like engine flames +class Flame : public ParticleSystem +{ }; +/* ---- class Jet -------------------------------------------------- */ + +/// jet style particles, like smoke +class Jet : public ParticleSystem +{ +public: + Jet(ParticleScript *script, core::Entity *entity, const math::Vector3f &location); + virtual ~Jet(); + + virtual void draw(float elapsed); +}; + +/* ---- class Trail ------------------------------------------------ */ + +/// trail style particles, like an engine trail +class Trail : public ParticleSystem +{ +public: + Trail(ParticleScript *script, core::Entity *entity, const math::Vector3f &location); + virtual ~Trail(); + + virtual void draw(float elapsed); +}; } // namespace render -- cgit v1.2.3