src/CallbackTurbine.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 #include "glob.h"
00024 #include <iostream>
00025 
00026 class CallbackTurbine : public osg::Referenced
00027 {
00028         private:
00029                 int currentIndex;
00030                 osg::ref_ptr<osg::Drawable> draw;
00031                 double angle;
00032 
00033         public:
00034                 CallbackTurbine(int currentIndex, osg::Drawable * draw)
00035                 {
00036                         this->currentIndex=currentIndex;
00037                         this->draw=draw;
00038                         angle = 0.0;
00039 
00040                 }
00041 
00042                 void update(osg::NodeVisitor * nv)
00043                 {
00044                         osg::StateSet * ss = draw->getOrCreateStateSet();
00045                         
00046                         if (posPorte != ENBAS)
00047                         {
00048                                 if (mvtPorte == DESCENDRE)
00049                                         angle -= COEF_TURBINE * cpt_mvt/(double)DUREE_MVT;
00050                                 else
00051                                         angle += COEF_TURBINE * cpt_mvt/(double)DUREE_MVT;      
00052                         }
00053                         osg::BoundingBox box = geo2->getBoundingBox();
00054                         osg::Vec3 centre = box.center();
00055                         //pat_dam->setPivotPoint(osg::Vec3(centre.x(),centre.y(),centre.z()));
00056                         pat1->setPivotPoint(osg::Vec3(centre.x(),centre.y(),centre.z()));
00057                         pat2_2->setPivotPoint(osg::Vec3(centre.x(),centre.y(),centre.z()));
00058                         quaternion->makeRotate(angle,1,0,0);
00059                         pat2_2->setAttitude(*quaternion);       
00060                 }
00061 };
00062 
00063 
00064 class geodeTurbineCallback : public osg::NodeCallback
00065 {
00066         public:
00067                 virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
00068                 {
00069                         osg::Geode * geo = dynamic_cast <osg::Geode * >(node);
00070                         if(geo)
00071                         {
00072                                 for(unsigned int i=0;i<geo->getNumDrawables();++i)
00073                                 {
00074                                         osg::Drawable * draw = geo->getDrawable(i);
00075                                         CallbackTurbine * data = dynamic_cast <CallbackTurbine *>(draw->getUserData());
00076                                         if(data)
00077                                                 data->update(nv);                                               
00078                                 }
00079                         }
00080                         traverse(node,nv);
00081                 }
00082 };

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