00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef CALLBACKPARTICLE_H
00024 #define CALLBACKPARTICLE_H
00025
00026 #include "glob.h"
00027
00028 #ifndef max
00029 #define max(a,b) (a>b)?a:b
00030 #endif
00031 #ifndef min
00032 #define min(a,b) (a<b)?a:b
00033 #endif
00034
00035 class PSChuteCallback : public osg::NodeCallback
00036 {
00037 public:
00038 PSChuteCallback(): rate(0.0), compteur_perso(false), terminer_chute(false), cpt(0), etat_precedent(ARRETER) {}
00039 virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
00040 {
00041 osgParticle::ModularEmitter * ps = dynamic_cast <osgParticle::ModularEmitter* >(node);
00042 osgParticle::RandomRateCounter *ChuteRate = static_cast<osgParticle::RandomRateCounter *>(ps->getCounter());
00043 osgParticle::SectorPlacer *placer = static_cast<osgParticle::SectorPlacer *>(ps->getPlacer());
00044
00045 if (compteur_perso)
00046 cpt++;
00047 if(ps)
00048 {
00049 switch(mvtPorte)
00050 {
00051 case DESCENDRE :
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082 rate = max(0,cpt_mvt)*MAX_PARTICLE_CHUTE/1333.;
00083 break;
00084
00085 case LEVER :
00086 etat_precedent = LEVER;
00087 if (posPorte != ENHAUT && cpt_mvt > DUREE_ATT_HZCHUTE)
00088 rate += MAX_PARTICLE_CHUTE/((double)DUREE_MVT-DUREE_ATT_HZCHUTE);
00089 if (cpt_mvt > DEBUT_MISE_A_NIVEAU && cpt_mvt < FIN_MISE_A_NIVEAU)
00090 {
00091 osg::Vec3 v = placer->getCenter();
00092 pas = HAUTEUR_EMIT/(double)(FIN_MISE_A_NIVEAU-DEBUT_MISE_A_NIVEAU);
00093 placer->setCenter(v.x(),v.y(),v.z()+pas);
00094 }
00095 break;
00096 default : etat_precedent = ARRETER;
00097 }
00098
00099 if (terminer_chute)
00100 {
00101 if (cpt < duree)
00102 rate -= newrate;
00103 else
00104 {
00105 compteur_perso = false;
00106 terminer_chute = false;
00107 cpt = 0;
00108 rate = MIN_PARTICLE;
00109 }
00110 }
00111
00112 if (posPorte == ENHAUT)
00113 rate = MAX_PARTICLE_CHUTE;
00114 ChuteRate->setRateRange((int)rate,(int)rate);
00115 }
00116 ChuteRate->setRateRange((int)rate,(int)rate);
00117 }
00118 private :
00119 double rate,newrate,duree,pas;
00120 int etat_precedent;
00121 int cpt;
00122 bool compteur_perso,terminer_chute;
00123 };
00124
00125 class PSChuteHzCallback : public osg::NodeCallback
00126 {
00127 public:
00128 PSChuteHzCallback(): rate(0.0){}
00129 virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
00130 {
00131 osgParticle::ModularEmitter * ps = dynamic_cast <osgParticle::ModularEmitter* >(node);
00132 osgParticle::RandomRateCounter *ChuteRate = static_cast<osgParticle::RandomRateCounter *>(ps->getCounter());
00133 osgParticle::SectorPlacer *placer = static_cast<osgParticle::SectorPlacer *>(ps->getPlacer());
00134
00135 if(ps)
00136 {
00137 if (posPorte != ENBAS)
00138 {
00139 switch(mvtPorte)
00140 {
00141 case DESCENDRE :
00142 rate -= MAX_PARTICLE_HZ/(double)DUREE_MVT;
00143 if (cpt_mvt < FIN_MISE_A_NIVEAU)
00144 {
00145 osg::Vec3 v = placer->getCenter();
00146 pas = HAUTEUR_EMIT/(double)(FIN_MISE_A_NIVEAU);
00147 placer->setCenter(v.x(),v.y(),v.z()-pas);
00148 }break;
00149 case LEVER :
00150 if (posPorte != ENHAUT)
00151 rate += MAX_PARTICLE_HZ/(double)DUREE_MVT ;
00152 if (cpt_mvt > DEBUT_MISE_A_NIVEAU && cpt_mvt < FIN_MISE_A_NIVEAU)
00153 {
00154 osg::Vec3 v = placer->getCenter();
00155 pas = HAUTEUR_EMIT/(double)(FIN_MISE_A_NIVEAU-DEBUT_MISE_A_NIVEAU);
00156 placer->setCenter(v.x(),v.y(),v.z()+pas);
00157
00158 }break;
00159 default : ;
00160 }
00161 }
00162 else
00163 {
00164 if (posPorte == ENBAS)
00165 rate = MIN_PARTICLE;
00166 if (posPorte == ENHAUT)
00167 rate = MAX_PARTICLE_HZ;
00168 }
00169 ChuteRate->setRateRange((int)rate,(int)rate);
00170 }
00171 }
00172 private :
00173 double rate;
00174 double pas;
00175 };
00176
00177 class PSChuteNuageCallback : public osg::NodeCallback
00178 {
00179 public:
00180 PSChuteNuageCallback(): rate(0.0), compteur_perso(false), terminer_chute(false), cpt(0), etat_precedent(ARRETER) {}
00181 virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
00182 {
00183 osgParticle::ModularEmitter * ps = dynamic_cast <osgParticle::ModularEmitter* >(node);
00184 osgParticle::RandomRateCounter *ChuteRate = static_cast<osgParticle::RandomRateCounter *>(ps->getCounter());
00185
00186 if (compteur_perso)
00187 cpt++;
00188
00189 if(ps)
00190 {
00191 switch(mvtPorte)
00192 {
00193 case DESCENDRE :
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211 rate = max(0,cpt_mvt)*MAX_PARTICLE_NUAG/1333.;
00212 break;
00213 case LEVER :
00214 etat_precedent = LEVER;
00215 if (posPorte != ENHAUT && cpt_mvt > DUREE_ATT_CHUTENUAG)
00216 rate += MAX_PARTICLE_NUAG/((double)DUREE_MVT - DUREE_ATT_CHUTENUAG); break;
00217 default : etat_precedent = ARRETER;
00218 }
00219
00220 if (terminer_chute)
00221 {
00222 if (cpt < duree)
00223 rate -= newrate;
00224 else
00225 {
00226 compteur_perso = false;
00227 terminer_chute = false;
00228 cpt = 0;
00229 rate = MIN_PARTICLE;
00230 }
00231 }
00232
00233 if (posPorte == ENHAUT)
00234 rate = MAX_PARTICLE_NUAG;
00235
00236 }
00237 ChuteRate->setRateRange((int)rate,(int)rate);
00238 }
00239 private :
00240 double rate,newrate,duree;
00241 int cpt,etat_precedent;
00242 bool compteur_perso,terminer_chute;
00243 };
00244
00245 #endif