cameraAnimation.cpp

00001 /* Copyright (c) 2009, Makhinya Maxim
00002  *
00003  * This library is free software; you can redistribute it and/or modify it under
00004  * the terms of the GNU Lesser General Public License version 2.1 as published
00005  * by the Free Software Foundation.
00006  *  
00007  * This library is distributed in the hope that it will be useful, but WITHOUT
00008  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00009  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00010  * details.
00011  * 
00012  * You should have received a copy of the GNU Lesser General Public License
00013  * along with this library; if not, write to the Free Software Foundation, Inc.,
00014  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
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     //else
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     // read model pre-rotation
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 }
Generated on Mon Aug 10 18:58:31 2009 for Equalizer 0.9 by  doxygen 1.5.8