Equalizer  1.8.0
Parallel Rendering Framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
cameraAnimation.cpp
1 
2 /* Copyright (c) 2009, Maxim Makhinya
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * - Redistributions of source code must retain the above copyright notice, this
8  * list of conditions and the following disclaimer.
9  * - Redistributions in binary form must reproduce the above copyright notice,
10  * this list of conditions and the following disclaimer in the documentation
11  * and/or other materials provided with the distribution.
12  * - Neither the name of Eyescale Software GmbH nor the names of its
13  * contributors may be used to endorse or promote products derived from this
14  * software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #include "cameraAnimation.h"
30 
31 #include <iostream>
32 #include <fstream>
33 
34 namespace eqPly
35 {
36 
37 CameraAnimation::Step CameraAnimation::getNextStep()
38 {
39  LBASSERT( _steps.size() > 0 );
40  LBASSERT( _curStep < _steps.size() );
41 
42  if( _steps.size() == 0 )
43  return Step();
44 
45  if( _steps.size() == 1 )
46  return _steps[ _curStep ];
47 
48  LBASSERT( _curStep < _steps.size()-1 );
49 
50  ++_curFrame;
51  if( _curFrame > _steps[_curStep+1].frame )
52  {
53  if( _curStep == _steps.size()-2 )
54  {
55  _curFrame = 1;
56  _curStep = 0;
57  }
58  else
59  ++_curStep;
60  }
61  //else
62  const Step& curStep = _steps[ _curStep ];
63  const Step& nextStep = _steps[ _curStep+1 ];
64 
65  if( _curFrame < curStep.frame )
66  _curFrame = curStep.frame+1;
67 
68  const float interval = float( nextStep.frame - curStep.frame );
69  const float curCoeff = ( nextStep.frame - _curFrame ) / interval;
70  const float nextCoeff = ( _curFrame - curStep.frame ) / interval;
71 
72  Step result( _curFrame,
73  curStep.position * curCoeff + nextStep.position * nextCoeff,
74  curStep.rotation * curCoeff + nextStep.rotation * nextCoeff );
75 
76  return result;
77 }
78 
79 
80 bool CameraAnimation::loadAnimation( const std::string& fileName )
81 {
82  _steps.clear();
83 
84  if( fileName.empty( ))
85  return false;
86 
87  std::ifstream file;
88  file.open( fileName.c_str( ));
89  if( !file )
90  {
91  LBERROR << "Path file could not be opened" << std::endl;
92  return false;
93  }
94 
95  // read model pre-rotation
96  file >> _modelRotation.x();
97  file >> _modelRotation.y();
98  file >> _modelRotation.z();
99 
100  const float m = static_cast<float>(M_PI_2) / 90.f;
101  _modelRotation *= m;
102 
103  uint32_t count = 0;
104  float v[7];
105  int frameNum = 0;
106  while ( !file.eof( ))
107  {
108  file >> v[count++];
109  if( count == 7 )
110  {
111  count = 0;
112  frameNum += LB_MAX( static_cast<int>( v[0] ), 1 );
113 
114  _steps.push_back( Step( frameNum,
115  eq::Vector3f( v[1] , v[2] , v[3] ),
116  eq::Vector3f( -v[5]*m, v[4]*m, v[6]*m )));
117  }
118  }
119  file.close();
120 
121  return true;
122 }
123 
124 }