cameraAnimation.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "cameraAnimation.h"
00018 #include <eq/base/debug.h>
00019
00020 #include <iostream>
00021 #include <fstream>
00022
00023 namespace eqPly
00024 {
00025
00026 CameraAnimation::Step CameraAnimation::getNextStep()
00027 {
00028 EQASSERT( _steps.size() > 0 );
00029 EQASSERT( _curStep < _steps.size() );
00030
00031 if( _steps.size() == 0 )
00032 return Step();
00033
00034 if( _steps.size() == 1 )
00035 return _steps[ _curStep ];
00036
00037 EQASSERT( _curStep < _steps.size()-1 );
00038
00039 _curFrame++;
00040 if( _curFrame > _steps[_curStep+1].frame )
00041 {
00042 if( _curStep == _steps.size()-2 )
00043 {
00044 _curFrame = 1;
00045 _curStep = 0;
00046 }else
00047 _curStep++;
00048 }
00049
00050 const Step& curStep = _steps[ _curStep ];
00051 const Step& nextStep = _steps[ _curStep+1 ];
00052
00053 if( _curFrame < curStep.frame )
00054 _curFrame = curStep.frame+1;
00055
00056 const float interval = nextStep.frame - curStep.frame;
00057 const float curCoeff = ( nextStep.frame - _curFrame ) / interval;
00058 const float nextCoeff = ( _curFrame - curStep.frame ) / interval;
00059
00060 Step result( _curFrame,
00061 curStep.translation*curCoeff + nextStep.translation*nextCoeff,
00062 curStep.rotation *curCoeff + nextStep.rotation *nextCoeff);
00063
00064 return result;
00065 }
00066
00067
00068 bool CameraAnimation::loadAnimation( const std::string& fileName )
00069 {
00070 _steps.clear();
00071
00072 if( fileName.empty( ))
00073 return false;
00074
00075 std::ifstream file;
00076 file.open( fileName.c_str( ));
00077 if( !file )
00078 {
00079 EQERROR << "Path file could not be opened" << std::endl;
00080 return false;
00081 }
00082
00083
00084 file >> _modelRotation.x();
00085 file >> _modelRotation.y();
00086 file >> _modelRotation.z();
00087
00088 const float m = static_cast<float>(M_PI_2) / 90.f;
00089 _modelRotation *= m;
00090
00091 uint32_t count = 0;
00092 float v[7];
00093 int frameNum = 0;
00094 while ( !file.eof( ))
00095 {
00096 file >> v[count++];
00097 if( count == 7 )
00098 {
00099 count = 0;
00100 frameNum += EQ_MAX( static_cast<int>( v[0] ), 1 );
00101
00102 _steps.push_back( Step( frameNum,
00103 eq::Vector3f( v[1] , v[2] , v[3] ),
00104 eq::Vector3f( -v[5]*m, v[4]*m, v[6]*m )));
00105 }
00106 }
00107 file.close();
00108
00109 return true;
00110 }
00111
00112 }