src/animationmanager.cpp

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 "animationmanager.h"
00024 
00025 animationManager::animationManager()
00026 {
00027 }
00028 
00029 
00030 animationManager::~animationManager()
00031 {
00032 }
00033 
00034 osg::AnimationPath* animationManager::createAnimationPath(osg::Vec3 animCenter, float roll, float radius, double looptime)
00035 {
00036         osg::AnimationPath * animationPath = new osg::AnimationPath();
00037         animationPath->setLoopMode(osg::AnimationPath::LOOP);
00038         int numSamples = 40;
00039         float yaw = 0.0f;
00040         float yaw_delta = 2.0f*osg::PI/((float)numSamples -1.0f);
00041         double time = 0.0f;
00042         double time_delta = looptime/((double) numSamples);
00043     
00044         for(int i =0; i<numSamples;++i)
00045         {
00046                 osg::Vec3 position = animCenter+osg::Vec3(sinf(yaw)*radius,cosf(yaw)*radius,0.0f);
00047                 osg::Quat rotation = osg::Quat(roll, osg::Vec3(0,1,0))*osg::Quat(-(yaw+osg::PI/2.),osg::Vec3(0,0,1));
00048                 
00049                 animationPath->insert(time,osg::AnimationPath::ControlPoint(position,rotation));
00050 
00051                 yaw+=yaw_delta;
00052                 time+=time_delta;
00053 
00054         }
00055 
00056         return animationPath;
00057 }
00058 
00059 osg::Node * animationManager::revoluteNode(osg::Node * node,osg::Vec3 animCenter,float roll, float radius, double looptime)
00060 {
00061         osg::AnimationPath * animationPath = animationManager::createAnimationPath(animCenter,roll,radius,looptime);
00062 
00063         
00064         //osg::Geode * cubeGeode = new osg::Geode;
00065         //osg::Box * cube = new osg::Box(osg::Vec3(0,0,0),10,20,30);
00066 
00067         //osg::ShapeDrawable *shape = new osg::ShapeDrawable(cube);
00068         osg::PositionAttitudeTransform * pat = new osg::PositionAttitudeTransform();
00069         pat->setUpdateCallback(new osg::AnimationPathCallback(animationPath,0,1));
00070         //cubeGeode->addDrawable(shape);
00071         
00072         pat->addChild(node);
00073 
00074         /*
00075         osg::Geode * cubeGeode = new osg::Geode;
00076         osg::Box * cube = new osg::Box(osg::Vec3(0,0,0),10,20,30);
00077 
00078         osg::ShapeDrawable *shape = new osg::ShapeDrawable(cube);
00079         osg::PositionAttitudeTransform * pat = new osg::PositionAttitudeTransform();
00080         pat->setUpdateCallback(new osg::AnimationPathCallback(animationPath,0,1));
00081         cubeGeode->addDrawable(shape);
00082         
00083         
00084         pat->addChild(cubeGeode);
00085         pat->addChild(node);*/
00086 
00087         return pat;
00088         
00089         
00090 }
00091 

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