cameraAnimation.cpp

00001 
00002 /* Copyright (c) 2009, Maxim Makhinya
00003  *
00004  * This library is free software; you can redistribute it and/or modify it under
00005  * the terms of the GNU Lesser General Public License version 2.1 as published
00006  * by the Free Software Foundation.
00007  *  
00008  * This library is distributed in the hope that it will be useful, but WITHOUT
00009  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00010  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00011  * details.
00012  * 
00013  * You should have received a copy of the GNU Lesser General Public License
00014  * along with this library; if not, write to the Free Software Foundation, Inc.,
00015  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00016  */
00017 
00018 #include "cameraAnimation.h"
00019 #include <eq/base/debug.h>
00020 
00021 #include <iostream>
00022 #include <fstream>
00023 
00024 namespace eqPly
00025 {
00026 
00027 CameraAnimation::Step CameraAnimation::getNextStep()
00028 {
00029     EQASSERT( _steps.size() > 0 );
00030     EQASSERT( _curStep < _steps.size() );
00031 
00032     if( _steps.size() == 0 )
00033         return Step();
00034 
00035     if( _steps.size() == 1 )
00036         return _steps[ _curStep ];
00037 
00038     EQASSERT( _curStep < _steps.size()-1 );
00039 
00040     _curFrame++;
00041     if( _curFrame > _steps[_curStep+1].frame )
00042     {
00043         if( _curStep == _steps.size()-2 )
00044         {
00045             _curFrame = 1;
00046             _curStep  = 0;
00047         }else
00048             _curStep++;
00049     }
00050     //else
00051     const Step& curStep  = _steps[ _curStep   ];
00052     const Step& nextStep = _steps[ _curStep+1 ];
00053 
00054     if( _curFrame < curStep.frame )
00055         _curFrame = curStep.frame+1;
00056 
00057     const float interval  = nextStep.frame - curStep.frame;
00058     const float curCoeff  = ( nextStep.frame - _curFrame ) / interval;
00059     const float nextCoeff = ( _curFrame - curStep.frame ) / interval;
00060 
00061     Step result( _curFrame,
00062                  curStep.translation*curCoeff + nextStep.translation*nextCoeff,
00063                  curStep.rotation   *curCoeff + nextStep.rotation   *nextCoeff);
00064 
00065     return result;
00066 }
00067 
00068 
00069 bool CameraAnimation::loadAnimation( const std::string& fileName )
00070 {
00071     _steps.clear();
00072 
00073     if( fileName.empty( ))
00074         return false;
00075 
00076     std::ifstream file;
00077     file.open( fileName.c_str( ));
00078     if( !file )
00079     {
00080         EQERROR << "Path file could not be opened" << std::endl;
00081         return false;
00082     }
00083 
00084     // read model pre-rotation
00085     file >> _modelRotation.x();
00086     file >> _modelRotation.y();
00087     file >> _modelRotation.z();
00088 
00089     const float m = static_cast<float>(M_PI_2) / 90.f;
00090     _modelRotation *= m;
00091 
00092     uint32_t count = 0;
00093     float v[7];
00094     int frameNum = 0;
00095     while ( !file.eof( ))
00096     {
00097         file >> v[count++];
00098         if( count == 7 )
00099         {
00100             count = 0;
00101             frameNum += EQ_MAX( static_cast<int>( v[0] ), 1 );
00102 
00103             _steps.push_back( Step( frameNum,
00104                              eq::Vector3f(  v[1]  , v[2]  , v[3]   ),
00105                              eq::Vector3f( -v[5]*m, v[4]*m, v[6]*m )));
00106         }
00107     }
00108     file.close();
00109 
00110     return true;
00111 }
00112 
00113 }
Generated on Sat Feb 6 12:59:42 2010 for Equalizer 0.9.1 by  doxygen 1.6.1