Equalizer 1.0
|
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 EQASSERT( _steps.size() > 0 ); 00040 EQASSERT( _curStep < _steps.size() ); 00041 00042 if( _steps.size() == 0 ) 00043 return Step(); 00044 00045 if( _steps.size() == 1 ) 00046 return _steps[ _curStep ]; 00047 00048 EQASSERT( _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 }else 00058 _curStep++; 00059 } 00060 //else 00061 const Step& curStep = _steps[ _curStep ]; 00062 const Step& nextStep = _steps[ _curStep+1 ]; 00063 00064 if( _curFrame < curStep.frame ) 00065 _curFrame = curStep.frame+1; 00066 00067 const float interval = float( nextStep.frame - curStep.frame ); 00068 const float curCoeff = ( nextStep.frame - _curFrame ) / interval; 00069 const float nextCoeff = ( _curFrame - curStep.frame ) / interval; 00070 00071 Step result( _curFrame, 00072 curStep.position * curCoeff + nextStep.position * nextCoeff, 00073 curStep.rotation * curCoeff + nextStep.rotation * nextCoeff ); 00074 00075 return result; 00076 } 00077 00078 00079 bool CameraAnimation::loadAnimation( const std::string& fileName ) 00080 { 00081 _steps.clear(); 00082 00083 if( fileName.empty( )) 00084 return false; 00085 00086 std::ifstream file; 00087 file.open( fileName.c_str( )); 00088 if( !file ) 00089 { 00090 EQERROR << "Path file could not be opened" << std::endl; 00091 return false; 00092 } 00093 00094 // read model pre-rotation 00095 file >> _modelRotation.x(); 00096 file >> _modelRotation.y(); 00097 file >> _modelRotation.z(); 00098 00099 const float m = static_cast<float>(M_PI_2) / 90.f; 00100 _modelRotation *= m; 00101 00102 uint32_t count = 0; 00103 float v[7]; 00104 int frameNum = 0; 00105 while ( !file.eof( )) 00106 { 00107 file >> v[count++]; 00108 if( count == 7 ) 00109 { 00110 count = 0; 00111 frameNum += EQ_MAX( static_cast<int>( v[0] ), 1 ); 00112 00113 _steps.push_back( Step( frameNum, 00114 eq::Vector3f( v[1] , v[2] , v[3] ), 00115 eq::Vector3f( -v[5]*m, v[4]*m, v[6]*m ))); 00116 } 00117 } 00118 file.close(); 00119 00120 return true; 00121 } 00122 00123 }