Particle.h

00001 #ifndef _Particle_H_
00002 #define _Particle_H_
00003 
00004 #include "MathUtil.h"
00005 #include "Sprite.h"
00006 #include "Entity2D.h"
00007 
00008 namespace zak {
00009 
00010 class ZAKENGINE_API Particle : public Sprite {
00011 
00012         private:
00013 
00014         public:
00015                 DWORD   _dwColor,_dwStartColor;
00016                 char    *_pdwColor;
00017                 char    *_pdwStartColor;
00018                 char    *_pdwTemp;
00019 
00020                 float   _rotSpeed;
00021 
00022                 float   _windX;
00023                 float   _windY;
00024 
00025                 float   _fRedInterpolation;
00026                 float   _fGreenInterpolation;
00027                 float   _fBlueInterpolation;
00028                 float   _fAlphaInterpolation;
00029                 
00030                 float   _startSizeX;
00031                 float   _startSizeY;
00032                 float   _sizeInterpolationX;
00033                 float   _sizeInterpolationY;
00034 
00035                 float   _fTimeAccum;
00036 
00037                 float   _fLifeTime;
00038 
00039                 bool    _bIsDead;
00040 
00041                 float   _speedX;
00042                 float   _speedY;
00043 
00044                 float   _precalcSin;
00045                 float   _precalcCos;
00046 
00047                 void Update(float fTimeBetweenFrames);
00048 //              void Draw(float fTimeBetweenFrames);
00049 
00050         Particle(){
00051                 _rotSpeed = 0.0f;
00052                 _fLifeTime = 0.0f;
00053                 _bIsDead = false;
00054                 _pdwColor = (char*)&_dwColor;
00055                 _pdwStartColor = (char*)&_dwStartColor;
00056                 
00057                 _fRedInterpolation=0.0f;
00058                 _fGreenInterpolation=0.0f;
00059                 _fBlueInterpolation=0.0f;
00060                 _fAlphaInterpolation=0.0f;
00061 
00062                 _sizeInterpolationX=0.0f;
00063                 _sizeInterpolationY=0.0f;
00064                 
00065                 _fTimeAccum = 0.0f;
00066 
00067                 _speedX = 0.0f;
00068                 _speedY = 0.0f;
00069 
00070                 _windX = 0.0f;
00071                 _windY = 0.0f;
00072         };
00073         ~Particle(){};
00074 };
00075 
00123 class ZAKENGINE_API ParticleSystem : public Entity2D {
00124         private:
00125                 Particle **_prtParticles;
00126 
00127                 DWORD   _dwStartColor;
00128                 DWORD   _dwEndColor;
00129 
00130                 char    *_pdwStartColor;
00131                 char    *_pdwEndColor;
00132 
00133                 float   _fLifeTime;
00134                 float   _fFrequency;
00135                 float   _fAccum;
00136 
00137                 float   _startSizeX;
00138                 float   _startSizeY;
00139                 float   _endSizeX;
00140                 float   _endSizeY;
00141 
00142                 float   _fParticlesSpeed;
00143                 float   _fParticlesAngle;
00144                 float   _rotSpeed;
00145                 float   _fAngleNoise;
00146                 float   _fSpeedNoise;
00147                 float   _fLifeNoise;
00148                 float   _rotSpeedNoise;
00149                 float   _wind;
00150                 float   _windDirection;
00151 
00152                 int             _iMaxParticles;
00153                 int             _lastParticle;
00154 
00155                 bool    _bSystemEnabled;
00156 
00157                 bool    _bIsAllDead;
00158 
00159                 Animation *_animation;
00160 
00161                 void SwapLast(int which);
00162 
00163         public:
00168                 void SetWindDirection(float windDirection) {
00169                         _windDirection = windDirection;
00170                 }
00171 
00176                 void SetWind(float wind) {
00177                         _wind = wind;
00178                 }
00179 
00185                 void SetStartDim(float sizeX, float sizeY) {
00186                         _startSizeX = sizeX;
00187                         _startSizeY = sizeY;
00188                 }
00189 
00195                 void SetEndDim(float sizeX, float sizeY) {
00196                         _endSizeX = sizeX;
00197                         _endSizeY = sizeY;
00198                 }
00199 
00204                 void SetStartColor(DWORD dwColor) {
00205                         _dwStartColor = dwColor;
00206                 } 
00207 
00212                 void SetEndColor(DWORD dwColor) {
00213                         _dwEndColor = dwColor;
00214                 } 
00215 
00220                 void SetLifeTime (float fLifeTime) {
00221                         _fLifeTime = fLifeTime;
00222                 }
00223 
00228                 void SetRotationSpeed(float rotSpeed) {
00229                         _rotSpeed = rotSpeed;
00230                 }
00231 
00236                 void SetRotationSpeedNoise(float rotSpeedNoise) {
00237                         _rotSpeedNoise = rotSpeedNoise;
00238                 }
00239 
00244                 void SetParticlesSpeed (float fParticlesSpeed) {
00245                         _fParticlesSpeed = fParticlesSpeed;
00246                 }
00247 
00252                 void SetParticlesAngle (float fParticlesAngle) {
00253                         _fParticlesAngle = fParticlesAngle;
00254                 }
00255 
00260                 void SetLifeNoise (float fLifeNoise) {
00261                         _fLifeNoise  = fLifeNoise;
00262                 }
00263 
00268                 void SetSpeedNoise (float fSpeedNoise) {
00269                         _fSpeedNoise = fSpeedNoise;
00270                 }
00271 
00276                 void SetAngleNoise (float fAngleNoise) {
00277                         _fAngleNoise = fAngleNoise;
00278                 }
00279 
00283                 void SetAllDead() {
00284                         for (int i=0; i<_iMaxParticles; i++) 
00285                                 _prtParticles[i]->_bIsDead = true;
00286                 }
00287 
00292                 bool IsEnableSystem() {
00293                         return _bSystemEnabled;
00294                 }
00295 
00299                 void SetEnableSystem() {
00300                         _bSystemEnabled = true;
00301                 }
00302 
00306                 void SetDisableSystem() {
00307                         _bSystemEnabled = false;
00308                 }
00309 
00313                 virtual void Draw ();
00314 
00319                 virtual void Update (float fTimeBetweenFrames);
00320 
00324                 virtual void EnableEffect() {           
00325                         g_renderer.EnableState(ZAK_RENDER_STATE_BLENDFUNCBRIGHT);
00326                         g_renderer.EnableModulate();
00327                 }
00328 
00332                 virtual void DisableEffect() {
00333                         g_renderer.DisableState(ZAK_RENDER_STATE_BLENDFUNCBRIGHT);
00334                         g_renderer.DisableModulate();
00335                 }
00336 
00341                 bool Load(char *particleIniFilename);
00342 
00349                 bool Load(int iMaxParticles, float fFrequency, char *spriteFilename) {
00350                         _fFrequency = fFrequency;
00351                         _fAccum = 0.0f;
00352 
00353                         if (iMaxParticles>0) {
00354                                 _iMaxParticles = iMaxParticles;
00355                                 _prtParticles = new Particle* [iMaxParticles];
00356                                 if (_prtParticles) {
00357                                         for (int i=0; i<_iMaxParticles; i++) {
00358                                                 _prtParticles[i] = new Particle;
00359                                                 
00360                                                 if (!_prtParticles[i]) {
00361                                                         delete [] _prtParticles;
00362                                                         return false;
00363                                                 }
00364                                                 
00365                                                 _prtParticles[i]->_bIsDead = true;
00366                                                 if (!_prtParticles[i]->LoadIni(spriteFilename)){
00367                                                         return false;
00368                                                 }
00369                                                 _prtParticles[i]->_dwColor = 0;
00370                                                 _prtParticles[i]->_fLifeTime = 0;
00371                                                 _prtParticles[i]->SetVisible(false);
00372                                         }
00373                                         return true;
00374                                 } else {
00375                                         return false;
00376                                 }
00377                         } else {
00378                                 _prtParticles = NULL;
00379                                 _iMaxParticles = 0;
00380                                 return false;
00381                         }
00382                         return false;
00383                 }
00384 
00389                 bool Unload();
00390 
00394         ParticleSystem() {
00395                 _rotSpeedNoise = 0.0f;
00396                 _rotSpeed = 0.0f;
00397                 _startSizeX = 0.0f;
00398                 _startSizeY = 0.0f;
00399                 _endSizeX = 0.0f;
00400                 _endSizeY = 0.0f;
00401                 _fParticlesSpeed = 0.0f;
00402                 _fParticlesAngle = 0.0f;
00403                 _fSpeedNoise = 0;
00404                 _fAngleNoise = 0;
00405                 _dwStartColor = 0;
00406                 _dwEndColor = 0;
00407                 _fLifeTime = 0.0f;
00408                 _fLifeNoise = 0.0f;
00409                 _wind = 0.0f;
00410                 _windDirection = 0.0f;
00411                 _pdwStartColor = (char*)&_dwStartColor;
00412                 _pdwEndColor = (char*)&_dwEndColor;
00413                 _prtParticles = NULL;
00414                 _bSystemEnabled = true;
00415                 _bIsAllDead = true;
00416                 _animation = NULL;
00417                 _lastParticle = 0;
00418         };
00419 
00423         ~ParticleSystem() {
00424                 if (_prtParticles) {
00425                         for (int i=0; i<_iMaxParticles; i++) {
00426                                 if (_prtParticles[i])
00427                                         delete _prtParticles[i];
00428                         }
00429 
00430                         delete [] _prtParticles;
00431                 }
00432         };
00433 };
00434 
00435 
00436 }
00437 #endif //_Particle_H_

Generado el Tue May 29 14:46:14 2007 para Zak Engine v1.1.0 por  doxygen 1.5.1-p1