Equalizer  1.4.1
cameraAnimation.cpp
00001 
00002 /* Copyright (c) 2009, Maxim Makhinya
00003  *
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions are met:
00006  *
00007  * - Redistributions of source code must retain the above copyright notice, this
00008  *   list of conditions and the following disclaimer.
00009  * - Redistributions in binary form must reproduce the above copyright notice,
00010  *   this list of conditions and the following disclaimer in the documentation
00011  *   and/or other materials provided with the distribution.
00012  * - Neither the name of Eyescale Software GmbH nor the names of its
00013  *   contributors may be used to endorse or promote products derived from this
00014  *   software without specific prior written permission.
00015  *
00016  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00017  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00018  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00019  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
00020  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00021  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00022  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00023  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00024  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00025  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00026  * POSSIBILITY OF SUCH DAMAGE.
00027  */
00028 
00029 #include "cameraAnimation.h"
00030 
00031 #include <iostream>
00032 #include <fstream>
00033 
00034 namespace eqPly
00035 {
00036 
00037 CameraAnimation::Step CameraAnimation::getNextStep()
00038 {
00039     LBASSERT( _steps.size() > 0 );
00040     LBASSERT( _curStep < _steps.size() );
00041 
00042     if( _steps.size() == 0 )
00043         return Step();
00044 
00045     if( _steps.size() == 1 )
00046         return _steps[ _curStep ];
00047 
00048     LBASSERT( _curStep < _steps.size()-1 );
00049 
00050     ++_curFrame;
00051     if( _curFrame > _steps[_curStep+1].frame )
00052     {
00053         if( _curStep == _steps.size()-2 )
00054         {
00055             _curFrame = 1;
00056             _curStep  = 0;
00057         }
00058         else
00059             ++_curStep;
00060     }
00061     //else
00062     const Step& curStep  = _steps[ _curStep   ];
00063     const Step& nextStep = _steps[ _curStep+1 ];
00064 
00065     if( _curFrame < curStep.frame )
00066         _curFrame = curStep.frame+1;
00067 
00068     const float interval  = float( nextStep.frame - curStep.frame );
00069     const float curCoeff  = ( nextStep.frame - _curFrame ) / interval;
00070     const float nextCoeff = ( _curFrame - curStep.frame ) / interval;
00071 
00072     Step result( _curFrame,
00073                  curStep.position * curCoeff + nextStep.position * nextCoeff,
00074                  curStep.rotation * curCoeff + nextStep.rotation * nextCoeff );
00075 
00076     return result;
00077 }
00078 
00079 
00080 bool CameraAnimation::loadAnimation( const std::string& fileName )
00081 {
00082     _steps.clear();
00083 
00084     if( fileName.empty( ))
00085         return false;
00086 
00087     std::ifstream file;
00088     file.open( fileName.c_str( ));
00089     if( !file )
00090     {
00091         LBERROR << "Path file could not be opened" << std::endl;
00092         return false;
00093     }
00094 
00095     // read model pre-rotation
00096     file >> _modelRotation.x();
00097     file >> _modelRotation.y();
00098     file >> _modelRotation.z();
00099 
00100     const float m = static_cast<float>(M_PI_2) / 90.f;
00101     _modelRotation *= m;
00102 
00103     uint32_t count = 0;
00104     float v[7];
00105     int frameNum = 0;
00106     while ( !file.eof( ))
00107     {
00108         file >> v[count++];
00109         if( count == 7 )
00110         {
00111             count = 0;
00112             frameNum += LB_MAX( static_cast<int>( v[0] ), 1 );
00113 
00114             _steps.push_back( Step( frameNum,
00115                              eq::Vector3f(  v[1]  , v[2]  , v[3]   ),
00116                              eq::Vector3f( -v[5]*m, v[4]*m, v[6]*m )));
00117         }
00118     }
00119     file.close();
00120 
00121     return true;
00122 }
00123 
00124 }
Generated on Mon Nov 26 2012 14:41:48 for Equalizer 1.4.1 by  doxygen 1.7.6.1