00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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
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 };