| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- $#include "ParticleEmitter.h"
- /// Particle emitter shapes.
- enum EmitterType
- {
- EMITTER_SPHERE,
- EMITTER_BOX
- };
- /*
- /// One particle in the particle system.
- struct Particle
- {
- /// Velocity.
- Vector3 velocity_;
- /// Original billboard size.
- Vector2 size_;
- /// Time elapsed from creation.
- float timer_;
- /// Lifetime.
- float timeToLive_;
- /// Size scaling value.
- float scale_;
- /// Rotation speed.
- float rotationSpeed_;
- /// Current color animation index.
- unsigned colorIndex_;
- /// Current texture animation index.
- unsigned texIndex_;
- };
- */
- /// %Color animation frame definition.
- struct ColorFrame
- {
- /// Construct with default values.
- ColorFrame();
- /// Construct with a color and zero time.
- ColorFrame(const Color& color);
-
- /// Construct from a color and time.
- ColorFrame(const Color& color, float time);
-
- /// Return interpolated value with another color-time pair at the time specified.
- Color Interpolate(const ColorFrame& next, float time);
-
- /// Color.
- Color color_ @ color;
- /// Time.
- float time_ @ time;
- };
- /// %Texture animation frame definition.
- struct TextureFrame
- {
- /// Construct with default values.
- TextureFrame();
-
- /// UV coordinates.
- Rect uv_ @ uv;
- /// Time.
- float time_ @ time;
- };
- /// %Particle emitter component.
- class ParticleEmitter : public BillboardSet
- {
- public:
- /// Load emitter parameters from an XML file.
- bool Load(XMLFile* file);
- /// Set maximum number of particles.
- void SetNumParticles(unsigned num);
- /// Set emission rate (both minimum and maximum.)
- void SetEmissionRate(float rate);
- /// Set minimum emission rate.
- void SetMinEmissionRate(float rate);
- /// Set maximum emission rate.
- void SetMaxEmissionRate(float rate);
- /// Set emitter type.
- void SetEmitterType(EmitterType type);
- /// Set emitter size.
- void SetEmitterSize(const Vector3& size);
- /// Set emission active period length (0 = infinite.)
- void SetActiveTime(float time);
- /// Set emission inactive period length (0 = infinite.)
- void SetInactiveTime(float time);
- /// Set whether should be emitting and optionally reset emission period.
- void SetEmitting(bool enable, bool resetPeriod = false);
- /// Set whether to update when particles are not visible.
- void SetUpdateInvisible(bool enable);
- /// Set particle time to live (both minimum and maximum.)
- void SetTimeToLive(float time);
- /// Set particle minimum time to live.
- void SetMinTimeToLive(float time);
- /// Set particle maximum time to live.
- void SetMaxTimeToLive(float time);
- /// Set particle size (both minimum and maximum.)
- void SetParticleSize(const Vector2& size);
- /// Set particle minimum size.
- void SetMinParticleSize(const Vector2& size);
- /// Set particle maximum size.
- void SetMaxParticleSize(const Vector2& size);
- /// Set negative direction limit.
- void SetMinDirection(const Vector3& direction);
- /// Set positive direction limit.
- void SetMaxDirection(const Vector3& direction);
- /// Set particle velocity (both minimum and maximum.)
- void SetVelocity(float velocity);
- /// Set particle minimum velocity.
- void SetMinVelocity(float velocity);
- /// Set particle maximum velocity.
- void SetMaxVelocity(float velocity);
- /// Set particle rotation (both minimum and maximum.)
- void SetRotation(float rotation);
- /// Set particle minimum rotation.
- void SetMinRotation(float rotation);
- /// Set particle maximum rotation.
- void SetMaxRotation(float rotation);
- /// Set particle rotation speed (both minimum and maximum.)
- void SetRotationSpeed(float speed);
- /// Set particle minimum rotation speed.
- void SetMinRotationSpeed(float speed);
- /// Set particle maximum rotation speed.
- void SetMaxRotationSpeed(float speed);
- /// Set constant force acting on particles.
- void SetConstantForce(const Vector3& force);
- /// Set particle velocity damping force.
- void SetDampingForce(float force);
- /// Set particle size additive modifier.
- void SetSizeAdd(float sizeAdd);
- /// Set particle size multiplicative modifier.
- void SetSizeMul(float sizeMul);
- /// Set color of particles.
- void SetColor(const Color& color);
- /// Set number of color animation frames.
- void SetNumColors(unsigned num);
- /// Set number of texture animation frames.
- void SetNumTextureFrames(unsigned num);
-
- /// Return maximum number of particles.
- unsigned GetNumParticles() const { return particles_.Size(); }
- /// Return whether is currently emitting.
- bool IsEmitting() const { return emitting_; }
- /// Return whether to update when particles are not visible.
- bool GetUpdateInvisible() const { return updateInvisible_; }
- /// Return minimum emission rate.
- float GetMinEmissionRate() const { return emissionRateMin_; }
- /// Return maximum emission rate.
- float GetMaxEmissionRate() const { return emissionRateMax_; }
- /// Return emitter type.
- EmitterType GetEmitterType() const { return emitterType_; }
- /// Return emitter size.
- const Vector3& GetEmitterSize() const { return emitterSize_; }
- /// Return emission active period length (0 = infinite.)
- float GetActiveTime() const { return activeTime_; }
- /// Return emission inactive period length (0 = infinite.)
- float GetInactiveTime() const { return inactiveTime_; }
- /// Return particle minimum time to live.
- float GetMinTimeToLive() const { return timeToLiveMin_; }
- /// Return particle maximum time to live.
- float GetMaxTimeToLive() const { return timeToLiveMax_; }
- /// Return particle minimum size.
- const Vector2& GetMinParticleSize() const { return sizeMin_; }
- /// Return particle maximum size.
- const Vector2& GetMaxParticleSize() const { return sizeMax_; }
- /// Return negative direction limit.
- const Vector3& GetMinDirection() const { return directionMin_; }
- /// Return positive direction limit.
- const Vector3& GetMaxDirection() const { return directionMax_; }
- /// Return particle minimum velocity.
- float GetMinVelocity() const { return velocityMin_; }
- /// Return particle maximum velocity.
- float GetMaxVelocity() const { return velocityMax_; }
- /// Return particle minimum rotation.
- float GetMinRotation() const { return rotationMin_; }
- /// Return particle maximum rotation.
- float GetMaxRotation() const { return rotationMax_; }
- /// Return particle minimum rotation speed.
- float GetMinRotationSpeed() const { return rotationSpeedMin_; }
- /// Return particle maximum rotation speed.
- float GetMaxRotationSpeed() const { return rotationSpeedMax_; }
- /// Return constant force acting on particles.
- const Vector3& GetConstantForce() const { return constantForce_; }
- /// Return particle velocity damping force.
- float GetDampingForce() const { return dampingForce_; }
- /// Return particle size additive modifier.
- float GetSizeAdd() const { return sizeAdd_; }
- /// Return particle size multiplicative modifier.
- float GetSizeMul() const { return sizeMul_; }
- /// Return number of color animation frames.
- unsigned GetNumColors() const { return colorFrames_.Size(); }
- /// Return a color animation frame, or null if outside range.
- ColorFrame* GetColor(unsigned index) { return index < colorFrames_.Size() ? &colorFrames_[index] : (ColorFrame*)0; }
- /// Return number of texture animation frames.
- unsigned GetNumTextureFrames() const { return textureFrames_.Size(); }
- /// Return a texture animation frame, or null if outside range.
- TextureFrame* GetTextureFrame(unsigned index) { return index < colorFrames_.Size() ? &textureFrames_[index] : (TextureFrame*)0; }
- TextureFrame* GetTextureFrame(unsigned index);
- };
|