src/CallbackParticle.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2007 by                                                 *
00003  *         Pierre-yves JEZEQUEL, Julien MICHOT, Loic MOISAN,               *
00004  *         Julien PAPILLON, Sebastien PINEAUD, Barthelemy SERRES           *
00005  *                                                                         *
00006  *   https://sourceforge.net/projects/anidam                               *
00007  *                                                                         *
00008  *   This program is free software; you can redistribute it and/or modify  *
00009  *   it under the terms of the GNU General Public License as published by  *
00010  *   the Free Software Foundation; either version 2 of the License, or     *
00011  *   (at your option) any later version.                                   *
00012  *                                                                         *
00013  *   This program is distributed in the hope that it will be useful,       *
00014  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00015  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00016  *   GNU General Public License for more details.                          *
00017  *                                                                         *
00018  *   You should have received a copy of the GNU General Public License     *
00019  *   along with this program; if not, write to the                         *
00020  *   Free Software Foundation, Inc.,                                       *
00021  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
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//public osg::Drawable::UpdateCallback
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                                                 /*if(etat_precedent != DESCENDRE)
00054                                                 {
00055                                                         duree = (double)(cpt_mvt + DUREE_ATT_HZCHUTE_END);
00056                                                         newrate = rate/(double)(cpt_mvt + DUREE_ATT_HZCHUTE_END); 
00057                                                 }
00058                                                 etat_precedent = DESCENDRE;
00059                                                 if (cpt_mvt < DUREE_MVT - DUREE_ATT_HZCHUTE_END && !compteur_perso)
00060                                                 {
00061                                                         compteur_perso = true;
00062                                                         std::cout << "cpt perso : " << compteur_perso << std::endl;
00063                                                 }
00064                                                 if (compteur_perso)
00065                                                         rate -= newrate; 
00066                                                 else
00067                                                 {
00068                                                         compteur_perso = false;
00069                                                         cpt = 0;
00070                                                 }
00071                                                 if (cpt_mvt <= 10)
00072                                                         terminer_chute = true;
00073 */
00074                                                 //hauteur
00075                                                 /*if (cpt_mvt < FIN_MISE_A_NIVEAU)
00076                                                 {
00077                                                         osg::Vec3 v = placer->getCenter();
00078                                                         pas = HAUTEUR_EMIT/(double)(FIN_MISE_A_NIVEAU);
00079                                                         placer->setCenter(v.x(),v.y(),v.z()-pas);
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//public osg::Drawable::UpdateCallback
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                                                                 //std::cout << v.x() << " " << v.y() << " " << v.z()+pas << std::endl;
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//public osg::Drawable::UpdateCallback
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                                                 /*if(etat_precedent != DESCENDRE)
00195                                                 {
00196                                                         newrate = rate/(double)(cpt_mvt + DUREE_ATT_CHUTENUAG_END);  
00197                                                         duree = (double)(cpt_mvt + DUREE_ATT_CHUTENUAG_END);  
00198                                                 }
00199                                                 etat_precedent = DESCENDRE;
00200                                                 if (cpt_mvt < DUREE_MVT - DUREE_ATT_CHUTENUAG_END)
00201                                                         compteur_perso = true;
00202                                                 if (compteur_perso)
00203                                                         rate -= newrate; 
00204                                                 else
00205                                                 {
00206                                                         compteur_perso = false;
00207                                                         cpt = 0;
00208                                                 }
00209                                                 if (cpt_mvt <= 10)
00210                                                         terminer_chute = true;*/
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                                 //ChuteRate->setRateRange((int)rate,(int)rate);
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

Generated on Tue Jun 5 16:56:48 2007 for Anidam by  doxygen 1.5.1