00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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
00065
00066
00067
00068 osg::PositionAttitudeTransform * pat = new osg::PositionAttitudeTransform();
00069 pat->setUpdateCallback(new osg::AnimationPathCallback(animationPath,0,1));
00070
00071
00072 pat->addChild(node);
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087 return pat;
00088
00089
00090 }
00091