src/CallbackPorte.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 CALLBACKPORTE_H
00024 #define CALLBACKPORTE_H
00025 
00026 #include "glob.h"
00027 
00028 class CallbackPorte : public osg::Referenced
00029 {
00030         private:
00031                 int currentIndex,i;
00032                 osg::ref_ptr<osg::Drawable> draw;
00033 
00034         public:
00035                 CallbackPorte(int currentIndex, osg::Drawable * draw)
00036                 {
00037                         this->currentIndex=currentIndex;
00038                         this->draw=draw;
00039                         i = 0;
00040                 }
00041 
00042                 void update(osg::NodeVisitor * nv)
00043                 {
00044                         osg::StateSet * ss = draw->getOrCreateStateSet();
00045                                 
00046                         //On stoppe le mouvement
00047                         if(mvtPorte == LEVER){
00048                                 dist+=PAS_MVT_PORTE;
00049                                 if(dist>0.4){
00050                                         mvtPorte = ARRETER;
00051                                         posPorte = ENHAUT;
00052                                         cpt_mvt = DUREE_MVT;
00053                                 }
00054                                 else
00055                                 {
00056                                         pat1->setPosition(osg::Vec3(0,dist,0));
00057                                         posPorte = AUMILIEU;
00058                                         cpt_mvt++;
00059                                 }
00060                         }
00061                         if(mvtPorte == DESCENDRE){
00062                                 dist-=PAS_MVT_PORTE;
00063                                 if(dist<0.00){
00064                                         mvtPorte=ARRETER;
00065                                         posPorte=ENBAS;
00066                                         cpt_mvt = 0;
00067                                 }
00068                                 else
00069                                 {
00070                                         pat1->setPosition(osg::Vec3(0,dist,0));
00071                                         posPorte = AUMILIEU;
00072                                         cpt_mvt--;
00073                                 }
00074                         }       
00075                         if (posPorte == ENHAUT)
00076                                 cpt_mvt = DUREE_MVT;
00077                         if (posPorte == ENBAS)
00078                                 cpt_mvt = 0;                            
00079                 }
00080 };
00081 
00082 class geodePorteCallback : public osg::NodeCallback
00083 {
00084         public:
00085                 virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
00086                 {
00087                         osg::Geode * geo = dynamic_cast <osg::Geode * >(node);
00088                         if(geo)
00089                         {
00090                                 for(unsigned int i=0;i<geo->getNumDrawables();++i)
00091                                 {
00092                                         osg::Drawable * draw = geo->getDrawable(i);
00093                                         CallbackPorte * data = dynamic_cast <CallbackPorte *>(draw->getUserData());
00094                                         if(data)
00095                                                 data->update(nv);                                       
00096                                                 
00097                                 }
00098                         }
00099                         traverse(node,nv);
00100                 }
00101 };
00102 
00103 #endif

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