My particle emitter class is of my own design (Which is why I'm surprised it works). Also it uses D3D for rendering - but I imagine it wouldn't be that hard to change it to Open GL.
Heres what my struct / class defs look like, although they won't really do you much good without the implementation. Oh, and to use this, I first create an emitter_p struct that will describe the properties of the emitter. Then I use the SetProperties function of the Emitter class and that creates the buffers and inits all of the particles
typedef struct particle{ D3DXVECTOR3 dir; D3DXVECTOR3 pos; float life[2]; float size[3]; float angle; float rot; short rotDir; // used for ROTRAND mode} particle;typedef struct emitter_p{ int count; // Number of particles D3DXVECTOR3 pos; // Position of the emitter D3DXVECTOR3 dir; // Direction and base velocity of spew D3DXVECTOR3 grav; // Global force applied to all particles // Ranges float drag; D3DXVECTOR3 vary[2];// Spew inaccuracy ( and speed! ) DWORD color[2]; // Color float life[2]; // Particle life float delay[2]; // Delay between particles float bound[3]; // Spew box area (x/y/z width) float size[4]; // Min/Max start Min/Max end float rotRate[2]; // num of rotations per second int minBurst; // Minimum number of particles to burst at once Texture *tex;// Texture to apply DWORD flags; // Options!// int srcblend, dstblend;} emitter_p;class CEmitter {public: CEmitter(); virtual ~CEmitter(); bool SetProperties(emitter_p properties); inline void Stop(); inline void Activate(); void Draw(); void LoadProperties(LPCSTR file);private: void Release(); void InitParticles(); inline void InitParticle(particle* pParticle, bool bDead = false); void InitDeadParticles(); bool bActive; bool bOkToBurst; double delay; // time before the next particle spawn emitter_p prop; // properties // Dynamic stuff (delete on destruction) particle *pParticles; VertexTC *pVerts; LPDIRECT3DINDEXBUFFER9 pIB; LPDIRECT3DVERTEXBUFFER9 pVB;};
I do notice a couple differences though. One being that you don't have a method that initializes a single particle instead of all of them at once. This ensures that dead particles are spawned with different properties than their previous life. Also are you randomizing the spawn location and vectors so that every particle doesn't have the same direction? For example in my emitter properties, I supply min/max ranges for almost every particle variable, then generate a random number in between those two values, and then I assign the variable. This makes every particle different.
Oh, and I find having an active variable in the particle struct useless - you already have the life, and if the life is less than or equal to 0 it is dead.
Sorry if this wasn't what you needed. I could give you an example or two of how I create a random ranged float and assign it, but I really don't want to post the entire code (its near 500 lines, plus it isn't fully completed ).
[edited by - Hawkeye3 on June 23, 2003 2:23:32 PM]